EIP-1965 Per-block chain ID validity check (Method to check if a chainID is valid at a specific block Number)

No call decision · Security & privacy · EIP status Stagnant · created 2019-04-20

An EIP that adds a precompile to check whether a given chain ID was valid at a given block number, preventing a past signed message from being replayed on another chain even after a fork.

Why it is needed

EIP-155 puts a chain ID in transactions to prevent replay on other chains, but when a smart contract verifies an off-chain signed message like an EIP-712 one, there was no comparable protection. EIP-1344 only tells a contract the current chain ID, so learning a past chain ID required the contract to cache history itself, at extra gas cost. In forks led by a minority, the bigger problem is that a caching system cannot guarantee the exact block at which the new chain ID was introduced. The follow-up proposal EIP-1959 solved the caching problem but did not address minority-fork protection. If the majority does not change its chain ID, or ignores the minority, there remains a risk that a message signed for the majority chain could be replayed as-is on the minority chain. EIP-1965 adds block number verification on top of this to close that gap.

What changes

Today

After EIP-1965

Who is affected

In depth

Precompile input/output structure

The new precompile takes two arguments: a 32-byte chainID value and a 32-byte blockNumber value. It returns 0x1 if the given chainID was valid at the given blockNumber, and 0x0 otherwise. A chainID is considered valid up through the block at which it is replaced by a new chainID, and the original text adds that it remains valid at every block number after the replacement as well.

Gas cost

The computation cost does not exceed G_blockhash + G_verylow. Since a chainID is only newly created at a hard fork, the actual cost may be lower. The original text notes that as the number of chainIDs accumulated in chain history grows, the cost may need adjustment later.

Advantages over EIP-1344

EIP-1344 tried to solve the problem by having contracts directly cache historical chainID records. This has higher overall gas costs, and in minority-led forks the caching system cannot reliably guarantee the block number at which a new chainID was introduced. By contrast, the original text explains that an opcode (precompile) approach is cheaper, safer, and leaves no gaps.

Difference from EIP-1959

EIP-1959 solves the caching problem in EIP-1344 but does not address protection for minority-led forks. The original text states that EIP-1965 shares the same rationale as EIP-1959, with the sole difference being that it additionally proposes a way to protect minority forks.

Two fork scenarios

The original text splits forks into two cases. First, when the majority decides to fork and the minority opposes it: if the majority changes its chainID, the minority also has time to change its own chainID at the same block, so the problem resolves naturally. Second, when the minority triggers a fork that the majority opposes or ignores: the majority has no incentive to change its chainID, leaving the risk that messages intended for the majority chain get reused on the minority chain. Including blockNumber among the values being verified invalidates the old chainID from the point the minority switches to a new chainID, blocking this risk.

Compatibility with EIP-712 signatures

At the time the original text was written, EIP-712 was still a draft, but it states that protecting users requires modifying it to include blockNumber among the values being verified. Since both chainID and blockNumber are mutable, they should be included in a different part of the message rather than in the domain separator, which is generated only once. Contracts that do not care about replay may omit this pair, but if chainID is included, blockNumber must also be included alongside it. Wallets should use the latest chainID and blockNumber at signing time, and during a fork transition, blockNumber determines which chainID should be used.

Current status

This EIP's status is Stagnant. It presupposes EIP-155 and originated from discussion of EIP-1344 and EIP-1959. The provided call records contain no discussion of whether this EIP will be included in a fork.

Original EIP · ← EIPs