EIPs Explained

ERC-1185 · Review · ERC · 2018-06-26

ERC-1185: Storage of DNS Records in ENS

Defines an ENS resolver profile for storing and querying DNS records on-chain, so an ENS name can act as an authoritative source for A, CNAME, TXT and other record sets.

What problem does it solve?

Traditional DNS is hierarchical: whoever runs .org ultimately controls whether ethereum.org resolves. ENS (ERC-137) gives a name's owner direct, on-chain control, and its subdomains can be irrevocably handed to other parties by smart contract.

This ERC lets the owner of an ENS name publish ordinary DNS records through their resolver. A DNS server or client that speaks this profile can then answer queries straight from ENS, without depending on a parent zone operator.

How it works

DNS normally manages a whole zone file at once. Rewriting a full zone on-chain for every small change would be expensive, so this profile works on record sets instead. A record set is identified by (node, name, resource type): for example, all A records for www.example.com under the ENS node for example.com. A set can hold zero or more values.

The resolver exposes four functions:

Function Purpose
setDNSRecords(bytes32 node, bytes data) Set, update or clear one or more records, given in DNS wire format. A record with no value clears that set.
clearDNSZone(bytes32 node) Remove every record for the node in one call.
dnsRecords(bytes32 node, bytes32 name, uint16 resource) Return all records for a name and type, in wire format.
hasDNSRecords(bytes32 node, bytes32 name) Whether any records exist for a name; needed for DNS wildcard handling.
  • node is the ENS namehash of the domain.
  • name is the keccak256 hash of the record name in DNS wire format.
  • resource is the numeric RR type from RFC 1035 and later RFCs (1 = A, 5 = CNAME, 16 = TXT, …).

Records belonging to the same set must be contiguous in the data passed to setDNSRecords; otherwise a later chunk overwrites an earlier one. The reference implementation also keeps a version number per node, so clearing a zone is a cheap version bump rather than deleting every entry. It also stores an optional zonehash, a content hash pointing to a full zone file kept off-chain.

Sample code

Reading the A records for www.example.eth (ethers v6):

import { Contract, JsonRpcProvider, namehash, dnsEncode, keccak256 } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const resolverAddr = await provider.getResolver("example.eth").then(r => r!.address);

const resolver = new Contract(
  resolverAddr,
  [
    "function dnsRecords(bytes32 node, bytes32 name, uint16 resource) view returns (bytes)",
    "function hasDNSRecords(bytes32 node, bytes32 name) view returns (bool)",
  ],
  provider,
);

const node = namehash("example.eth");
const name = keccak256(dnsEncode("www.example.eth")); // hash of the wire-format name
const A = 1;                                          // RR type for IPv4 addresses

if (await resolver.hasDNSRecords(node, name)) {
  const wire: string = await resolver.dnsRecords(node, name, A);
  console.log("raw RRset (DNS wire format):", wire);
}

The result is raw wire-format bytes; decode it with any DNS library.

Things to know

  • Status is Review: the interface is close to settled but not yet Final.
  • Because it works per record set rather than per zone, it cannot fully support zone transfers or DNSSEC signing of the stored data.
  • Writes go through the resolver's normal authorisation, so only the name's owner (or an approved operator) can change records.
  • Related resolver profiles cover text records (ERC-634) and content hashes (ERC-1577). Off-chain resolvers can serve the same data through ERC-3668 CCIP Read.

#ens #dns #resolver #naming #erc

Details

Authors
Jim McDonald (@mcdee)
Status
Review
Type
Standards Track / ERC
Created
2018-06-26
Requires
Required by

Machine-readable: Markdown · JSON