EIPs Explained

EIP-2294 · Stagnant · Informational · 2019-09-19

EIP-2294: Explicit bound to Chain ID size

Proposes explicit upper bounds on chain ID values, a JavaScript-safe range up to 2^31-1 and a hard maximum that keeps EIP-155 signature math inside uint64, so wallets, clients and contracts agree on every ID.

What problem does it solve?

EIP-155 introduced the chain ID for replay protection but never said how large it may be. In principle it is an arbitrary integer, and EIP-1344 exposes it to contracts as a 256-bit word. In practice different components store it differently:

  • Legacy transactions encode it inside the signature's v value as chainId * 2 + 35 or + 36, which overflows fixed-width integers for very large IDs.
  • JavaScript tooling often handles it as a number, which loses precision above 2^53 and is commonly treated as a 32-bit value.
  • EIP-712 domains and ERC-1271 verification hash the chain ID, so two components disagreeing on its value means signatures that verify in one place and fail (or replay) in another.

With L2s, L3s and app chains multiplying, the authors wanted a clear statement of which values are safe.

How it works

The EIP defines two ranges, informationally:

Range Bounds Reason
Safe Range 1 to 2^31 − 1 (2,147,483,647) Representable everywhere, including common JavaScript handling
Max Range 1 to MAX_CHAIN_ID Keeps EIP-155 arithmetic within uint64
MAX_CHAIN_ID = floor(MAX_UINT64 / 2) - 36 = 9,223,372,036,854,775,771

The largest intermediate value in EIP-155 math is chainId * 2 + 36, so this bound guarantees no overflow with 64-bit unsigned arithmetic. Zero and negative values are not allowed.

The ~63 bits of the max range also leave room for ideas like hash-derived chain IDs for temporary or forked chains, without making collisions likely in normal use.

Sample code

Validating a chain ID before adding a network or signing (TypeScript):

const SAFE_MAX = 2n ** 31n - 1n;                   // 2147483647
const MAX_UINT64 = 2n ** 64n - 1n;
const MAX_CHAIN_ID = MAX_UINT64 / 2n - 36n;        // 9223372036854775771n

type Verdict = "safe" | "max-range" | "invalid";

function checkChainId(id: bigint): Verdict {
  if (id < 1n) return "invalid";
  if (id <= SAFE_MAX) return "safe";
  if (id <= MAX_CHAIN_ID) return "max-range";      // fine for clients, risky for JS number-based tools
  return "invalid";
}

// Legacy (EIP-155) v value stays within uint64 for any max-range ID
const v = (id: bigint, recovery: 0n | 1n) => id * 2n + 35n + recovery;

console.log(checkChainId(1n));            // "safe"
console.log(checkChainId(MAX_CHAIN_ID));  // "max-range"
console.log(v(MAX_CHAIN_ID, 1n) <= MAX_UINT64); // true

Things to know

  • Status is Stagnant and the type is Informational: it describes recommended limits but does not change consensus rules.
  • The authors state that, as of 2022, no known chain used an ID outside these bounds.
  • If you are choosing a chain ID for a new network, staying inside the Safe Range avoids problems with wallets and libraries that treat it as a JavaScript number.
  • Always handle chain IDs as bigint (ethers v6 already does) rather than number in new code.

#chain-id #transactions #signatures #wallets #informational

Details

Authors
Zainan Victor Zhou (@xinbenlv), Alex Beregszaszi (@axic), Bryant Eisenbach (@fubuloubu)
Status
Stagnant
Type
Informational
Created
2019-09-19
Requires

Machine-readable: Markdown · JSON