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.

This article examines ENSIP1, which defines ENS name resolution and registration, including how authorized registrants can update registered information.

This article translates, summarizes, and expands on the proposal below.

I have also covered various EIPs, BIPs, SLIPs, CAIPs, and ENSIPs.

Overview

Overview

Ethereum Name Service (ENS) defines a mechanism for mapping short, human-readable names to resources such as contracts and data. For example, entering a name such as vitalik.wallet or www.mysite.swarm can resolve to its associated wallet address or website. This makes the system easier to use because users do not need to work directly with long, complex addresses. The mapping between names and resources can also be updated, allowing users to keep the same name when they change wallets or a website moves to a different server. A single name can have multiple types of records, enabling the same domain to identify different services, such as a website, email, or decentralized application (DApp).

Motivation

The name resolution mechanisms that previously existed on Ethereum provided basic functionality but had several limitations.

  • Only a single global namespace and centralized resolver were available.
  • Subdomains and delegation had little support.
  • Record types were limited, preventing multiple kinds of information from being associated with a single name.
  • Responsibilities such as name resolution, registration, and ownership management were combined.

Removing these limitations enables several use cases. For instance, users can create subdomains such as live.mysite.eth and forum.mysite.eth, associate multiple services with a name (such as a Swarm-hosted DApp and a mail server), and support DNS records so that conventional website and email addresses can be resolved through the blockchain. These capabilities also enable a DNS gateway bridging ENS names and existing internet infrastructure, allowing conventional clients to access blockchain services.

Specification

Ethereum Name Service (ENS) consists of three main components.

The first is the ENS registry, a single contract that associates registered names with their respective resolvers. Name owners can also configure resolver addresses and create subdomains. A subdomain may have a different owner from its parent domain.

The second component is the resolver, which returns the actual resource associated with a name. For example, it can return a contract address, content hash, or IP address. Resolvers are designed to handle multiple record types and can be extended through ENS Improvement Proposals (ENSIPs).

The third component is the registrar, which allocates domain names to users. A registrar owns the corresponding node in the ENS registry and is the party authorized to update that node. Registrars may be implemented as smart contracts or externally owned accounts, although registrars for the root and top-level domains are expected to be contracts.

Name Resolution

ENS resolution is a two-step process. First, hash the name to be resolved using the namehash algorithm, then call the ENS registry with the result. The registry returns the address of the corresponding resolver. The client then queries that resolver for the desired resource, such as an address.

For example, retrieving the token contract address associated with beercoin.eth works as follows.

javascript
var node = namehash("beercoin.eth");
var resolver = ens.resolver(node);
var address = resolver.addr(node);

Because namehash avoids string processing during lookup, it can be precomputed and embedded in a contract, enabling fast, constant-time lookups for any name.

Name Syntax

ENS names consist of components called labels, separated by dots (.). Each label is normalized according to the international UTS46 standard. This makes names case-insensitive, so names with the same spelling are treated identically.

There is no limit on the length of a label or name, but for compatibility with conventional DNS, labels of up to 64 characters and complete names of up to 255 characters are recommended. Labels beginning or ending with a hyphen, or beginning with a digit, should also be avoided.

The Namehash Algorithm

Before ENS uses a name, it hashes it with the namehash algorithm. The algorithm splits a hierarchical name into labels and recursively computes hashes. It produces a unique, fixed-length hash (a node) for a given input.

python
def namehash(name):
  if name == '':
    return '\0' * 32
  else:
    label, _, remainder = name.partition('.')
    return sha3(namehash(remainder) + sha3(label))

For example, processing mysite.swarm involves the following computation.

text
node = '\0' * 32
node = sha3(node + sha3('swarm'))
node = sha3(node + sha3('mysite'))

This produces reproducible results for any name.

Namehash Test Vectors

The specification provides the following test vectors for checking implementation conformance.

text
namehash('') = 0x0000000000000000000000000000000000000000000000000000000000000000
namehash('eth') = 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae
namehash('foo.eth') = 0xde9b09fd7c5f901e23a3f19fecc54828e9c848539801e86591bd9801b019f84f

Using namehash enables ENS to handle hierarchical names efficiently and consistently on-chain.

ENS Registry

The ENS Registry is the central contract managing fundamental information about every ENS domain. It stores the owner, resolver, and TTL of each name (node), forming the basis of domain management.

Its primary functions are as follows.

javascript
function owner(bytes32 node) constant returns (address);

Returns the owner of the specified node (the registrar's address).

javascript
function resolver(bytes32 node) constant returns (address);

Returns the resolver address associated with the node. The resolver resolves the actual resource.

javascript
function ttl(bytes32 node) constant returns (uint64);

Returns the TTL (Time To Live). The TTL specifies the maximum duration for which the node's information may be cached.

javascript
function setOwner(bytes32 node, address owner);

Transfers ownership of the node to another address. Only the current owner can perform this operation, which emits a Transfer event upon success.

javascript
function setSubnodeOwner(bytes32 node, bytes32 label, address owner);

Creates a subdomain and assigns its owner. If it already exists, the operation updates its owner. It emits a NewOwner event upon success.

javascript
function setResolver(bytes32 node, address resolver);

Configures the resolver for the node. It emits a NewResolver event upon success.

javascript
function setTTL(bytes32 node, uint64 ttl);

Sets the TTL for the node. This TTL applies to the owner and resolver information as well as all data returned by the resolver.

Resolver

A resolver returns actual resources associated with a domain name, such as addresses, text information, and content hashes. A resolver can implement multiple capabilities as needed, but it must implement the functions required by the interfaces it supports. Every resolver must also have a fallback function that rejects calls to nonexistent functions.

The supportsInterface Function

Every resolver must implement the following function.

javascript
function supportsInterface(bytes4 interfaceID) constant returns (bool)

It returns whether the resolver supports the given interface ID. An interface ID is the XOR of the function signature hashes that constitute the interface. For an interface consisting of one function, the function signature hash itself is the interface ID.

It must return true for 0x01ffc9a7. This is the interface ID of supportsInterface itself.

Standardized interfaces include the following.

Interface name Interface hash Defining specification
addr 0x3b3b57de Contract address resolution
name 0x691f3431 ENSIP3
ABI 0x2203ab56 ENSIP4
text 0x59d1d43c ENSIP5
contenthash 0xbc1c58d1 ENSIP7
interfaceImplementer 0xb8f2bbb4 ENSIP8
addr(bytes32,uint256) 0xf1cb7e06 ENSIP9

Additional interfaces may be introduced through ENSIPs.

Contract Address Interface

The most fundamental interface is address resolution. Resolvers supporting it must implement the following function.

javascript
function addr(bytes32 node) constant returns (address);

If the target node has no addr record, the resolver must return the zero address. Clients must check this result and avoid sending funds or interacting with contracts when the zero address is returned, as assets could otherwise be lost.

When an address changes, the following event is emitted.

javascript
event AddrChanged(bytes32 indexed node, address a);

This allows external systems to detect address updates.

Registry Reference Implementation

js
contract ENS {
    struct Record {
        address owner;
        address resolver;
        uint64 ttl;
    }
 
    mapping(bytes32=>Record) records;
 
    event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
    event Transfer(bytes32 indexed node, address owner);
    event NewResolver(bytes32 indexed node, address resolver);
 
    modifier only_owner(bytes32 node) {
        if(records[node].owner != msg.sender) throw;
        _
    }
 
    function ENS(address owner) {
        records[0].owner = owner;
    }
 
    function owner(bytes32 node) constant returns (address) {
        return records[node].owner;
    }
 
    function resolver(bytes32 node) constant returns (address) {
        return records[node].resolver;
    }
 
    function ttl(bytes32 node) constant returns (uint64) {
        return records[node].ttl;
    }
 
    function setOwner(bytes32 node, address owner) only_owner(node) {
        Transfer(node, owner);
        records[node].owner = owner;
    }
 
    function setSubnodeOwner(bytes32 node, bytes32 label, address owner) only_owner(node) {
        var subnode = sha3(node, label);
        NewOwner(node, label, owner);
        records[subnode].owner = owner;
    }
 
    function setResolver(bytes32 node, address resolver) only_owner(node) {
        NewResolver(node, resolver);
        records[node].resolver = resolver;
    }
 
    function setTTL(bytes32 node, uint64 ttl) only_owner(node) {
        NewTTL(node, ttl);
        records[node].ttl = ttl;
    }
}

Record

javascript
struct Record {
    address owner;
    address resolver;
    uint64 ttl;
}

A struct that stores information associated with each ENS node. It holds the owner, resolver, and TTL (validity period) of the node. Each ENS domain manages its required metadata through this struct.

Parameters

  • owner
    • Owner address of the node.
  • resolver
    • Address of the resolver associated with the node.
  • ttl
    • Cache validity period of the node's information, in seconds.

records

javascript
mapping(bytes32=>Record) records;

A mapping that associates each node hash with its corresponding Record struct. Using a node as the key retrieves the Record containing its owner, resolver, and TTL. It serves as the core database of ENS.

Parameters

  • bytes32
    • Node hash.
  • Record
    • Information associated with the node.

NewOwner

javascript
event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);

An event emitted when a new owner is assigned to a subnode. It is emitted when a subdomain is created or updated, identifying the node and label to which a new owner has been assigned.

Parameters

  • node
    • Parent node hash.
  • label
    • Hash of the label identifying the subnode.
  • owner
    • Address of the new owner.

Transfer

javascript
event Transfer(bytes32 indexed node, address owner);

An event emitted when ownership of a node is transferred to another address. It notifies observers of a change in the node's owner.

Parameters

  • node
    • Hash of the node whose ownership was transferred.
  • owner
    • Address of the new owner.

NewResolver

javascript
event NewResolver(bytes32 indexed node, address resolver);

An event emitted when a new resolver is assigned to a node. It notifies observers that the resolver referenced by the node has changed.

Parameters

  • node
    • Hash of the node whose resolver was changed.
  • resolver
    • Address of the new resolver.

only_owner

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

A modifier restricting function execution to the owner of the specified node. If the caller is not the node's owner, execution is aborted. Only addresses holding ownership of the node can change its settings.

Parameters

  • node
    • Hash of the node subject to access control.

Functions

ENS

javascript
function ENS(address owner) {
    records[0].owner = owner;
}

The ENS contract's initialization function. It is called at deployment to assign ownership of the root node (node=0) to the specified address.

Arguments

  • owner
    • Owner address of the root node.

owner

javascript
function owner(bytes32 node) constant returns (address) {
    return records[node].owner;
}

Retrieves the owner of a node. It returns the owner address of the specified node.

Arguments

  • node
    • Hash of the node whose owner is requested.

Return value

  • address
    • Owner address of the node.

resolver

javascript
function resolver(bytes32 node) constant returns (address) {
    return records[node].resolver;
}

Retrieves the resolver for a node. It returns the resolver address associated with the specified node.

Arguments

  • node
    • Hash of the node whose resolver is requested.

Return value

  • address
    • Resolver address configured for the node.

ttl

javascript
function ttl(bytes32 node) constant returns (uint64) {
    return records[node].ttl;
}

Retrieves a node's TTL. It returns the TTL (cache validity period) of the specified node.

Arguments

  • node
    • Hash of the node whose TTL is requested.

Return value

  • uint64
    • TTL of the node.

setOwner

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

Changes the owner of a node. It transfers ownership of the target node to a new address. A Transfer event is emitted upon success.

Arguments

  • node
    • Hash of the target node.
  • owner
    • Address of the new owner.

setSubnodeOwner

javascript
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) only_owner(node) {
    var subnode = sha3(node, label);
    NewOwner(node, label, owner);
    records[subnode].owner = owner;
}

Sets or updates the owner of a subnode. It derives the subnode from the specified parent node and label, then sets its owner. If the subnode already exists, its owner is updated. A NewOwner event is emitted upon success.

Arguments

  • node
    • Parent node hash.
  • label
    • Hash of the label identifying the subnode.
  • owner
    • Address of the new owner.

setResolver

javascript
function setResolver(bytes32 node, address resolver) only_owner(node) {
    NewResolver(node, resolver);
    records[node].resolver = resolver;
}

Sets the resolver associated with a node. It assigns a new resolver address to the specified node. A NewResolver event is emitted upon success.

Arguments

  • node
    • Hash of the target node.
  • resolver
    • Address of the new resolver.

setTTL

javascript
function setTTL(bytes32 node, uint64 ttl) only_owner(node) {
    NewTTL(node, ttl);
    records[node].ttl = ttl;
}

Sets a node's TTL. It assigns a new TTL to the specified node. This changes the maximum duration for which its information may be cached.

Arguments

  • node
    • Hash of the target node.
  • ttl
    • New TTL.

Example Resolver Implementations

Built-in Resolver

This is the simplest resolver configuration, in which the contract itself acts as the resolver. It returns its own address for any specified node, removing the need for a separate resolver contract. However, the requirement to execute throw when an undefined function is called may limit its use for other purposes.

js
contract DoSomethingUseful {
    // Other code
 
    function addr(bytes32 node) constant returns (address) {
        return this;
    }
 
    function supportsInterface(bytes4 interfaceID) constant returns (bool) {
        return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
    }
 
    function() {
        throw;
    }
}

addr

javascript
function addr(bytes32 node) constant returns (address) {
    return this;
}

Returns the contract's own address. It returns that address regardless of the supplied node. The contract can therefore be registered directly as a resolver in the ENS registry.

Arguments

  • node
    • Node to resolve.

Return value

  • address
    • Address of this contract.

supportsInterface

javascript
function supportsInterface(bytes4 interfaceID) constant returns (bool) {
    return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
}

Reports whether an interface is supported. It indicates that the contract implements the addr interface (0x3b3b57de) and supportsInterface itself (0x01ffc9a7).

Arguments

  • interfaceID
    • Interface ID to check.

Return value

  • bool
    • true if implemented.

Fallback Function

javascript
function() {
    throw;
}

A fallback function that rejects unknown function calls. Any call to a function that does not exist in the contract fails.

Standalone Resolver

This resolver can store address records, and only its owner can update them. After deploying it, associate the ENS registry with this resolver and call setAddr to configure an address for a name.

js
contract Resolver {
    event AddrChanged(bytes32 indexed node, address a);
 
    address owner;
    mapping(bytes32=>address) addresses;
 
    modifier only_owner() {
        if(msg.sender != owner) throw;
        _
    }
 
    function Resolver() {
        owner = msg.sender;
    }
 
    function addr(bytes32 node) constant returns(address) {
        return addresses[node];    
    }
 
    function setAddr(bytes32 node, address addr) only_owner {
        addresses[node] = addr;
        AddrChanged(node, addr);
    }
 
    function supportsInterface(bytes4 interfaceID) constant returns (bool) {
        return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
    }
 
    function() {
        throw;
    }
}

AddrChanged

javascript
event AddrChanged(bytes32 indexed node, address a);

An event emitted when an address associated with a node changes. It notifies users and clients that the address of the target node has been updated.

Parameters

  • node
    • Hash of the updated node.
  • a
    • New address.

owner

javascript
address owner;

A variable recording the resolver's owner. It stores the account authorized to update the resolver's address records.

Parameters

  • owner
    • Owner address.

addresses

javascript
mapping(bytes32=>address) addresses;

A mapping storing an address for each node. It stores the address associated with each ENS node and returns it on request.

Parameters

  • bytes32
    • Node hash.
  • address
    • Configured address.

only_owner

javascript
modifier only_owner() {
    if(msg.sender != owner) throw;
    _
}

A modifier restricting execution to the owner. If the sender is not owner, execution is aborted.

Resolver

javascript
function Resolver() {
    owner = msg.sender;
}

The Standalone Resolver's initialization function. It is called during deployment and sets the contract creator as the owner.

addr

javascript
function addr(bytes32 node) constant returns(address) {
    return addresses[node];    
}

Returns the address associated with a node. It returns the address stored in the mapping.

Arguments

  • node
    • Target node.

Return value

  • address
    • Registered address.

setAddr

javascript
function setAddr(bytes32 node, address addr) only_owner {
    addresses[node] = addr;
    AddrChanged(node, addr);
}

Sets the address of a node. Only the owner can execute it; after updating the address, it emits an AddrChanged event.

Arguments

  • node
    • Target node.
  • addr
    • New address.

supportsInterface

javascript
function supportsInterface(bytes4 interfaceID) constant returns (bool) {
    return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
}

Reports whether an interface is supported. It indicates support for the addr interface and supportsInterface.

Arguments

  • interfaceID
    • Interface ID to check.

Return value

  • bool
    • true if implemented.

Fallback Function

javascript
function() {
    throw;
}

A fallback function that rejects calls to undefined functions. All calls to nonexistent functions fail.

Public Resolver

This resolver is broadly similar to the Standalone Resolver, but determines update permissions using the ENS registry. By reusing ENS registration information to determine ownership, it supports more decentralized usage.

js
contract PublicResolver {
    event AddrChanged(bytes32 indexed node, address a);
    event ContentChanged(bytes32 indexed node, bytes32 hash);
 
    ENS ens;
    mapping(bytes32=>address) addresses;
 
    modifier only_owner(bytes32 node) {
        if(ens.owner(node) != msg.sender) throw;
        _
    }
 
    function PublicResolver(address ensAddr) {
        ens = ENS(ensAddr);
    }
 
    function addr(bytes32 node) constant returns (address ret) {
        ret = addresses[node];
    }
 
    function setAddr(bytes32 node, address addr) only_owner(node) {
        addresses[node] = addr;
        AddrChanged(node, addr);
    }
 
    function supportsInterface(bytes4 interfaceID) constant returns (bool) {
        return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
    }
 
    function() {
        throw;
    }
}

AddrChanged

javascript
event AddrChanged(bytes32 indexed node, address a);

An event emitted when the address of a node changes. It notifies observers of an address update.

Parameters

  • node
    • Updated node.
  • a
    • New address.

ContentChanged

javascript
event ContentChanged(bytes32 indexed node, bytes32 hash);

An event emitted when content associated with a node changes. It notifies observers that the content hash has been updated.

Parameters

  • node
    • Node being updated.
  • hash
    • New content hash.

ens

javascript
ENS ens;

A variable holding a reference to the ENS registry. It is used to check the owner of a node.

Parameters

  • ens
    • ENS contract instance.

addresses

javascript
mapping(bytes32=>address) addresses;

A mapping associating nodes with addresses. It manages the address for each ENS node.

Parameters

  • bytes32
    • Node hash.
  • address
    • Configured address.

only_owner

javascript
modifier only_owner(bytes32 node) {
    if(ens.owner(node) != msg.sender) throw;
    _
}

A modifier restricting execution to the owner recorded in the ENS registry. Instead of maintaining its own owner, the resolver controls access according to ownership registered in ENS.

Parameters

  • node
    • Node whose permissions are checked.

PublicResolver

javascript
function PublicResolver(address ensAddr) {
    ens = ENS(ensAddr);
}

The Public Resolver's initialization function. It receives the address of the ENS registry and stores the reference.

Arguments

  • ensAddr
    • ENS contract address.

addr

javascript
function addr(bytes32 node) constant returns (address ret) {
    ret = addresses[node];
}

Returns the address of a node. It returns the address associated with the ENS node.

Arguments

  • node
    • Target node.

Return value

  • address
    • Registered address.

setAddr

javascript
function setAddr(bytes32 node, address addr) only_owner(node) {
    addresses[node] = addr;
    AddrChanged(node, addr);
}

Sets the address of a node. Only the node's owner in the ENS registry can execute it, and an event is emitted after the update.

Arguments

  • node
    • Target node.
  • addr
    • New address.

supportsInterface

javascript
function supportsInterface(bytes4 interfaceID) constant returns (bool) {
    return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
}

Reports whether an interface is supported. It indicates support for addr and supportsInterface.

Arguments

  • interfaceID
    • Interface ID to check.

Return value

  • bool
    • true if implemented.

Fallback Function

javascript
function() {
    throw;
}

A fallback function that rejects calls to undefined functions. All calls to nonexistent functions fail.

Example Registrar Implementation

js
contract FIFSRegistrar {
    ENS ens;
    bytes32 rootNode;
 
    function FIFSRegistrar(address ensAddr, bytes32 node) {
        ens = ENS(ensAddr);
        rootNode = node;
    }
 
    function register(bytes32 subnode, address owner) {
        var node = sha3(rootNode, subnode);
        var currentOwner = ens.owner(node);
        if(currentOwner != 0 && currentOwner != msg.sender)
            throw;
 
        ens.setSubnodeOwner(rootNode, subnode, owner);
    }
}

ens

javascript
ENS ens;

A variable holding a reference to the ENS registry. It serves as a handle for invoking registry functions such as retrieving node owners and setting subnode owners. The registrar uses this reference to invoke setSubnodeOwner at the final stage of registration.

Parameters

  • ens
    • Contract reference to the ENS registry.

rootNode

javascript
bytes32 rootNode;

A variable holding the root node (parent node) managed by this registrar. It contains the node hash of the domain being managed, such as example.eth. During registration, the registrar hashes rootNode and the sublabel to derive the target node.

Parameters

  • rootNode
    • Hash of the parent node being managed.

Functions

FIFSRegistrar

javascript
function FIFSRegistrar(address ensAddr, bytes32 node) {
    ens = ENS(ensAddr);
    rootNode = node;
}

The FIFSRegistrar initialization function. When the registrar is created, it initializes the ENS registry address and the rootNode it manages. This establishes the registry and parent node to be referenced in subsequent registrations.

Arguments

  • ensAddr
    • ENS registry address.
  • node
    • Hash of the root node being managed.

register

javascript
function register(bytes32 subnode, address owner) {
    var node = sha3(rootNode, subnode);
    var currentOwner = ens.owner(node);
    if(currentOwner != 0 && currentOwner != msg.sender)
        throw;

    ens.setSubnodeOwner(rootNode, subnode, owner);
}

Registers a subnode on a first-come, first-served basis. It registers a new subnode under rootNode. First, it calculates the target node from rootNode and subnode, then retrieves the current owner from the ENS registry. If no owner has been set (0), registration is available free of charge. If an owner already exists, the record can be overwritten only if the current caller is that owner. When these conditions are met, it calls setSubnodeOwner on the ENS registry to set the owner to owner.

Arguments

  • subnode
    • Label hash of the subnode to register.
  • owner
    • Owner address after registration.

Conclusion

This article covered ENSIP1, the proposal defining ENS name registration and allowing authorized registrants to update registered information.

If you have any questions, feel free to contact me via direct message on Twitter.

Twitter @cardene777

I also publish on other platforms.

https://chaldene.net/