EIPs Explained

ERC-4834 · Final · ERC · 2022-02-22

ERC-4834: Hierarchical Domains

A minimal, DNS-like naming standard in which every domain, from the root down, is a contract that resolves its own subdomains and sets its own access rules.

What problem does it solve?

ENS (ERC-137) gives Ethereum addresses human-readable names, but its architecture (registry, registrars, resolvers) is comparatively complex and it does not define standard access control for who may change a name.

ERC-4834 takes a simpler, more generic approach: each level of the hierarchy is just a contract implementing the same tiny interface. The root, top-level domains and subdomains are all "domains", so resolving a name is a simple iterative walk, much like DNS.

How it works

A domain contract implements two view functions:

interface IDomain {
    function hasDomain(string[] memory name) external view returns (bool);
    function getDomain(string[] memory name) external view returns (address);
}

Resolution. To resolve a.b.c, split it into ["a", "b", "c"], start at the root, and walk right-to-left: append c to the path and ask the root hasDomain(path), then move to getDomain(path); repeat for b, then a. If any hasDomain returns false, resolution fails. There is no depth limit, and every contract on the path fully controls what it returns, which allows behaviour like time-dependent resolution.

Optional extensions:

  • Registerable: createDomain, setDomain, deleteDomain plus canCreateDomain / canSetDomain / canDeleteDomain checks and matching events.
  • Enumerable: totalSubdomains() and subdomainByIndex(i).
  • Access Control: a subdomain can implement canMoveSubdomain / canDeleteSubdomain, which its parent should consult, so a subdomain is not limited to its parent's rules. A root might be run by a DAO and a leaf by a single NFT holder.

Sample code

Off-chain resolver using ethers v6:

import { Contract, JsonRpcProvider } from "ethers";

const ABI = [
  "function hasDomain(string[] name) view returns (bool)",
  "function getDomain(string[] name) view returns (address)",
];

async function resolve(name: string, rootAddr: string, provider: JsonRpcProvider) {
  const labels = name.split(".");
  let current = rootAddr;
  const path: string[] = [];
  for (let i = labels.length - 1; i >= 0; i--) {
    path.push(labels[i]);
    const domain = new Contract(current, ABI, provider);
    if (!(await domain.hasDomain(path))) throw new Error(`cannot resolve ${name}`);
    current = await domain.getDomain(path);
  }
  return current;
}

The path passed at each step follows the spec's reference algorithm, which accumulates labels from right to left.

Things to know

  • Status: Final. It is independent of ENS: names under ERC-4834 do not appear in ENS and vice versa. The spec says it is general enough to model ENS, but not the other way round.
  • Parents are all-powerful. A parent can re-point any subdomain, so before acquiring a pre-linked name, audit the contract and every parent up to the root.
  • Black-hole risk. A malicious subdomain can return false from canMoveSubdomain to lock itself in place, or true unexpectedly as a backdoor. Audit before calling setDomain.
  • There is no built-in notion of "owner", records or resolvers; those are left to implementations.

#naming #domains #ens #resolution #access-control

Details

Authors
Gavin John (@Pandapip1)
Status
Final
Type
Standards Track / ERC
Created
2022-02-22

Machine-readable: Markdown · JSON