Skip to content

feat(adapters)!: resolve chain ids through a governed ChainIdRegistry - #12

Merged
xavikh merged 1 commit into
registry-auditfrom
feat/chain-id-registry
Aug 26, 2026
Merged

xavikh merged 1 commit into
registry-auditfrom
feat/chain-id-registry

Conversation

@xavikh

@xavikh xavikh commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Targets main.

Every adapter carried its chain-id table in bytecode, so adding a chain to a live deployment meant redeploying the adapter and re-attaching it on the controller through governance on both sides — for a two-integer lookup.

The table is a contract now.

The shape

One registry per bridge protocol. CCIP addresses chains by its own selector, a future LayerZero adapter by something else, and the two are unrelated. The registry is deployed before the adapter and baked in as an immutable, so the send path resolves it correctly under delegatecall.

The table is governable; the binding is not. Adding a chain is one setChainIdPair. Moving an adapter to a different registry still means a new adapter.

BaseAdapter owns both mappers now, non-virtual, turning the registry's 0 into the revert IBaseAdapter requires. CCIPAdapter loses both constant tables — its call sites are unchanged, because they already went through those functions.

What falls out

TestnetCCIPAdapter deleted it existed only to replace the mainnet-only table for testnets. Test_Deploy.s.sol now deploys a registry and the shipping adapter, so a testnet rehearsal exercises the contract that ships
ChainIds.sol / CCIPChainIds.sol deleted no importer left in src/; values moved to test/fixtures/chains.json
OversizedSelectorCCIPAdapter deleted a selector wider than uint64 is reachable through config now

Tests seed their registries from chains.json rather than from a Solidity table only the tests can see.

The trade, stated plainly

Selector correctness moved out of audited bytecode and into config. A wrong-but-nonzero selector is caught by nothing — resolution proves a lane exists, never that it points at the right chain.

That was impossible before, when the table was audited bytecode, and it is the price of making the table configurable. The repair is the same trade in the other direction: one setChainIdPair through governance rather than replacement adapters on both sides.

MANAGE_CHAIN_ID_REGISTRY_PERMISSION warrants the same governance rigor as MANAGE_CONTROLLER_CONFIG_PERMISSION: its holder can repoint a live lane in one call, redirecting both outbound sends and inbound attribution. Monitoring that watches chainToAdapter will not see it — watch ChainIdPairSet too.

Review

Four adversarial agents went at this (deploy/ops, security, simplicity, docs). No fail-open path was found. Traced and confirmed clean:

  • The registry call compiles to STATICCALL — a malicious or buggy registry cannot reenter or corrupt controller state. Its entire capability is: return a number, revert, or burn gas.
  • receiveMessage re-anchors on the payload's originChainId, so no repoint can make a message authenticate as the wrong origin. A repoint can only deny.

Their findings are folded into this commit: the uint64 bound, the corrected claims about what resolution proves, and the docs the change obsoleted — the root README taught a compiled-in table, and SPEC's install recipe listed a four-argument adapter constructor.

Deliberately not done: no uint64 constraint inside ChainIdRegistry. Baking one bridge's width into a protocol-agnostic table would break LayerZero next, whose EIDs are uint32; SafeCast at the adapter is the backstop.

Verification

386/386 pass, 0 skipped under forge 1.4.0 (the CI pin — local 1.7.1 formats differently):

MAINNET_RPC_URL=… BASE_RPC_URL=… forge test

That includes test_fork_everyMappedSelectorIsALiveLane, which now validates all 15 mainnet entries of chains.json against the real Ethereum CCIP router. _chainSelectorPairs stays an independent transcription — that check is worthless if both sides are copied from one place.

🤖 Generated with Claude Code

@xavikh
xavikh force-pushed the feat/chain-id-registry branch from 622c4b1 to 028c18b Compare August 26, 2026 10:39
@xavikh
xavikh changed the base branch from feat/deploy-kit to main August 26, 2026 10:39
Every adapter carried its chain-id table in bytecode, so adding a chain to a live
deployment meant redeploying the adapter and re-attaching it on the controller
through governance on both sides -- for a two-integer lookup.

The table is a contract now. One registry per bridge protocol -- CCIP addresses
chains by its own selector, a future LayerZero adapter by something else, and the
two are unrelated -- deployed before the adapter and baked in as an immutable, so
the send path resolves it correctly under `delegatecall`.

The trade is deliberate: the TABLE is governable, the BINDING is not. Adding a
chain is one `setChainIdPair`; moving an adapter to a different registry still
means a new adapter. What the permission holder gains is not small -- they can
repoint a live lane in one call, redirecting both outbound sends and inbound
attribution, and the adapter follows without notice. It warrants the same
governance rigor as MANAGE_CONTROLLER_CONFIG_PERMISSION.

`BaseAdapter` owns both mappers now, non-virtual, turning the registry's `0` into
the revert `IBaseAdapter` requires. `CCIPAdapter` loses both constant tables; its
call sites are unchanged because they already went through those functions.

Falls out of it:
- `TestnetCCIPAdapter` is gone. It existed only to replace the mainnet-only table
  for testnets; `Test_Deploy.s.sol` now deploys a registry and the shipping
  adapter, so a testnet rehearsal exercises the contract that ships.
- `ChainIds.sol` and `CCIPChainIds.sol` had no importer left in `src/`, so they
  move to `test/fixtures/chains.json`. Tests seed their registries from that file
  rather than from a Solidity table only the tests can see.
- `OversizedSelectorCCIPAdapter` is gone: a selector wider than `uint64` is now
  reachable through config, so the mock had no reason to exist.

What the registry does NOT buy: a wrong-but-nonzero selector is caught by nothing.
Resolution proves a lane exists, never that it points at the right chain. That was
impossible before, when the table was audited bytecode, and it is the price of
making the table configurable -- the repair is the same trade in the other
direction, one `setChainIdPair` instead of replacement adapters on both sides.

The mainnet fork test changed target rather than coverage: it used to validate the
hardcoded table against the real CCIP router, and now validates every mainnet
entry of chains.json the same way. `_chainSelectorPairs` stays an independent
transcription; that check is worthless if both sides are copied from one place.

386/386 pass, forge 1.4.0.
@xavikh
xavikh force-pushed the feat/chain-id-registry branch from 028c18b to a898e6c Compare August 26, 2026 11:27
@xavikh
xavikh changed the base branch from main to registry-audit August 26, 2026 13:53
@xavikh
xavikh merged commit 811097b into registry-audit Aug 26, 2026
4 checks passed
@xavikh
xavikh deleted the feat/chain-id-registry branch August 26, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant