EIP-2294 Upper bound rule on chain ID value size (Explicit bound to Chain ID size)

No call decision · Security & privacy · EIP status Stagnant · created 2019-09-19

A proposal to clearly define the value range of chain ID, the identifier that distinguishes chains. This is to prevent encoding errors and cross-client inconsistency risks that arise from using excessively large values.

Why it is needed

EIP-155 embeds a chain ID in transactions to prevent the same signature from being replayed on a different chain, but placed no limit on the size of this chain ID value. If the chain ID can grow up to 256 bits, computing the signature's v value and RLP-encoding it can require operations beyond 256 bits. The chain ID has also become queryable from within smart contracts via EIP-1344, and is increasingly used to prevent replay attacks, as in EIP-712 signature domain separation and ERC-1271 on-chain signature verification. If clients, wallets, dApps, and JSON-RPC implementations each handle large chain ID values differently, it can create a consensus-critical vulnerability where validation results diverge, so a clear upper bound that everyone follows is needed.

What changes

Today

After EIP-2294

Who is affected

In depth

Safe Range and Max Range

This EIP defines two ranges for chain ID. The "Safe Range" is (1, 2^31-1), with the upper bound set to a value the Javascript number type can handle safely. The "Max Range" is (1, MAX_CHAIN_ID), where MAX_CHAIN_ID := floor(MAX_UINT64 / 2) - 36 = 9,223,372,036,854,775,771. Values of 0 or less are not allowed in either range.

Why MAX_CHAIN_ID was set to that value

In EIP-155's v value computation, the maximum value that appears during the operation is CHAIN_ID * 2 + 36. MAX_CHAIN_ID is derived by working backward so that this operation does not overflow within uint64 range. Since underflow cannot occur, the lower bound is simply set to 1 without further adjustment. Clients must verify that this overflow condition does not occur even when using the largest chain ID value.

Relationship with EIP-155

EIP-155 introduced the chain ID parameter for domain separation (replay prevention) of signed messages, but set no rules on the size of this value. Allowing the chain ID up to 256 bits would require operations beyond 256 bits when computing the v field in a transaction's RLP encoding. This EIP proposes a reasonable upper bound, allowing a sufficiently large range of chain ID values to be used without causing problems during encoding.

Connection to EIP-1344, EIP-712, and ERC-1271

Use of and dependence on the chain ID field has grown since EIP-1344 made it queryable during smart contract execution. The chain ID is increasingly used to prevent replay attacks, as in EIP-712 signatures and ERC-1271 on-chain signature verification. Without a clearly defined range for the chain ID, implementations of EIP-155 (and its derivative, EIP-1344) could diverge between client codebases and external tools, which could create a consensus-critical vulnerability in the network.

Hash-based temporary chain ID concept

The Motivation section also mentions using a hash-based identifier, whose value can change depending on circumstances such as a contentious fork, instead of the chain ID. This EIP itself does not define how that would work, but notes that about 63 bits of entropy would be enough to make collisions nearly nonexistent under ordinary, non-malicious use.

Backward compatibility

As of the writing date, 2022-10-18, no chain is known to use a chain ID value outside the proposed range, so introducing this upper bound is expected to have no practical impact. If a chain is found operating with an incompatible chain ID, it is recommended that appropriate action be taken when this EIP is adopted.

Security considerations and current status

The Security Considerations section of the source simply states "Needs discussion", with no specific content. This proposal has type Informational and status Stagnant, and is not being actively discussed.

Original EIP · ← EIPs