Ethereum Basics – Difference Between ChainID and NetworkID

genesisgo-ethereumprivate-blockchain

Here it's described in Ethereum's go implementation.

type ChainConfig struct {
    ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection

A few questions:

  1. How is it different than networkID?
  2. Is chainID and networkID needed in every block or just the genesis block?
  3. Can you give a specific example of what it means when it says chainID is used "for replay protection"?

EDIT: Still unanswered:

What would happen in the situation that you set networkID to one of the mainnet networkIDs, but change the other config variables to whatever you want? Why does it matter what you set for networkID if you're running a local chain?

Best Answer

How is it different than networkID?

ChainID was introduced in EIP-155 to prevent replay attacks between the main ETH and ETC chains, which both have a networkID of 1.

It's basically just an additional way to tell chains apart. Subsequent to EIP-155, ETH has a chainID of 1, while ETC has a chainID of 61 (even though they still have the same networkID of 1).

Is chainID and networkID needed in every block or just the genesis block?

It's required for the chain to operate in general - e.g. it's required when signing transactions, meaning transactions signed on the ETH network end up with a different hash than those signed on ETC. Before EIP-155, signed transactions on each network would look the same, and could be replayed.

Edit:

A specific example of how chainId is used.

As per the EIP-155 page, the v value of a transaction's signature is dependent on the value of chainID.

If block.number >= FORK_BLKNUM and v = CHAIN_ID * 2 + 35 or v = CHAIN_ID * 2 + 36, then when computing the hash of a transaction for purposes of signing or recovering, instead of hashing only the first six elements (i.e. nonce, gasprice, startgas, to, value, data), hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0. The currently existing signature scheme using v = 27 and v = 28 remains valid and continues to operate under the same rules as it does now.

There is a detailed example of how this is applied on the EIP-155 page.

Related Topic