Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines EIP-155, which introduces a mechanism for preventing replay attacks across Ethereum networks.

This article translates, summarizes, and supplements the material linked below.

I have also covered other ERCs.

Overview

EIP-155 is an improvement proposal for Ethereum transaction signing designed to prevent replay attacks. A replay attack occurs when a transaction executed on one network is reused without authorization on another network.

EIP-155 addresses this problem by introducing a new element, CHAIN_ID, into the transaction signing process.

The following resource covers reentrancy and other smart contract security topics. Reentrancy is distinct from cross-chain replay.

https://chaldene.net/bug-bounty

Specification

Main Changes

Block Number and the Use of CHAIN_ID

Starting at the specified fork block (FORK_BLKNUM), transaction signatures can include CHAIN_ID. This binds a protected transaction to its intended chain identifier.

Changes to the Signing Process

  • Previously
    • Transaction signing used six elements: nonce, gasprice, startgas, to, value, and data.
  • New process
    • Adds CHAIN_ID and two zero values, making nine elements in the signing preimage.

Why Add Two Zero Values?

  • Format compatibility
    • Introducing `CHAIN_ID) changes the signing data format. The two zero values are part of the nine-element format used by EIP-155, distinguishing it from the original six-element signing preimage.
  • Extensibility
    • The Japanese article describes the zeros as placeholders for future extensions. The EIP-155 specification actually fixes both values at zero; implementations must not substitute arbitrary values for them.
  • Security
    • Incorporating CHAIN_ID binds the signature to the intended network and prevents unauthorized reuse on networks enforcing different chain IDs.

The additional values form part of EIP-155's new signing format. The chain ID is the key component providing cross-chain replay protection.

Setting the Signature's v Value

  • Previously
    • v was {0,1} + 27.
  • New rule
    • v becomes {0,1} + CHAIN_ID * 2 + 35.
    • When hashing only six elements, the original v values continue to apply.

Changes to Signature Recovery

When the chain-specific v values CHAIN_ID * 2 + 35 or CHAIN_ID * 2 + 36 are used, the transaction signing hash must be reconstructed from nine elements.

The previous signature scheme, using v = 27 or v = 28, remains valid.

The change enables verification that a protected transaction was signed for a particular chain ID, strengthening security against cross-chain replay. Legacy unprotected signatures remain subject to replay risk.

Example

The example illustrates how an Ethereum transaction is signed, focusing on how its data is processed and signed with a private key.

Transaction Parameters

  • nonce (9)
    • The transaction sequence number.
  • gasprice (20 * 10^9)
    • The price per unit of gas, 20 Gwei in this example.
  • startgas (21000)
    • The transaction's gas limit.
  • to (0x3535353535353535353535353535353535353535)
    • The address receiving Ether.
  • value (10^18 wei)
    • The amount sent, 1 Ether in this example.
  • data
    • No additional transaction data.

Signing Process

  1. Construct the signing data
    • Encode the applicable parameters using RLP.
  2. Calculate the signing hash
    • Compute the hash of the encoded data.
  3. Sign with the private key
    • Sign the hash using the specified private key.
    • The signature contains three values, (v, r, s).

Key Points

  • Change in the v value
    • The original values are 27 and 28. EIP-155 incorporates CHAIN_ID; this example uses 37.
  • Signed transaction format
    • After signing, the transaction is serialized for transmission over the network.

The example shows how EIP-155 changes the signing process to produce a transaction bound to a particular network, mitigating cross-chain replay attacks.

Additional Notes

EIP-155 helps prevent transactions from being replayed across Ethereum and other Ethereum-based blockchains, such as Ethereum Classic and the historical Morden testnet.

Key Points of EIP-155

Network Separation

  • EIP-155 provides a way to prevent protected transactions on Ethereum (ETH) from being executed on Ethereum Classic (ETC) or Morden when the networks use and enforce different chain IDs.

Use of CHAIN_ID

  • The proposal recommends distinct CHAIN_ID values for different networks.
  • ETC should use a different CHAIN_ID, and future testnets and alternative Ethereum chains are encouraged to adopt their own identifiers.

EIP-155 defines rules that help Ethereum and similar networks operate separately. Distinct chain IDs help prevent signed transactions from being reused without authorization on other networks.

Chain ID List

The following table reproduces the historical chain ID examples discussed in the article. Several of these test networks have since been retired; the table is not a recommendation for current testnet selection.

CHAIN_ID Table

CHAIN_ID Network Description
1 Ethereum Mainnet Ethereum's primary public network.
2 Morden (retired) and Expanse Mainnet Morden was a testnet; Expanse is another blockchain project.
3 Ropsten A historical Ethereum testnet.
4 Rinkeby A historical Ethereum testnet popular with DApp developers.
5 Goerli Another widely used historical Ethereum testnet.
42 Kovan A historical Ethereum testnet.
1337 Geth private chain (historical default) An example of a privately configured Ethereum network using Geth.

Additional Information

Chain IDs distinguish Ethereum-based networks and help prevent confusion between them. Distinct, correctly enforced identifiers improve replay protection.

Citation

Vitalik Buterin (@vbuterin), "EIP-155: Simple replay attack protection," Ethereum Improvement Proposals, no. 155, October 2016. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-155.

Conclusion

This article examined EIP-155, which introduces replay protection into Ethereum transaction signing.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/