ERC-7785 On-chain registration of chain identifiers (Onchain registration of chain identifiers)
Draft · Names & metadata · created 2024-09-26
Proposes hashing a chain name to produce a 32-byte chain identifier, and mapping names to identifiers via ENS to replace the centralized GitHub list.
Why it is needed
Currently, the correspondence between chain names and identifiers, such as Mainnet being 0x1, is managed by a single centralized list on GitHub. This approach has two problems. First, it does not scale as the number of L2s keeps growing. Second, whoever manages the list becomes a single point of failure that can block or censor registrations. Furthermore, if names and identifiers are not fixed one-to-one, spoofing attacks become possible. An attacker could link a newly created name (e.g. my-testnet) to an already-used mainnet identifier (0x1), so that a user believes they are signing a harmless testnet transaction while actually signing a mainnet transaction, and the attacker can then relay this signature directly to mainnet.
In depth
Extending chain identifiers to 32 bytes and deriving them via hash
Current chain identifiers are short and arbitrarily assigned; as their number grows, it is proposed to extend them to 32 bytes and derive them using a cryptographic hash function. The input must include the chain name (CHAIN_NAME), with other information optional. For L2s, the example given is chain_id = Keccak-256(CHAIN_NAME, SETTLEMENT_CHAIN_ID, VERSION, DEPLOYER_CONTRACT_ADDRESS, SALT). SETTLEMENT_CHAIN_ID is the id of the L1 (mainnet or testnet) the L2 settles to, VERSION is an arbitrary string distinguishing the hash function's domain, and DEPLOYER_CONTRACT_ADDRESS is the L2's address on L1.
Resolving chain names via ENS
Any ENS name can be resolved to a chain identifier in the manner defined by ERC-2304. The record the name points to must contain not only the identifier but also the additional information needed to verify that identifier. As an example, on mainnet the name rollup resolves as rollup.eth -> {version, bridge, chain_id}, and it is verified by recomputing chain_id == hash("rollup", 0x1, version, bridge) and checking the value matches.
Spoofing and replay attacks, and the principle of prevention
The existing centralized list guarantees a one-to-one correspondence between names and identifiers. Without this guarantee, an attacker could bind a new name such as my-testnet to the mainnet identifier 0x1. The user believes they are signing a seemingly harmless transaction for my-testnet, but is actually signing a mainnet transaction, and the attacker can replay this signature on mainnet. Deriving the identifier from the name via a hash function and verifying legacy identifiers through a reverse mapping eliminates this kind of spoofing.
Compatibility with existing (legacy) identifiers
Existing identifiers that were not derived using this proposal's method can still be supported by verifying uniqueness through a reverse mapping from identifier to name. For example, if legacy-rollup.eth resolves to identifier 0x123, you check whether looking up 0x123 in reverse under the chainid.reverse domain returns a chain_name equal to legacy-rollup. If the two values match, the mapping is considered valid.
Bootstrapping and handover procedure
To begin handling legacy chain identifiers, the Ethereum Foundation (EF) envisions first populating two subdomains, l2.eth and chainid.reverse, using the existing Ethereum list. Afterward, when a rollup registers its own rollup.eth to point to its chain_id, the EF transfers rollup.l2.eth and chain_id.chainid.reverse to that rollup. The rollup then updates the transferred chain_id.chainid.reverse so that it returns rollup.eth.
Unresolved points and the proposal's status
This ERC is in Draft status, a proposal that can still change or be discontinued. The Rationale section remains TBD, so the reasoning behind the design decisions and comparisons with alternatives have not yet been written. It is also unconfirmed whether ERC-2304 can sufficiently replace ENSIP-11, since the original text itself marks this as a TODO.
Things to watch out for
- Replay attacks via domain spoofing: If the one-to-one correspondence between names and identifiers breaks down, spoofing can enable replay attacks. This can be eliminated by generating newly derived identifiers with a hash function and verifying legacy identifiers through a reverse mapping.
- Potential for domain squatting: There is a possibility of domain squatting, where names are preemptively registered in bulk to sell at a high price later. However, as long as L2 registrations keep increasing, the same problem is expected to appear even with the existing centralized GitHub list.