DotnsProtocolRegistry

Git Source

Inherits: Initializable, UUPSUpgradeable, OwnableUpgradeable, 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

__gap

uint256[50] 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

NameTypeDescription
initialOwneraddressAddress that owns the contract once initialised.
tldLabelstringBare 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.

Owner-restricted, 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. Emits

Note: emits: AddressUpdated on each effective change.

function set(bytes32 key, address addr) external override onlyOwner;

remove

Clears the address stored for a given key.

Owner-restricted, 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. Emits @custom:emits AddressRemoved.

function remove(bytes32 key) external override onlyOwner;

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.

Owner-restricted, 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 onlyOwner;

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

NameTypeDescription
versionStringstringDeclared 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.

Owner-restricted, 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 onlyOwner;

_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 onlyOwner;