EIPs Explained

EIP-3220 · Stagnant · Core · 2020-10-21

EIP-3220: Crosschain Identifier Specification

A 32-byte crosschain identifier built from a truncated genesis (or fork) block hash plus chain ID, chain type and a checksum, so chains can be told apart even when they share a chain ID or fork.

What problem does it solve?

EIP-155 gave Ethereum chains an integer chain ID to stop transactions being replayed across networks. That number has limits when you work across many heterogeneous chains:

  • it is just a number, so two unrelated chains can pick the same one,
  • it relies on a public registry rather than anything verifiable from the chain itself,
  • after a contentious fork, both sides may keep the same ID,
  • many non-Ethereum chains have no chain ID concept at all.

The Enterprise Ethereum Alliance's Crosschain Interoperability Task Force wanted an identifier that is unique, self-verifying against the chain's own data, and carries a little descriptive metadata. EIP-3220 proposes one.

How it works

The crosschain ID is 32 bytes, laid out as:

Field Bytes Meaning
Truncated block hash 16 The 16 least-significant bytes of the genesis block hash, or of the block just before a fork for a forked chain
Native chain ID 8 The chain ID used when signing transactions; 0 if the chain has none
Chain type 2 0x00 undefined, 0x01 mainnet, 0x1[0-A] testnet, 0x2[0-A] private dev network
Governance identifier 2 Optional "owner" of a new chain, to help settle fork disputes; 0 for existing chains
Reserved 3 All zero for now
Checksum 1 Least-significant byte of SHA-256 over the other 31 bytes

Because the first field comes from a real block hash, anyone with access to the chain can check that an ID really belongs to it. If it matches neither the genesis hash nor a known fork-point hash, the ID cannot be verified and a crosschain application should reject it. The checksum only catches typing mistakes (1 in 256 false positive).

The EIP also mentions a registration and lookup service for chain metadata but does not specify it.

Sample code

Building and checking an ID (TypeScript, ethers v6 helpers; illustrative, field encoding as described above):

import { concat, dataSlice, sha256, toBeHex, zeroPadValue } from "ethers";

function crosschainId(blockHash: string, chainId: bigint, chainType: number, gov = 0): string {
  const body = concat([
    dataSlice(blockHash, 16, 32),     // 16 least-significant bytes
    toBeHex(chainId, 8),              // native chain ID
    toBeHex(chainType, 2),            // e.g. 0x0001 = mainnet
    toBeHex(gov, 2),                  // governance identifier
    "0x000000",                       // reserved
  ]);
  const checksum = dataSlice(sha256(body), 31, 32); // least-significant byte
  return concat([body, checksum]);
}

function checksumOk(id: string): boolean {
  return dataSlice(sha256(dataSlice(id, 0, 31)), 31, 32) === dataSlice(id, 31, 32);
}

Things to know

  • Status: Stagnant. It never became a finalized standard; Ethereum tooling identifies chains by EIP-155 chain IDs.
  • The crosschain ID is not signed into transactions. Its replay protection relies on applications checking it against block hashes.
  • The spec says the field is the "block hash immediately prior to the fork", but does not define which fork-point to use when a chain forks multiple times.
  • For peer-to-peer detection of which fork a node is on, Ethereum uses the fork identifier from EIP-2124, which also hashes the genesis block together with fork block numbers.

#crosschain #interoperability #chain-id #identifier

Details

Authors
Weijia Zhang (@weijia31415), Peter Robinson (@drinkcoffee)
Status
Stagnant
Type
Standards Track / Core
Created
2020-10-21

Machine-readable: Markdown · JSON