Verified contractPartialLicenseRef-DCL-1.0
AddressRegistry
Address0xdbb7cf1cba967d2d577045e138eed359675a6fa7
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.25
- Same code
Only this contract
Details
- Compiler
- solc 0.8.25+commit.b61c2a91
- Language
- solidity
- Optimization
- Yes, 100,000 runs
- EVM version
- cancun
- License
- LicenseRef-DCL-1.0
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,970,800
- Creation transaction
- 0x55b86ef8be…1a08e7bcf3
2 files
- src/concrete/AddressRegistry.solmain3.48 KB
- src/interface/IAddressRegistryV1.sol4.82 KB
src/concrete/AddressRegistry.sol
// 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";
/// @dev The only account that may bind a name. A compile-time constant rather
/// than storage, so it can never be rotated, and part of the creation code, so
/// changing it changes the deterministic deploy address and code hash of
/// `AddressRegistry` on every network.
///
/// Rotating it is an ordinary source change that moves the creation code, and
/// therefore the deploy address, the code hash, the snapshot `script/Build.sol`
/// generates and the release that carries them.
address constant ADDRESS_REGISTRY_ROOT = 0x0b300013CD54a8F1aC40981f80FaaA18b8Cc1E4c;
/// @title AddressRegistry
/// @notice The whole of `IAddressRegistryV1`: an immutable root authority binds
/// a `bytes32` name, anyone reads a bound name, and a read of an unbound name
/// reverts.
///
/// There is deliberately nothing else. No removal, no upgrade, no pause, and no
/// authority besides root — root is a compile-time constant, so it cannot even
/// hand itself over.
///
/// A binding is mutable because the address it names is. Rotating an owning
/// multisig is ordinary business and has to be expressible without moving
/// anybody's deterministic address, which a binding welded to one address
/// forever would make impossible: the name is in the consumer's creation code,
/// so a new name means new creation code and a new address.
///
/// Mutability costs nothing already deployed. A consumer resolves a name once,
/// in its constructor, and never reads the registry again, so re-binding a name
/// changes what the next deployment resolves and nothing else — a rotation is a
/// deliberate migration, never a silent change to live contracts.
///
/// The storage mapping is `internal` rather than `public`: a public mapping's
/// generated getter answers an unbound name with the zero address, which is
/// exactly the silent failure `get` reverts to prevent.
contract AddressRegistry is IAddressRegistryV1 {
/// The bindings. Not `public`: the only reader is `get`, which reverts on an
/// unbound name. A name maps to the zero address if and only if it is
/// unbound, which is why `register` rejects the zero address.
mapping(bytes32 name => address account) internal sAddresses;
/// @inheritdoc IAddressRegistryV1
function register(bytes32 name, address account) external {
if (msg.sender != ADDRESS_REGISTRY_ROOT) {
revert NotRoot(msg.sender);
}
// Rejected so that a name can never be both bound and unreadable. There
// is deliberately no way to unbind a name; the nearest thing is
// re-binding it to something inert.
if (account == address(0)) {
revert ZeroAccount(name);
}
sAddresses[name] = account;
emit Register(name, account);
}
/// @inheritdoc IAddressRegistryV1
/// @dev Returns whatever root has bound most recently. A caller that needs
/// an answer that cannot move reads once and stores it, which is what a
/// consumer resolving a name in its constructor does.
function get(bytes32 name) external view returns (address) {
address account = sAddresses[name];
if (account == address(0)) {
revert NameNotRegistered(name);
}
return account;
}
}
src/interface/IAddressRegistryV1.sol
// 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 (`register`), and
/// anyone reads a bound name (`get`). Root may re-bind a name it has already
/// bound. There is no removal, no upgrade and no authority beyond root, and an
/// implementation MUST NOT add any.
///
/// 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.
///
/// Bindings are mutable because the addresses they name are. Rotating an owning
/// multisig is ordinary business, and a binding that could never change would
/// make it impossible: the name a consumer resolves is in that consumer's
/// creation code, so a name welded to one address forever would force a new
/// name — and therefore new creation code and a new deterministic address — for
/// a routine rotation. That is the problem the registry exists to remove, not a
/// property worth keeping.
///
/// A binding moving never moves anything already deployed. A consumer resolves
/// a name once, at construction, and stores the answer; it never consults the
/// registry again. So re-binding a name changes what the *next* deployment
/// resolves and nothing else, which is exactly what makes a rotation a
/// deliberate migration rather than a silent, retroactive change to live
/// contracts.
///
/// A compromised root therefore cannot touch anything deployed. It can point a
/// name at an address it controls, so that a deployment made after the
/// compromise snapshots that address. That is caught by verifying a deployment
/// after deploying it and before anything depends on it: the deployed contract
/// has already snapshotted the value, so checking it is checking settled state.
/// A poisoned deploy is a burned deterministic address, discovered before use.
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 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. A name cannot be unbound once bound; the
/// closest thing is binding it somewhere deliberately inert.
/// @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 every time `name` is bound, including when it is re-bound. The
/// log is the complete history of the registry and the only way to discover
/// a binding without already knowing the name; the most recent `Register`
/// for a name is its current binding.
/// @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`, replacing any address it is already bound to.
///
/// The implementation MUST revert `NotRoot` unless the caller is the root
/// authority, and MUST revert `ZeroAccount` if `account` is the zero
/// address. 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 currently 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.
///
/// A caller that needs an answer that cannot move MUST read once and store
/// the result, which is what a consumer resolving a name in its constructor
/// does. Reading at the point of use instead means reading whatever root
/// has bound most recently.
/// @param name The name to read.
/// @return The address bound to `name`. Never the zero address.
function get(bytes32 name) external view returns (address);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 100000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std-1.16.2/=dependencies/forge-std-1.16.2/",
"rain-sol-codegen-0.1.37/=dependencies/rain-sol-codegen-0.1.37/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.