Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

Background

ERC-7406 proposes a multi-namespace registry that stores key-value mappings onchain. This article explains how the registry organizes different kinds of data.

The explanation below translates, summarizes, and expands on the original proposal.

I also cover other EIPs here.

Overview

This Ethereum Improvement Proposal introduces a mapping structure that supports multiple namespaces. It lets a registry store collections of key-value pairs onchain.

Think of a key-value mapping as a dictionary or phone book. Each key, or identifier, points to a corresponding value, or piece of information. Onchain mappings can represent more complex structures and relationships.

Example

Suppose you run an online bookstore. In the catalog, a book's ISBN (International Standard Book Number) is the key, and details such as its author, title, and price form the value.

  • Key
    • 978-4-123456-78-9 (the book's ISBN)
  • Value
    • { author: "Taro Yamada", title: "Introduction to Blockchain", price: "JPY 2,000" }

Looking up the ISBN retrieves all of the book's details.

Blockchain applications

A multi-namespace registry extends this idea. Different namespaces can store different information about the same digital asset, such as ownership, purchase history, and license terms.

  • Namespace 1 (ownership information)
    • Key
      • Asset ID
    • Value
      • Owner's wallet address
  • Namespace 2 (purchase history)
    • Key
      • Asset ID
    • Value
      • [purchase date: "2023-01-01", buyer: "wallet address A", price: "JPY 500"]
  • Namespace 3 (license information)
    • Key
      • Asset ID
    • Value
      • { license type: "commercial", expiration date: "2024-12-31" }

The same key, here the asset ID, can have different types of values. Each namespace organizes one kind of information, making records easier to manage in complex applications.

The registry can serve as a source of information whose changes can be traced. Mapping records paired with onchain assets can act as pointers and encapsulate different details, making the same structure useful across applications.

The examples below explain how mapping records, or onchain key-value pairs, can be associated with digital assets represented by tokens or smart contracts.

Acting as pointers

A mapping record can point to a specific onchain asset. For example, a token might represent ownership of a digital artwork. A record associated with that token can store details such as the artist, creation date, and purchase history. Looking up the record gives readers a place to find information about the asset.

Encapsulating different details

A mapping record gives related information a place in one organized structure. This makes different fields easier to access and manage together.

Supporting different applications

The records can apply to different kinds of onchain assets and hold different kinds of data. Applications can extend the information available about an asset and manage details appropriate to their use case.

In each case, the mapping records hold additional information about an onchain asset. Developers can organize those records according to how the application uses or presents the asset.

The proposed structure is intended to accommodate more use cases than registries such as the Ethereum Name Service (ENS). Its flexible mappings offer an alternative for applications that need to manage several categories of records.

With namespaces, developers can store and look up records in the categories their applications need instead of fitting all information into one set of keys.

Motivation

Blockchain registries let decentralized applications store and retrieve important information. Existing systems such as the ENS registry serve particular purposes but may lack the flexibility needed for more complex uses. A general mapping with multiple namespaces would let developers handle several uses in one registry.

The proposed multi-namespace registry offers several benefits.

Flexibility

Developers can define and manage multiple namespaces, each with its own set of keys. The same key can point to different values depending on the namespace. For example, a registry may use namespaces for different session types or store mappings from short URLs to full URLs.

Traceable history

Namespaces can serve as version numbers for entries. That makes it possible to track changes, restore older data, and mark entries that are no longer used. Developers can manage data and its governance within one contract.

Broader compatibility

The structure is designed to accommodate applications beyond the scope of registries such as ENS. Different decentralized applications can use the same registry model.

The registry can organize records by category, preserve how information changes over time, and give different applications a shared way to work with it.

Specification

owner

javascript
function owner(bytes32 namespace, bytes32 key) external view returns (address);

Overview

Returns the owner for a namespace and key.

Details

Returns the current owner's address for the specified key in the specified namespace. The same key can have different owners in different namespaces.

Arguments

  • namespace
    • Namespace in which to look up the key.
  • key
    • Key whose owner to look up.

Return value

  • address
    • Owner's address for the namespace and key.

resolver

javascript
function resolver(bytes32 namespace, bytes32 key) external view returns (address);

Overview

Returns the resolver address for a namespace and key.

Details

Returns the resolver associated with the specified key in the specified namespace. Different namespaces can associate the same key with different resolvers.

Arguments

  • namespace
    • Namespace in which to look up the key.
  • key
    • Key whose resolver address to look up.

Return value

  • address
    • Resolver address for the namespace and key.

setOwner

javascript
function setOwner(bytes32 namespace, bytes32 key, address newOwner) external;

Overview

Changes the owner for a namespace and key to a new address.

Details

Only the current owner can change the owner of the entry. The same key can have different owners in other namespaces. On success, the contract emits a Transfer event.

Arguments

  • namespace
    • Namespace containing the key.
  • key
    • Key whose owner to change.
  • newOwner
    • New owner's address.

createNamespace

javascript
function createNamespace(bytes32 namespace) external;

Overview

Creates a namespace.

Details

Creates a new namespace in the registry, for example to support a new version or a new protocol type. On success, the contract emits a NewNamespace event.

Arguments

  • namespace
    • Namespace to create.

setResolver

javascript
function setResolver(bytes32 namespace, bytes32 key, address newResolver) external;

Overview

Sets a new resolver address for a namespace and key.

Details

Only the key's current owner can change the resolver for the entry. Other namespaces can associate the same key with different resolvers. On success, the contract emits a NewResolver event.

Arguments

  • namespace
    • Namespace containing the key.
  • key
    • Key whose resolver to set.
  • newResolver
    • New resolver's address.

Resolver specification

A multi-namespace resolver contract can use the same specification as the resolver in ERC-137.

For more on ERC-137, see the following article.

[ERC-137] How ENS associates names with addresses

Additional notes

A registry with multiple namespaces can support identity verification, session management, record tracking, and decentralized publishing. Developers can use these capabilities to organize data in more complex decentralized applications.

Identity verification

Applications can store and manage information that identifies users, for example data used when users sign in.

Session management

Applications can maintain session information, such as whether a user is signed in, and track it while the user interacts with the service.

Record tracking

Applications can record and trace the history of specific transactions or events. This improves transparency and helps when records need to be audited.

Decentralized publishing

Creators can publish and manage their work without relying on a centralized platform.

Different namespaces can organize the records for each of these use cases. Developers can use this flexibility to design more complex applications around their users' needs.

Compatibility

The proposal adds functionality without modifying existing behavior and identifies no compatibility issues.

Implementation

Registry implementation

The illustrative code below is reproduced as shown in the original article. It contains inconsistencies with the interface above and is not a ready-to-compile implementation.

ts
pragma solidity ^0.8.12;

import "./IERC7406Interface.sol";

contract ERC7406 {
    struct Record {
        address owner;
        address resolver;
    }


    // A map is used to record namespace existence
    mapping(byte32=>uint) namespaces;
    mapping(bytes32=>mapping(bytes32=>Record)) records;

    event NewOwner(bytes32 indexed namespace, bytes32 indexed key, address owner);
    event Transfer(bytes32 indexed namespace, bytes32 indexed key, address owner);
    event NewResolver(bytes32 indexed namespace, bytes32 indexed key, address resolver);
    event NewNamespace(bytes32 namespace)

    modifier only_owner(bytes32 namespace, bytes32 key) {
        if(records[namespace][key].owner != msg.sender) throw;
        _
    }

    modifier only_approver() {
        if(records[0][0].owner != msg.sender) throw;
        _
    }

    function ERC7406(address approver) {
        records[0][0].owner = approver;
    }

    function owner(bytes32 namespace, bytes32 key) constant returns (address) {
        return records[namespace][key].owner;
    }
  
    function createNamespace(bytes32 namespace) only_approver() {
       if (status == 0) throw;
       NewNamespace(namespace);
       if (namespaces[namespace] != 0) {
           return;
       }
       namespaces[namespace] = 1;
    }

    function resolver(bytes32 namespace, bytes32 key) constant returns (address) {
        if (namespaces[namespace] == 0) throw;
        return records[namespace][key].resolver;
    }

    function setOwner(bytes32 namespace, bytes32 key, address owner) only_owner(namespace, key) {
        Transfer(key, namespace, owner);
        records[namespace][key].owner = owner;
    }

    function setResolver(bytes32 namespace, bytes32 key, address resolver) only_approver() {
        if (namespaces[namespace] == 0) {
            this.createNamespace(namespace, 1);
        }
        NewResolver(key, namespace, resolver);
        records[namespace][key].resolver = resolver;
    }
}

Security Considerations

Managing multiple namespaces and permissions in one registry creates potential risks, including unauthorized access or data exposure.

Thorough testing, audits, and peer review can help identify and fix weaknesses before deployment. Developers with security expertise can strengthen the registry by participating in that review.

Because the registry handles several types of data and access control together, each use case should account for security risks. Testing, audits, and community review can help mitigate them.

Citation

Mengshi Zhang (@MengshiZhang), Zihao Chen (@zihaoccc), "ERC-7406: Multi-Namespace Onchain Registry [DRAFT]," Ethereum Improvement Proposals, no. 7406, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7406.

Conclusion

ERC-7406 proposes storing key-value records in multiple namespaces. Using the namespace and key together lets a single registry manage separate kinds of data about an asset.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777

You can find my other writing here.

https://chaldene.net/