EIP-1959 Chain ID history verification opcode (New Opcode to check if a chainID is part of the history of chainIDs)

No call decision · EVM & execution · EIP status Stagnant · created 2019-04-20

This adds a new opcode, VALID_CHAINID. With this opcode, a smart contract can directly check whether a given chain ID was a value valid at some point in that chain's history, from genesis to the present.

Why it is needed

EIP-155 uses the chain ID to prevent replay attacks across different chains. Off-chain messages such as EIP-712 signatures, state channels, and meta-transactions also use the chain ID to distinguish validity, but there is a problem: a hard fork can change the chain ID itself. The earlier EIP-1344 lets a contract look up only the "current" chain ID, so if a hard fork changes the chain ID, messages signed before that point become invalid all at once. Meta-transactions can get by with re-signing, but services where the entire off-chain state is at stake, such as state channels, risk having their whole state become inaccessible at the moment of the fork. Avoiding this requires building separate cache logic per contract to track past chain IDs, which is more costly and easy to miss.

What changes

Today

After EIP-1959

Who is affected

In depth

Opcode specification

The VALID_CHAINID opcode is added at position 0x46. It takes one stack argument: a 32-byte value representing the chain ID to check. It pushes 0x1 onto the stack if that value is one of the chain IDs (including the current value) that have been valid for that chain from genesis to the present, and 0x0 otherwise. The execution cost is set equal to G_blockhash.

Difference from EIP-1344

EIP-1344 lets contracts query only the 'latest' chain ID. This exposes a problem: the moment a hard fork changes the chain ID, every L2 message signed before that point gets rejected. The EIP-1344 discussion notes that validating an older chain ID requires a contract to implement its own trust cache, but this caching approach has higher overall gas cost and creates a gap during the short window before the cache updates, in which even the immediately preceding chain ID is treated as invalid.

Viewing off-chain messages as part of chain state

The premise of this proposal is that an off-chain message signed with a valid chain ID should be considered part of that chain's off-chain state from the moment it was signed. Just as on-chain state carries through before and after a hard fork, off-chain messages should not suddenly become invalid simply because a hard fork occurred. VALID_CHAINID is presented as a simple, safe means of upholding this principle.

Replay protection and the wallet's role

When requesting a signature, a wallet always uses that chain's 'latest' chain ID. This prevents replay between chains with different chain ID histories. At the same time, among multiple forks that share the same chain ID history up to the branch point, a message signed with an older chain ID can be reused, which is described as intended behavior that preserves the validity the user expected at the time of signing.

Replay vulnerability and limits for minority forks

In a contentious hard fork, if the majority chain does not change its chain ID, a message newly signed on the majority chain can also be replayed on the minority fork (which shares the same chain ID history). This problem exists in EIP-1344 as well. Including a block number in the signed message to check chain ID validity at that point is mentioned as an alternative, but it has the limitation that it cannot be enforced, since it's useless if the contract skips the check. This proposal assumes the minority fork will not draw later attention and does not separately address this issue.

Gas cost pricing

The opcode's execution cost is priced the same as G_blockhash. The original text notes that this cost may need to be adjusted later as the number of values included in the chain ID history grows.

Backwards compatibility

It is fully compatible with every chain that already implements EIP-155's chain-ID-based signature differentiation, and existing contracts are unaffected. However, it also suggests it would help further to modify EIP-712, which is still in Draft status, to separate the chain ID from the domain separator and, where needed, let contracts dynamically compute or cache the chain ID.

Progress status

This EIP is currently in Stagnant status. Both the Test Cases and Implementation sections remain TBD, and the original text does not indicate any actual implementation or fork-inclusion decision.

Original EIP · ← EIPs