DotnsProtocolRegistry
Inherits: Initializable, UUPSUpgradeable, BootstrapOwnableUpgradeable, IDotnsProtocolRegistry
Title: dotNS Protocol Registry
Author: Parity
Upgradeable address registry for all dotNS protocol contracts, and the authority for the network's top-level domain.
Single source of truth for sibling-contract lookups. All siblings resolve each other via
well-known bytes32 constants in DotnsConstants rather than holding direct addresses,
so an upgrade or rewire only mutates this contract. The TLD node and suffix are set once
at initialisation and read live by every consumer, so a network runs one TLD without
recompiling its contracts.
Note: security-contact: admin@parity.io
State Variables
_addresses
Address stored for each well-known protocol key.
mapping(bytes32 key => address addr) private _addresses
_registeredRefcount
Reference count per address, incremented for every key it is registered under.
Lets isRegisteredAddress answer in O(1) and survive a contract being mapped to
multiple keys without being treated as deregistered when only one key is rewired.
mapping(address addr => uint256 refcount) private _registeredRefcount
_tldNode
Namehash of the TLD node, namehash(0, keccak256(bytes(tldLabel))).
bytes32 private _tldNode
_tld
TLD suffix including the leading dot, e.g. .dot.
string private _tld
_expectedCodehash
Codehash declared for the code that executes for each well-known key.
mapping(bytes32 key => bytes32 codehash) private _expectedCodehash
_protocolVersion
Release tag the network was last declared to run, bare semver (e.g. 0.8.0).
string private _protocolVersion
_keys
Every key that holds an address, so the keys can be listed on chain.
EnumerableSet.Bytes32Set private _keys
__gap
uint256[48] private __gap
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor() ;
initialize
Initialises the protocol registry and fixes the network's TLD.
Callable exactly once via Initializable, otherwise
Note:
reverts: InvalidInitialization. Sets initialOwner as owner. tldLabel is the
bare label without a dot (e.g. dot, paseo); it must be a single DNS label,
otherwise @custom:reverts InvalidTld. The TLD is fixed here because changing it after
names exist would reroot every node.
function initialize(address initialOwner, string calldata tldLabel) external initializer;
Parameters
| Name | Type | Description |
|---|---|---|
initialOwner | address | Bootstrap owner, which governs alongside Root until Root renounces it. |
tldLabel | string | Bare TLD label, without the leading dot. |
get
Returns the address stored for a given key.
Returns address(0) when the key is unset; callers must validate when non-zero is
required.
function get(bytes32 key) external view override returns (address addr);
set
Sets or updates the address for a given key.
Root or the bootstrap owner, otherwise @custom:reverts OwnableUnauthorizedAccount.
addr must be non-zero, otherwise @custom:reverts ZeroAddress. Idempotent when the new
value matches the stored one (no event emitted in that case). Maintains a
per-address refcount so the same contract can occupy multiple keys without losing
its registered status until every key is rewired. Lists key in
Notes:
-
function: keys, including when the address is unchanged. Emits
-
emits: AddressUpdated on each effective change.
function set(bytes32 key, address addr) external override onlyRootOrOwner;
remove
Clears the address stored for a given key.
Root or the bootstrap owner, otherwise @custom:reverts OwnableUnauthorizedAccount. The
key must hold an address, otherwise @custom:reverts KeyNotRegistered. Decrements the
removed
address's refcount, so a contract still reachable under another key keeps its
registered status. Exists because the registry is a discovery directory that would
otherwise only ever grow: a contract retired from the protocol, or one published for
lookup that should no longer be listed, has no other way out. Also clears any
codehash declared for the key, so a later re-registration never starts out with a
stale claim. Drops key from @custom:function keys. Emits
Note: emits: AddressRemoved.
function remove(bytes32 key) external override onlyRootOrOwner;
keys
Returns every key that holds an address.
Lets a client that holds only this registry's address list every key and resolve
each through @custom:function get. Keys are ASCII labels padded to 32 bytes, such as
bytes32("registrar"). The order is unspecified and can change when a key is removed.
function keys() external view override returns (bytes32[] memory registeredKeys);
Returns
| Name | Type | Description |
|---|---|---|
registeredKeys | bytes32[] | Keys that currently hold an address. |
initializeKeys
Lists the well-known keys that already hold an address in @custom:function keys.
For a registry upgraded onto a network whose keys were set before @custom:function keys existed; on a fresh deploy @custom:function set lists every key as it is set. Runs once, through the upgrade that introduces @custom:function keys, otherwise
Note: reverts: InvalidInitialization. Root or the bootstrap owner, otherwise
function initializeKeys() external override reinitializer(2) onlyRootOrOwner;
isRegisteredAddress
Returns true iff addr is currently registered under at least one well-known key.
O(1) refcount-backed lookup answering discovery, not authority: it reports that
governance listed an address, not that the address may act. Store writes and
StoreFactory deploys are gated on the specific components in
Note:
function: StoreAuth.isStoreWriter, not on this, precisely so that listing a
contract for discovery does not confer write authority. Treats address(0) as never
registered regardless of refcount.
function isRegisteredAddress(address addr) external view override returns (bool registered);
tldNode
Returns the namehash of the network's TLD node.
namehash(0, keccak256(bytes(tldLabel))), fixed at initialisation. Consumers use it
as the root parent when deriving a name's node.
function tldNode() external view override returns (bytes32 node);
tld
Returns the network's TLD suffix, including the leading dot (e.g. .dot).
Fixed at initialisation. Consumers append it when rendering a label as a full name.
function tld() external view override returns (string memory suffix);
protocolVersion
Returns the release tag this network was last declared to run, as bare semver
(e.g. 0.8.0, never v0.8.0 and never with build metadata).
Written by the deploy and upgrade tooling as the final step of a fully applied deployment or upgrade, so a crashed or partial run leaves the previous value standing rather than over-claiming. Empty until first set; consumers treat empty as "this deployment predates version declarations" and fall back to probing. A declaration, not a proof: the owner is trusted to keep it truthful, and
Note: function: expectedCodehash is the per-contract cross-check.
function protocolVersion() external view override returns (string memory semver);
setProtocolVersion
Declares the release tag this network runs.
Root or the bootstrap owner, otherwise @custom:reverts OwnableUnauthorizedAccount.
semver must be non-empty, start with an ASCII digit, and contain only alphanumerics,
dots,
and hyphens, otherwise @custom:reverts InvalidProtocolVersion. That admits semver
core and pre-release identifiers (0.8.0, 0.8.0-rc.1) while rejecting the two
values consumers cannot parse and compare: a leading v and + build metadata.
Full semver validation stays in the tooling. Emits
Note: emits: ProtocolVersionSet.
function setProtocolVersion(string calldata semver) external override onlyRootOrOwner;
version
Returns the declared release, mirroring protocolVersion under the historical
version() selector every dotNS contract exposes.
Sibling contracts mirror the same stored value by reading it from here, so
version() answers identically network-wide; this contract is where the value
lives, so it reads its own storage.
function version() external view virtual returns (string memory versionString);
Returns
| Name | Type | Description |
|---|---|---|
versionString | string | Declared release as bare semver, empty when never declared. |
expectedCodehash
Returns the codehash declared for the code that executes for key.
For a proxy entry this is the implementation's codehash; for a plain contract, its
own. bytes32(0) means never declared (or reset). Comparing this against the
actual codehash behind @custom:function get detects an upgrade performed outside
the release tooling: the declaration lives here while the code lives there, so
drift between the two is the signal, and clearing it requires re-declaring, which
is the discipline the check enforces. Verification against release artifacts is
the trustless escalation and lives off chain.
function expectedCodehash(bytes32 key) external view override returns (bytes32 codehash);
setExpectedCodehash
Declares the codehash of the code that executes for key.
Root or the bootstrap owner, otherwise @custom:reverts OwnableUnauthorizedAccount. The
key must currently be registered, otherwise @custom:reverts KeyNotRegistered; a
removal clears the declaration, so an unregistered key never carries a stale
claim. bytes32(0) is allowed as an explicit reset to "undeclared". Kept separate
from @custom:function set so the write API stays minimal: the deploy tooling pairs
the two calls, and an unpaired rewire is not silent, it surfaces as
declared-versus-actual drift to any verifier. Emits
Note: emits: ExpectedCodehashSet.
function setExpectedCodehash(bytes32 key, bytes32 codehash) external override onlyRootOrOwner;
renounceOwnership
Removes the bootstrap owner of the whole deployment, leaving Root as the only governance of every dotNS contract.
Root only, otherwise @custom:reverts RenounceRequiresRoot: a Root call passes the gate
behind this proxy only on a runtime where Root can govern dotNS. Clears the owner,
then requires every contract under a known key (DotnsConstants.registryKeys) or a
registered key that answers owner() to answer zero, otherwise
Note:
reverts: OwnerStillSet. A contract that reads its owner from this registry
passes. A contract still running code with an owner of its own, such as a proxy not
yet upgraded or a superseded cost model registry left under its key, fails the
renounce. A contract with no owner() is skipped. Reads no msg.sender.
function renounceOwnership() public override onlyRoot;
_requireNoOwner
Reverts with OwnerStillSet when the contract under key answers a non-zero
owner().
Skips an unset key and a contract whose owner() reverts or answers malformed data.
function _requireNoOwner(bytes32 key) private view;
Parameters
| Name | Type | Description |
|---|---|---|
key | bytes32 | Registry key to check. |
_authorizeUpgrade
Function that should revert when msg.sender is not authorized to upgrade the contract.
Called by
{upgradeToAndCall}.
Normally, this function will use an xref:access.adoc[access control] modifier such as
{Ownable-onlyOwner}.
function _authorizeUpgrade(address) internal onlyOwner {}
function _authorizeUpgrade(address newImplementation) internal override onlyRootOrOwner;