ERC-7406 Multi-namespace on-chain registry (Multi-Namespace Onchain Registry)
Draft · Names & metadata · created 2023-07-23
A general-purpose on-chain registry standard that maintains multiple namespaces within a single contract, with each namespace managing its own key-value records independently.
Why it is needed
Blockchain-based registries are a core building block that decentralized apps use to store and retrieve key information. However, existing approaches such as the ENS registry are tailored to a specific use case and can lack the flexibility to handle more complex situations. For example, if you want the same key to point to different values depending on usage, or want to handle different kinds of data such as session management or resolving short addresses into full addresses within a single place, you end up with the burden of creating a separate registry for each use case. It is also difficult for a single structure to track or roll back how data has changed over different versions. This proposal defines a generalized mapping structure that supports multiple namespaces, so that a single registry can efficiently handle a wide range of use cases.
What to implement
function owner(bytes32 namespace, bytes32 key) external view returns (address);: Returns the owner of the given key under the specified namespace.function resolver(bytes32 namespace, bytes32 key) external view returns (address);: Returns the address of the resolver (the contract that actually reports the value) for the given key under the specified namespace.function setOwner(bytes32 namespace, bytes32 key, address newOwner) external;: Transfers ownership of a key within that namespace to another address. Only the current owner may call this.function createNamespace(bytes32 namespace) external;: Creates a new namespace in the registry, such as a new version or a new protocol type.function setResolver(bytes32 namespace, bytes32 key, address newResolver) external;: Sets the resolver address for a key within that namespace. Only the owner of that key may call this.
In depth
Two-level (namespace, key) mapping structure
Unlike existing ENS-style registries, which keep a single record per key, this standard requires every lookup and setter function to take both a bytes32 namespace and a bytes32 key. The same key can have a different owner and resolver depending on the namespace. The source document gives examples of this structure: if the registry is a session store, the namespace could represent the session type; if it is a store mapping short URLs to full URLs, the namespace could represent that data type. It also explains that using namespaces to distinguish version numbers allows entry versioning, change history tracking, data rollback, and tombstoning, all within a single contract.
Lookup functions owner and resolver
owner(bytes32 namespace, bytes32 key) returns the owner address of that key under the given namespace, and resolver(bytes32 namespace, bytes32 key) returns the resolver address within the same scope. Both are external view functions that only read state without modifying it. In the reference implementation, resolver is set up to revert if the namespace does not exist (if namespaces[namespace] is 0).
Ownership transfer setOwner
setOwner(bytes32 namespace, bytes32 key, address newOwner) transfers ownership of a key under a specific namespace to a new owner. This function may only be called by the current owner of that key within that namespace. The same key can have different owners depending on the namespace. On success, a Transfer(bytes32 namespace, bytes32 key, address newOwner) event is logged.
Namespace creation createNamespace
createNamespace(bytes32 namespace) creates a new namespace in the current registry, such as a new version or a new protocol type. On success, a NewNamespace(bytes32 namespace) event is logged. In the reference implementation, the approver address is stored as records[0][0].owner at deployment, and the only_approver modifier restricts namespace creation to that approver alone. If the namespace already exists, the call simply returns.
Resolver setting setResolver and ERC-137 compatibility
setResolver(bytes32 namespace, bytes32 key, address newResolver) sets the resolver address for a key under the given namespace, and per the specification only the owner of that key may call it. The same key can have a different resolver depending on the namespace, and on success a NewResolver(bytes32 namespace, bytes32 key, address newResolver) event is logged. The resolver contract itself can use the specification defined in ERC-137 (ENS) as is, so the registry acts as a pointer while the resolver handles actual value resolution, preserving an ENS-style structure.
Compatibility with existing behavior
Since this proposal only adds new functionality without changing existing behavior, the source document states there are no backward compatibility issues. The design rationale is that supporting multiple namespaces allows a single registry to handle diverse use cases such as identity management, session management, record tracking, and decentralized content publishing.
A proposal still at the Draft stage
This document is a Draft status Standards Track ERC written on July 23, 2023. Since it is not yet finalized, the specification may change or progress may stall, so the latest state should be checked before implementing.
Things to watch out for
- Security review needed due to namespaces and access control: The source document states that because this registry manages multiple namespaces and access control, it raises security considerations, and that sufficient testing, auditing, and peer review will be conducted to find and reduce attack vectors and vulnerabilities.