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.

ERC-181 defines a mechanism for reverse resolution of Ethereum addresses using the Ethereum Name Service (ENS).

This article translates, summarizes, and expands on the following specification.

More ERC explainers:

Overview

ENS allows human-readable names, such as alice.eth, to be associated with Ethereum addresses. ERC-181 defines conventions for looking up a name starting from an address.

Three important components of the naming system are:

  • Top-level domain (TLD): The final label of a domain name, such as eth or com.
  • Registrar: A contract responsible for allocating or managing names within its namespace.
  • Resolver: A contract that provides records associated with a name, including address records and reverse name records.

The objective is to make Ethereum addresses easier to recognize and display. An application can display a name such as alice.eth instead of an abbreviated hexadecimal address.

The reverse registrar allows an account to configure its associated reverse record or delegate control of that record. This is distinct from ownership of the forward ENS name.

Motivation

Forward resolution translates a human-readable name into an address. Reverse resolution performs the opposite lookup, obtaining a name associated with an address.

Several applications benefit from this functionality:

  • Account monitoring applications
    • Applications can display recognizable account names alongside or instead of hexadecimal addresses.
  • Associating metadata
    • Applications can discover descriptive records associated with an address regardless of how they originally obtained it.
  • Expressing a preferred name
    • Although another party can configure a forward name pointing to an address, reverse records allow an authorized account to express its own preferred name.

A reverse record is not sufficient to establish that the account controls the returned ENS name. Clients should forward-resolve that name and verify that it maps back to the original address before presenting it as a verified reverse name.

Specification

ERC-181 places reverse ENS records for Ethereum addresses under the special domain addr.reverse.

To derive the reverse name, encode the address as a lowercase hexadecimal string without the 0x prefix and append .addr.reverse.

For example, the address 0x112234455c3a32fd11230c42e7bccd4a84e02010 corresponds to:

112234455c3a32fd11230c42e7bccd4a84e02010.addr.reverse

The client computes the namehash of that name, discovers the corresponding resolver through the ENS registry, and queries its name record.

Contracts implementing this mechanism therefore need to derive the hexadecimal address representation consistently.

Registrar

The registrar responsible for addr.reverse provides operations for managing reverse records associated with Ethereum accounts.

claim(address owner)

When called by an account, this function assigns ownership of that account's reverse ENS node to the supplied owner address.

It returns the namehash of the reverse node.

This allows a contract to configure its reverse record and delegate its management to another account with relatively little initialization code.

claimWithResolver(address owner, address resolver)

Assigns the specified resolver to the calling account's reverse node and transfers ownership of that node to the supplied owner.

The historical implementation treats a zero resolver argument as an instruction to leave the resolver unchanged.

The function returns the namehash of the reverse node. It allows ownership and resolver configuration to be handled within one transaction.

setName(string name)

Configures the calling account's reverse record using the default reverse resolver and sets its name record to the supplied string.

This provides a convenient way to configure a reverse name in a single transaction.

These operations allow accounts and contracts to configure or delegate management of their reverse ENS records. They do not automatically register or update the corresponding forward name.

Resolver interface

The reverse resolver exposes the function name(bytes32 node).

The node is the namehash of the relevant ENS name, rather than the Ethereum address itself.

  • The function returns the name record associated with the supplied node.
  • When no name record exists, it returns an empty string.

A compatible resolver therefore allows an application to retrieve the preferred name associated with an Ethereum address.

The interface identifier is 0x691f3431, corresponding to the selector of name(bytes32). Other resolver capabilities can be exposed independently.

Reverse resolution retrieves a name record for an address-derived ENS node. A forward-resolution check is necessary to confirm that the returned name points back to the original address.

Registrar implementation

The original specification provides the following historical Solidity implementation of a reverse registrar and default reverse resolver.

javascript
pragma solidity ^0.4.10;

import "./AbstractENS.sol";

contract Resolver {
    function setName(bytes32 node, string name) public;
}

/**
 * @dev Provides a default implementation of a resolver for reverse records,
 * which permits only the owner to update it.
 */
contract DefaultReverseResolver is Resolver {
    AbstractENS public ens;
    mapping(bytes32=>string) public name;

    /**
     * @dev Constructor
     * @param ensAddr The address of the ENS registry.
     */
    function DefaultReverseResolver(AbstractENS ensAddr) {
        ens = ensAddr;
    }

    /**
     * @dev Only permits calls by the reverse registrar.
     * @param node The node permission is required for.
     */
    modifier owner_only(bytes32 node) {
        require(msg.sender == ens.owner(node));
        _;
    }

    /**
     * @dev Sets the name for a node.
     * @param node The node to update.
     * @param _name The name to set.
     */
    function setName(bytes32 node, string _name) public owner_only(node) {
        name[node] = _name;
    }
}

contract ReverseRegistrar {
    // namehash('addr.reverse')
    bytes32 constant ADDR_REVERSE_NODE = 0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;

    AbstractENS public ens;
    Resolver public defaultResolver;

    /**
     * @dev Constructor
     * @param ensAddr The address of the ENS registry.
     * @param resolverAddr The address of the default reverse resolver.
     */
    function ReverseRegistrar(AbstractENS ensAddr, Resolver resolverAddr) {
        ens = ensAddr;
        defaultResolver = resolverAddr;
    }

    /**
     * @dev Transfers ownership of the reverse ENS record associated with the
     *      calling account.
     * @param owner The address to set as the owner of the reverse record in ENS.
     * @return The ENS node hash of the reverse record.
     */
    function claim(address owner) returns (bytes32 node) {
        return claimWithResolver(owner, 0);
    }

    /**
     * @dev Transfers ownership of the reverse ENS record associated with the
     *      calling account.
     * @param owner The address to set as the owner of the reverse record in ENS.
     * @param resolver The address of the resolver to set; 0 to leave unchanged.
     * @return The ENS node hash of the reverse record.
     */
    function claimWithResolver(address owner, address resolver) returns (bytes32 node) {
        var label = sha3HexAddress(msg.sender);
        node = sha3(ADDR_REVERSE_NODE, label);
        var currentOwner = ens.owner(node);

        // Update the resolver if required
        if(resolver != 0 && resolver != ens.resolver(node)) {
            // Transfer the name to us first if it's not already
            if(currentOwner != address(this)) {
                ens.setSubnodeOwner(ADDR_REVERSE_NODE, label, this);
                currentOwner = address(this);
            }
            ens.setResolver(node, resolver);
        }

        // Update the owner if required
        if(currentOwner != owner) {
            ens.setSubnodeOwner(ADDR_REVERSE_NODE, label, owner);
        }

        return node;
    }

    /**
     * @dev Sets the `name()` record for the reverse ENS record associated with
     * the calling account. First updates the resolver to the default reverse
     * resolver if necessary.
     * @param name The name to set for this address.
     * @return The ENS node hash of the reverse record.
     */
    function setName(string name) returns (bytes32 node) {
        node = claimWithResolver(this, defaultResolver);
        defaultResolver.setName(node, name);
        return node;
    }

    /**
     * @dev Returns the node hash for a given account's reverse records.
     * @param addr The address to hash
     * @return The ENS node hash.
     */
    function node(address addr) constant returns (bytes32 ret) {
        return sha3(ADDR_REVERSE_NODE, sha3HexAddress(addr));
    }

    /**
     * @dev An optimised function to compute the sha3 of the lower-case
     *      hexadecimal representation of an Ethereum address.
     * @param addr The address to hash
     * @return The SHA3 hash of the lower-case hexadecimal encoding of the
     *         input address.
     */
    function sha3HexAddress(address addr) private returns (bytes32 ret) {
        addr; ret; // Stop warning us about unused variables
        assembly {
            let lookup := 0x3031323334353637383961626364656600000000000000000000000000000000
            let i := 40
        loop:
            i := sub(i, 1)
            mstore8(i, byte(and(addr, 0xf), lookup))
            addr := div(addr, 0x10)
            i := sub(i, 1)
            mstore8(i, byte(and(addr, 0xf), lookup))
            addr := div(addr, 0x10)
            jumpi(loop, i)
            ret := sha3(0, 40)
        }
    }
}

The default resolver stores a string for each node and checks registry ownership before permitting updates.

The registrar derives the reverse node from the calling account's lowercase hexadecimal address, updates the resolver where necessary, and assigns ownership of the node.

The assembly routine computes the Keccak-256 hash of the 40-character hexadecimal representation without its 0x prefix.

The code uses historical Solidity 0.4 syntax, including sha3 and older assembly conventions. It is retained unchanged for reference and has not been independently compiled or audited. Production integrations should use the appropriate deployed ENS contracts and current interfaces for the target network.

Citation

Nick Johnson arachnid@notdot.net, "ERC-181: ENS support for reverse resolution of Ethereum addresses," Ethereum Improvement Proposals, no. 181, December 2016. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-181.

Conclusion

ERC-181 establishes a reverse-record namespace and resolver interface for mapping Ethereum addresses to human-readable ENS names. Reverse resolution improves address presentation, while forward verification helps applications avoid presenting an unrelated name as an authenticated association.

Questions are welcome via Twitter @cardene777.

Other publications:

https://chaldene.net/