Architecture Components
The ENS architecture is built on three foundational components that work together to provide a flexible, upgradeable naming system.The ENS Registry
The registry is the central component of ENS. It’s a single smart contract that maintains a mapping of domain names (as namehashes) to their associated records.Registry Data Structure
Fromcontracts/registry/ENSRegistry.sol:7-11:
- owner - The address that controls this domain
- resolver - The contract responsible for resolving this domain to addresses/resources
- ttl - Time-to-live for caching (in seconds)
Core Registry Functions
The ENS interface defines these essential operations:All registry operations use
bytes32 node hashes, not human-readable names. Names are converted to hashes using the namehash algorithm.Subdomain Management
The registry enables domain owners to create and manage subdomains:- Takes the parent node and a label (hash of subdomain name)
- Computes the subnode hash:
keccak256(parent_node, label) - Sets the owner of the new subdomain
- Returns the new subdomain hash
Only the owner of a domain can create its subdomains. This maintains the hierarchical trust model.
Authorization Model
Owner-Based Authorization
The registry uses a modifier to restrict operations to domain owners:Operator Approval
Domain owners can approve operators to manage all their domains:contracts/registry/ENSRegistry.sol:112-118:
Registrars
Registrars are contracts that own a domain in the registry and implement rules for allocating subdomains.Registrar Types
BaseRegistrar Pattern
The BaseRegistrar:- Owns the TLD (e.g.,
.eth) in the registry - Maintains a minimal set of ownership functions
- Delegates registration logic to controllers
- Provides strong guarantees: controllers can register new names but cannot modify existing ownership
Why separate BaseRegistrar and Controller?
Why separate BaseRegistrar and Controller?
This separation provides security guarantees:
- Name owners have confidence that even if the controller is upgraded, their existing names remain secure
- Controllers can be replaced to improve registration UX or pricing without risking existing domains
- Innovation can happen in registration mechanics while ownership remains constant
ETHRegistrarController
Implements the .eth registration process:- Commit Phase - User commits to a hash of (name + secret)
- Wait Period - Minimum delay to prevent frontrunning
- Reveal Phase - User reveals name and secret, pays registration fee
- Registration - If valid, name is registered through BaseRegistrar
Resolvers
Resolvers are responsible for storing and returning the actual data associated with a name.Resolver Interface
Fromcontracts/resolvers/Resolver.sol, a resolver can implement multiple profiles:
Resolvers use ERC-165 to advertise which interfaces they support, allowing applications to check capabilities before querying.
Record Storage
Resolvers store records indexed by the namehash:PublicResolver
The most common resolver implementation that supports all standard record types. Domain owners can:- Set Ethereum addresses:
setAddr(node, address) - Set content hashes:
setContenthash(node, hash) - Set text records:
setText(node, key, value) - Set multi-chain addresses:
setAddr(node, coinType, addressData)
Complete Resolution Flow
Here’s how a complete ENS lookup works:Registry Events
The registry emits events for all changes:These events allow applications to track ENS changes off-chain and maintain caches of ENS data.
Security Considerations
Ownership Guarantees
Fromcontracts/registry/ENSRegistry.sol:24-26, the registry is initialized with:
- The root is owned by a multisig or governance contract
- TLD owners are typically set once and rarely changed
- Domain owners have full control over their domains and subdomains
Resolver Trust
When you query ENS:- You trust the registry to return the correct resolver
- You trust the resolver to return correct data
Next Steps
Namehash Algorithm
Learn how names are converted to unique identifiers
Registry Contracts
Complete API reference for the ENS registry