-
Notifications
You must be signed in to change notification settings - Fork 0
Address registry: interface, concrete, reader lib and post-deploy cross-network verification #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thedavidmeister
wants to merge
5
commits into
main
Choose a base branch
from
2026-08-08-address-registry-interface-lib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a0cc8d
feat(registry): address registry interface, reader lib and cross-netw…
thedavidmeister 0958f42
test(registry): fork two networks in the cross-network gate test, not…
thedavidmeister bf5ac30
docs: Zoltu deploys with CREATE2 under a zero salt, not CREATE with a…
thedavidmeister 605c1c2
feat(registry): mutable bindings, post-deploy verification, concrete …
thedavidmeister d58d007
test(deploy): repin testDeployZoltu's literal to this repo's compiler…
thedavidmeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity ^0.8.25; | ||
|
|
||
| /// @title IAddressRegistryV1 | ||
| /// @notice A registry of `bytes32` names to addresses with exactly two | ||
| /// operations: an immutable root authority binds a name that is unbound, and | ||
| /// anyone reads a name that is bound. There is no rotation, no removal, no | ||
| /// upgrade and no admin surface, and an implementation MUST NOT add any: the | ||
| /// value of the registry is that a binding, once made, is a constant. | ||
| /// | ||
| /// Names are opaque 32-byte values. This interface says nothing about how a | ||
| /// name is derived — hashed from a string, a raw ASCII literal, a counter — and | ||
| /// an implementation MUST NOT constrain it. Two callers agreeing on a name is | ||
| /// entirely their business. | ||
| /// | ||
| /// The write-once property is what makes a deploy-time check of a binding worth | ||
| /// anything. Against a mutable value the check would be a race, because the | ||
| /// value could move between the check and the read that consumes it. Here, once | ||
| /// `get` returns for a name, it returns the same address forever. | ||
| /// | ||
| /// Compromising root therefore cannot change any existing binding. It can reach | ||
| /// a network nobody has deployed to yet and bind the intended names against | ||
| /// itself, burning them there, which forces a different name on that network | ||
| /// and moves addresses on that network only. That is a loud, per-network loss | ||
| /// of determinism, never a silent or retroactive change. | ||
| interface IAddressRegistryV1 { | ||
| /// Thrown when an account that is not the root authority calls `register`. | ||
| /// @param sender The `msg.sender` that was not root. | ||
| error NotRoot(address sender); | ||
|
|
||
| /// Thrown when `register` is called for a name that is already bound. | ||
| /// Bindings are write-once, so this is thrown even for root, and even when | ||
| /// the account being registered is the account already bound. | ||
| /// @param name The name that is already bound. | ||
| /// @param account The address `name` is bound to. | ||
| error NameAlreadyRegistered(bytes32 name, address account); | ||
|
|
||
| /// Thrown when `register` is called with the zero address. The zero address | ||
| /// is how an unbound name reads, so binding it would produce a name that is | ||
| /// both bound and unreadable, and that `register` would accept a second | ||
| /// time. | ||
| /// @param name The name that was being bound to the zero address. | ||
| error ZeroAccount(bytes32 name); | ||
|
|
||
| /// Thrown by `get` when a name has never been bound, so that a caller | ||
| /// cannot silently proceed on the zero address by forgetting to check. | ||
| /// @param name The name that is not bound. | ||
| error NameNotRegistered(bytes32 name); | ||
|
|
||
| /// Emitted when `name` is bound to `account`. Bindings are write-once, so | ||
| /// exactly one `Register` is ever emitted per name, and the log is the | ||
| /// complete enumeration of the registry — there is no other way to discover | ||
| /// a binding without already knowing the name. Both parameters are indexed | ||
| /// for that reason: the log has to answer "what is this name bound to" and | ||
| /// "what did root bind to this address" without a full scan. | ||
| /// @param name The name that was bound. | ||
| /// @param account The address `name` was bound to. | ||
| event Register(bytes32 indexed name, address indexed account); | ||
|
|
||
| /// Binds `name` to `account`, permanently. | ||
| /// | ||
| /// The implementation MUST revert `NotRoot` unless the caller is the root | ||
| /// authority, MUST revert `ZeroAccount` if `account` is the zero address, | ||
| /// and MUST revert `NameAlreadyRegistered` if `name` is already bound — | ||
| /// including when the caller is root and including when `account` is the | ||
| /// address already bound. On success it MUST emit `Register`. | ||
| /// @param name The name to bind. | ||
| /// @param account The address to bind it to. | ||
| function register(bytes32 name, address account) external; | ||
|
|
||
| /// The address `name` is bound to. | ||
| /// | ||
| /// The implementation MUST revert `NameNotRegistered` when `name` is | ||
| /// unbound, rather than returning the zero address, so that no caller has | ||
| /// to remember to check. It MUST NOT expose any other reader that returns | ||
| /// the zero address for an unbound name, as that reintroduces exactly the | ||
| /// mistake this reverting read exists to prevent. | ||
| /// @param name The name to read. | ||
| /// @return account The address bound to `name`. Never the zero address. | ||
| function get(bytes32 name) external view returns (address account); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity ^0.8.25; | ||
|
|
||
| import {IAddressRegistryV1} from "../interface/IAddressRegistryV1.sol"; | ||
|
|
||
| /// @title LibAddressRegistry | ||
| /// @notice Reads the `IAddressRegistryV1` deployed at a single deterministic | ||
| /// address on every network, verifying the registry's code hash first, exactly | ||
| /// as `LibRainDeploy` verifies `ZOLTU_FACTORY_CODEHASH` before using the Zoltu | ||
| /// factory. An address alone says nothing on a chain the caller has not | ||
| /// audited; the address plus the code hash says the caller is talking to the | ||
| /// registry it compiled against. | ||
| /// | ||
| /// That is the whole library. It resolves a name to an address. What a consumer | ||
| /// resolves a name for, and when — an owner set in a constructor or an | ||
| /// initializer, under `Ownable` or RBAC or nothing at all — is entirely the | ||
| /// consumer's business and none of this library's. | ||
| library LibAddressRegistry { | ||
| /// Thrown when the code at the registry address is not the registry this | ||
| /// library was compiled against. An address with no code hits this too: an | ||
| /// empty account's code hash is zero (or the hash of empty code), never the | ||
| /// expected value. | ||
| /// @param expectedCodeHash The code hash of the pinned registry. | ||
| /// @param actualCodeHash The code hash actually found at the address. | ||
| error UnexpectedAddressRegistryCodeHash(bytes32 expectedCodeHash, bytes32 actualCodeHash); | ||
|
|
||
| /// The deterministic Zoltu deploy address of `AddressRegistry`, the same on | ||
| /// every network. | ||
| /// | ||
| /// Derived from that contract's creation code, not observed from a chain: | ||
| /// the Zoltu factory is `CREATE2` over its calldata with a zero salt, so the | ||
| /// address is a pure function of the creation code | ||
| /// (`LibRainDeploy.zoltuAddress`). The root authority is a constant in that | ||
| /// creation code, so changing the root moves this address, and both this and | ||
| /// `ADDRESS_REGISTRY_CODEHASH` MUST be re-derived whenever it changes. | ||
| address constant ADDRESS_REGISTRY = 0x619e47868cE4a9AEbBD6444c9385f1558c79ED52; | ||
|
|
||
| /// The code hash of `AddressRegistry` once deployed, i.e. `keccak256` over | ||
| /// the runtime code its creation code leaves behind. Derived from the same | ||
| /// compilation as `ADDRESS_REGISTRY`, and moves with it. | ||
| bytes32 constant ADDRESS_REGISTRY_CODEHASH = 0x01e8bf67abc9d4b4abe2d39c66c07c1b02e39bdf559c694f94f5853bad6394d8; | ||
|
|
||
| /// The address a name is bound to in the registry. | ||
| /// | ||
| /// Verifies the registry's code hash before reading, so a chain where the | ||
| /// registry is absent, or where something else occupies its address, is a | ||
| /// loud revert rather than a call into unknown code. The registry itself | ||
| /// reverts on an unbound name, so a returned address is always a real | ||
| /// binding and is never the zero address. | ||
| /// @param name The name to resolve. Opaque; the registry constrains nothing | ||
| /// about how it was derived. | ||
| /// @return The address bound to `name`. | ||
| function resolve(bytes32 name) internal view returns (address) { | ||
| bytes32 actualCodeHash = ADDRESS_REGISTRY.codehash; | ||
| if (actualCodeHash != ADDRESS_REGISTRY_CODEHASH) { | ||
| revert UnexpectedAddressRegistryCodeHash(ADDRESS_REGISTRY_CODEHASH, actualCodeHash); | ||
| } | ||
| return IAddressRegistryV1(ADDRESS_REGISTRY).get(name); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.