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
- A contract can only know the current chain ID, so it cannot directly verify the validity of a past signature
- Using past history requires the contract to cache it itself, which costs more gas and can create gaps
- In a minority fork, a caching system cannot guarantee the exact block at which the new chain ID was introduced
- If the majority does not change its chain ID, a message meant for the majority chain risks being replayed on the minority chain
After EIP-1965
- The new precompile allows directly querying whether a given chain ID was valid at a given block number
- Cheaper and safer validation of past chain IDs, without a caching contract
- Minority forks can also prevent replay based on their own transition block, without the majority's cooperation
- Including a block number in an EIP-712 signature makes it possible to distinguish message validity before and after a fork
Who is affected
- Wallet & app developers: EIP-712-signed messages must be modified to include not just chainID but also blockNumber, with both placed in the message body rather than the domain separator
- Users: Even if a fork occurs, the risk that a signed message gets replayed on an unintended chain is reduced
- Client teams: A new precompile (costing G_blockhash + G_verylow gas) must be implemented
- Minority fork operators: Even if the majority does not change its chain ID, independent replay protection becomes possible based on the fork's own transition block
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.