EIPs Explained

EIP-3788 · Stagnant · Core · 2021-09-02

EIP-3788: Strict enforcement of chainId

Proposed making nodes reject any transaction whose chainId does not match their own, closing the loophole where chainId 0 transactions can be replayed across chains.

What problem does it solve?

EIP-155 added a chain ID to signed transactions so a transaction signed for one network cannot be replayed on another. But, as this EIP points out, a transaction with chainId = 0 is still treated as valid. That was kept deliberately, so developers could create transactions that work on any chain.

With many EVM-compatible networks built from forks of Ethereum clients, that escape hatch became a risk. Most wallets do not show users which chain ID they are signing. A malicious (or careless) network could get users to sign chainId = 0 transactions and then replay them on Ethereum mainnet or elsewhere.

How it works

From a fork block N, a node rejects any transaction whose chain ID differs from the chain ID in its own configuration. In particular, chainId = 0 transactions become invalid.

if node.config.chainId != tx.chainId:
    reject(tx)

The check is applied in two places:

  1. JSON-RPC (eth_sendTransaction, eth_sendRawTransaction): reject early, so users never have a transaction pending that is guaranteed to fail.
  2. Transaction validation during block processing: so such a transaction can never be included in a block.

The node's configured chain ID is the single source of truth.

Sample code

Typed transactions (EIP-2718, e.g. EIP-1559 type-2) always carry an explicit chainId. With ethers v6 the signer fills it in from the connected provider, and you can make the intent explicit:

import { JsonRpcProvider, Wallet, parseEther } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
const { chainId } = await provider.getNetwork();

const tx = await wallet.sendTransaction({
  to: "0x000000000000000000000000000000000000dEaD",
  value: parseEther("0.001"),
  chainId,            // bound to this network only, never 0
});
console.log(tx.chainId); // e.g. 1n on mainnet

Things to know

  • Status: Stagnant. It was never scheduled for a network upgrade.
  • The spec says it would break any application or tooling that still submits chainId == 0 transactions after the fork block.
  • It does not stop someone from launching a network that reuses chainId = 1 or any other existing ID. Replay protection only works when chain IDs are unique.
  • For wallets the practical lesson stands without a fork: always sign with an explicit, correct chain ID and show it to the user.

#transactions #chainid #replay-protection #security #core

Details

Authors
Gregory Markou (@GregTheGreek)
Status
Stagnant
Type
Standards Track / Core
Created
2021-09-02
Requires

Machine-readable: Markdown · JSON