Repository navigation
feat(adapters)!: resolve chain ids through a governed ChainIdRegistry - #13
Merged
Merged
Conversation
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.
feat(adapters)!: resolve chain ids through a governed ChainIdRegistry
`setChainIdPair` wrote `_fromNative` unconditionally, so two standard chain ids could claim one bridge selector. `_fromNative` then stopped being the inverse of `_toNative`: the loser kept sending over the shared selector and paying real CCIP fees, while inbound traffic over it resolved to the winner, so `ccipReceive` attributed a genuine message to the wrong origin chain. That also made the `delete` of the previous reverse entry unsafe. It never checked the entry belonged to the chain being written, so repairing the collision cleared a bystander's inbound lane -- a chain named in neither the call nor any emitted event. Rejecting the second claimant closes both. With exclusivity enforced, `_fromNative[previous]` is by construction the caller's own entry, so the delete needs no ownership check. Reassigning a selector now means clearing its owner first; both calls fit in one proposal. Also switch `ChainsFixture.ccipSelector` to `SafeCast.toUint64`. The selectors used to be `uint64` constants, so an over-wide one was a compile error. Read from JSON, a plain cast truncated silently and every assertion reading the same file agreed with itself on the wrong value. Verified by mutation: an extra digit now fails 16 tests where it previously failed none.
`id(Transaction)` spelled `abi.encode` independently of `encode()`, so the invariant that `id(bytes)` only matches it for canonically encoded payloads was held by convention across two lines rather than structurally. Routing through `encode()` means a future change to the encoding cannot desync the two overloads. Byte-identical output; no behaviour change.
giorgilagidze
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 underdelegatecall.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.BaseAdapterowns both mappers now, non-virtual, turning the registry's0into the revertIBaseAdapterrequires.CCIPAdapterloses both constant tables — its call sites are unchanged, because they already went through those functions.What falls out
TestnetCCIPAdapterdeletedTest_Deploy.s.solnow deploys a registry and the shipping adapter, so a testnet rehearsal exercises the contract that shipsChainIds.sol/CCIPChainIds.soldeletedsrc/; values moved totest/fixtures/chains.jsonOversizedSelectorCCIPAdapterdeleteduint64is reachable through config nowTests seed their registries from
chains.jsonrather 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
setChainIdPairthrough governance rather than replacement adapters on both sides.MANAGE_CHAIN_ID_REGISTRY_PERMISSIONwarrants the same governance rigor asMANAGE_CONTROLLER_CONFIG_PERMISSION: its holder can repoint a live lane in one call, redirecting both outbound sends and inbound attribution. Monitoring that watcheschainToAdapterwill not see it — watchChainIdPairSettoo.Review
Four adversarial agents went at this (deploy/ops, security, simplicity, docs). No fail-open path was found. Traced and confirmed clean:
STATICCALL— a malicious or buggy registry cannot reenter or corrupt controller state. Its entire capability is: return a number, revert, or burn gas.receiveMessagere-anchors on the payload'soriginChainId, 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
uint64bound, 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
uint64constraint insideChainIdRegistry. Baking one bridge's width into a protocol-agnostic table would break LayerZero next, whose EIDs areuint32;SafeCastat the adapter is the backstop.Verification
386/386 pass, 0 skippedunder forge 1.4.0 (the CI pin — local 1.7.1 formats differently):That includes
test_fork_everyMappedSelectorIsALiveLane, which now validates all 15 mainnet entries ofchains.jsonagainst the real Ethereum CCIP router._chainSelectorPairsstays an independent transcription — that check is worthless if both sides are copied from one place.