EIP-2124 · Final · Networking · 2019-05-03
EIP-2124: Fork identifier for chain compatibility checks
Defines the fork ID, a 4-byte checksum of the genesis and past forks plus the next fork block, so nodes can tell in one exchange whether a peer is on a compatible chain.
What problem does it solve?
Many public and private Ethereum networks share the same peer-to-peer infrastructure. Before this EIP, the only way to know if a peer was on your chain was to open a TCP connection, do the RLPx crypto handshake and then the eth handshake. That is expensive, and it still could not tell Ethereum from Ethereum Classic, which share a genesis.
There is a second problem: after a hard fork, nodes that did not upgrade keep hanging on to good peers, wasting slots and bandwidth. On testnets they could linger for months.
EIP-2124 defines a compact fork identifier that summarizes a chain's genesis and fork history, plus rules for deciding from it whether to connect.
How it works
Each node computes two values:
FORK_HASH: IEEE CRC32 of the genesis hash followed by every fork block number that has already passed, each as a big-endianuint64, in ascending order. Forks at the same block are counted once; rules active from genesis do not count as forks.FORK_NEXT: the block number of the next known fork, or0if none.
The fork ID is RLP([FORK_HASH, FORK_NEXT]). It is cross-validated, not just compared:
- Same hash: connect, unless the remote announces a next fork that we have already passed locally.
- Remote hash is one of our earlier states and its next fork matches our next fork after that: connect (remote is syncing).
- Remote hash is a later state we can reach with our known future forks: connect (we are syncing).
- Otherwise reject.
CRC32 is used because it fits 4 bytes, uses all input, and is available everywhere. A cryptographic hash would add nothing since peers can lie anyway. The small size matters because node records (EIP-778) have only 300 bytes in total.
Sample code
Computing mainnet's early fork hashes in Python, matching the spec's values:
import struct, zlib
genesis = bytes.fromhex(
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
h = zlib.crc32(genesis)
print(hex(h)) # 0xfc64ec04 (Frontier)
h = zlib.crc32(struct.pack(">Q", 1_150_000), h)
print(hex(h)) # 0x97c2c34c (Homestead)
h = zlib.crc32(struct.pack(">Q", 1_920_000), h)
print(hex(h)) # 0x91d1f948 (DAO fork)
RLP encoding examples from the spec: {Hash: 0, Next: 0} encodes to c6840000000080, and {Hash: 0xdeadbeef, Next: 0xbaddcafe} to ca84deadbeef84baddcafe.
Things to know
- Status: Final. It is used in the
eth/64handshake (EIP-2364) and laterethprotocol versions, and in discovery records. The reference implementation is go-ethereum'score/forkidpackage. - The spec deliberately does not handle clean separation of three-way splits at the same block.
- Peers advertise only one future fork, because future forks can be postponed; hashing them in would split the network prematurely.
- Since the Shanghai upgrade, forks are scheduled by timestamp rather than block number. EIP-6122 extends the fork ID to handle timestamp-based forks.