Ethereum Name Service 백서

Ethereum Name Service

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 22쪽

"name" always refers to a single label within a specific registry. The full name is reconstructed by walking up the registry hierarchy. ### The IRegistry Interface Every registry in the hierarchy, whether it's the root registry, a TLD registry like `.eth`, or a user's subname registry, must implement the `IRegistry` interface: ```solidity interface IRegistry is IRegistryEvents { /// Returns the child registry for a label, or address(0) if none exists. function getSubregistry(string calldata label) external view returns (IRegistry); /// Returns the resolver for a label, or address(0) if none exists. function getResolver(string calldata label) external view returns (address); /// Returns this registry's parent and the label it's registered under. function getParent() external view returns (IRegistry parent, string memory label); } ``` These three functions are what enable the hierarchical model: * **`getSubregistry(label)`**: links a name to its child registry. This is how the tree is traversed downward during resolution. * **`getResolver(label)`**: links a name to its resolver contract. This is how records are found during resolution. * **`getParent()`**: links a registry back to its parent. This is how the [Universal Resolver V2](/ensv2/universal-resolver-v2) verifies canonical registry chains. `IRegistry` is deliberately minimal. It says nothing about tokens, permissions, or name lifecycle. The [Permissioned Registry](/ensv2/permissioned-registry) is the standard implementation that adds [ERC1155Singleton](/ensv2/erc1155-singleton) tokenization, [Enhanced Access Control](/ensv2/enhanced-access-control), expiry management, and [mutable token IDs](/ensv2/mutable-token-ids). But a custom registry could implement `IRegistry` with entirely different ownership and access models. #### IRegistryEvents `IRegistry` inherits `IRegistryEvents`, which defines the events any registry is expected to emit: | Event | Emitted when | | -------------------- | ----------------------------------- | | `LabelRegistered` | A name is registered with an owner | | `LabelReserved` | A name is reserved (no owner) | | `LabelUnregistered` | A name is unregistered | | `ExpiryUpdated` | Expiry extended via `renew()` | | `SubregistryUpdated` | Child registry pointer changed | | `ResolverUpdated` | Resolver address changed | | `TokenRegenerated` | Token ID changed due to role update | | `ParentUpdated` | Canonical parent reference changed | ### Resolution Resolution works by walking down the registry tree from root, querying `getResolver()` and `getSubregistry()` at each level. The deepest resolver found along the path wins (longest-suffix match). If a name has no resolver of its own, it inherits the resolver of its closest ancestor that does. See [Resolution: findResolver](/ensv2/universal-resolver-v2#resolution) on the Universal Resolver V2 page for the full algorithm and step-by-step examples with diagrams. ### Subtree Operations One consequence of this tree structure is that it becomes possible to delete or reassign entire subtrees in a single operation. For example, suppose `montoya.eth` is transferred to a new owner, who wants to configure their own set of subdomains; they can simply replace the subregistry responsible for subnames of `montoya.eth` with their own new subregistry: ```mermaid flowchart TB eth@{label: "<b>eth</b><hr>owner: 0x1234..."} montoya@{label: "&nbsp;<hr>owner: 0x5678..."} newMontoya@{label: "<b>montoya.eth</b><hr>owner: 0xABCD..."} inigo@{label: "<b>Resolver 2</b><hr>owner: 0x7890...<br>addr(60): 0x7890...", shape: notch-rect} domingo@{label: "<b>domingo.montoya.eth</b><hr>owner: 0x90AB..."} montoyaResolver@{label: "<b>Resolver 1</b><hr>owner: 0x5678...<br>addr(60): 0x5678...", shape: notch-rect} eth ~~~ montoya eth-- montoya --> newMontoya eth-- montoya --> montoyaResolver montoya-- inigo --> inigo montoya-- domingo --> domingo ``` All resolvers and subregistries previously associated with `montoya.eth` are thus removed in a single operation. The new owner will still need to replace the resolver for `montoya.eth` if they wish to change how the bare name itself is resolved, however. ### Namespace Aliasing This hierarchical structure need not be limited to trees, either; by reusing the same subregistry for more than one name, entire namespaces can be aliased to each other: ```mermaid flowchart TB root@{label: "<b>Registry 1</b><hr>owner: 0x0123...</b>"} eth@{label: "<b>Registry 2</b><hr>owner: 0x1234..."} montoya@{label: "<b>Registry 3</b><hr>owner: 0x5678..."} inigo@{label: "<b>Resolver 4</b><hr>owner: 0x7890...<br>addr(60): 0x7890...", shape: notch-rect} domingo@{label: "<b>Registry 5</b><hr>owner: 0x90AB..."} montoyaResolver@{label: "<b>Resolver 1</b><hr>owner: 0x5678...<br>addr(60): 0x5678...", shape: notch-rect} root-- eth --> eth eth-- montoya --> montoya eth-- wallet --> montoya eth-- montoya --> montoyaResolver montoya-- inigo --> inigo montoya-- domingo --> domingo ``` In this example, both `inigo.montoya.eth` and `inigo.wallet.eth` resolve identically, as would any other subnames with resolvers set. Notably, `domingo.montoya.eth` will resolve using Resolver 1, while `domingo.wallet.eth` will not resolve at all - there are no resolvers set anywhere in its hierarchy! If we set a resolver for `domingo` in Registry 3, both names would resolve identically using it, just as they do for `inigo`. This example also illustrates that in ENSv2, registries have no individual concept of 'their name'. In earlier diagrams we labelled each registry with a name for convenience, but as these examples demonstrate, there's no requirement that a registry have exactly one name associated with it - it can have thousands, or none at all! ### Token Representation and Permissions Registries in ENSv2 are typically implemented as [ERC1155Singleton](/ensv2/erc1155-singleton) token contracts, where each subname is an NFT with exactly one owner. Because of the hierarchical structure, merely owning a subname token does not guarantee anything in isolation: the registry must be referenced by a parent registry, and so on up to the root. Client authors must take care in how they represent names to users. The [Universal Resolver V2](/ensv2/universal-resolver-v2) provides `findCanonicalRegistry()` to verify a registry's position in the hierarchy. Permissions are managed through [Enhanced Access Control](/ensv2/enhanced-access-control), a role-based system where each name has its own set of grantable and revokable roles. By selectively revoking roles, all the functionality of the [ENSv1 Name Wrapper](/wrapper/overview) can be replicated. See the [Permissioned Registry](/ensv2/permissioned-registry) page for the full role table, transfer behavior, and code examples. ## Registry Template In ENSv1, different parts of the namespace used different registry contracts: the root ENS Registry, the Name Wrapper, and dedicated subname registrars were all separate, incompatible implementations. ENSv2 unifies this with a single extensible base: **PermissionedRegistry**. ### One Registry to Rule Them All [PermissionedRegistry](/ensv2/permissioned-registry) is not just the contract that manages `.eth` names. It's the template that every registry in the ENSv2 hierarchy is built from. Whether it's the root `.eth` registry, a project running a subdomain service, or a DAO managing community names, they all use the same base contract. This means every registry in the tree shares the same: * **[ERC1155Singleton](/ensv2/erc1155-singleton)** token model: each name is an NFT with a single owner * **[Enhanced Access Control](/ensv2/enhanced-access-control)** permission system: roles, admin roles, resource scoping * **[Mutable Token IDs](/ensv2/mutable-token-ids)**: version counters that protect against stale permissions and transfer griefing * **[anyId polymorphism](/ensv2/mutable-token-ids#anyid-polymorphism)**: accept labelhash, tokenId, or resource interchangeably * **Name lifecycle**: the same AVAILABLE → REGISTERED state machine (with optional reservation) ### Customizing via Inheritance To create a custom registry, you inherit from `PermissionedRegistry` and override the behaviors you need. The base contract is designed with virtual functions at the key extension points. ENSv2 ships two derived registries: * **UserRegistry**: for user-owned subdomain registries (described below) * **WrapperRegistry**: a migration-specific variant that receives locked Name Wrapper tokens from ENSv1 (see [Migration](/ensv2/migration)) #### UserRegistry A UUPS-upgradeable proxy designed for user-owned subdomain registries. It adds: * Proxy-based deployment via [`VerifiableFactory`](/ensv2/verifiable-factory) (cheap per-name deployments) * An `initialize()` function that grants initial roles to the passed accounts * Upgrade authorization gated by `ROLE_UPGRADE` ```solidity contract UserRegistry is Initializable, PermissionedRegistry, UUPSUpgradeable, IProxyAuthorization, IEACGrantInitializable { // ... constructor, supportsInterface, _authorizeUpgrade omitted function initialize(Grant[] calldata grants) public initializer { __UUPSUpgradeable_init(); emit RegistryCreated(); for (uint256 i; i < grants.length; ++i) { _grantRoles(ROOT_RESOURCE, grants[i].roleBitmap, grants[i].account, false); } if (roleCount(ROOT_RESOURCE) == 0) { revert InvalidOwner(); } } } ``` This is the registry that gets deployed when someone creates subnames under their name. Each child namespace gets its own `UserRegistry` proxy instance. ### Registry Interface Hierarchy Registry functionality is split across layered interfaces. Each layer adds a capability, and PermissionedRegistry implements all of them. A custom registry can implement only the layers it needs. ```mermaid graph BT IRegistry["IRegistry"] IOwnedRegistry["IOwnedRegistry"] ITemporalRegistry["ITemporalRegistry"] IERC1155Singleton["IERC1155Singleton"] ITokenizedRegistry["ITokenizedRegistry"] IStandardRegistry["IStandardRegistry"] IEnhancedAccessControl["IEnhancedAccessControl"] IUnsafeTransferable["IUnsafeTransferable"] IContractNamer["IContractNamer"] IPermissionedRegistry["IPermissionedRegistry"] IRegistry --> IOwnedRegistry IRegistry --> ITemporalRegistry IERC1155Singleton --> ITokenizedRegistry IOwnedRegistry --> ITokenizedRegistry ITokenizedRegistry --> IStandardRegistry ITemporalRegistry --> IStandardRegistry IStandardRegistry --> IPermissionedRegistry IEnhancedAccessControl --> IPermissionedRegistry IUnsafeTransferable --> IPermissionedRegistry IContractNamer --> IPermissionedRegistry ``` | Interface | Extends | Adds | | ----------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | | `IRegistry` | `IRegistryEvents` | `getSubregistry`, `getResolver`, `getParent` | | `IOwnedRegistry` | `IRegistry` | `findOwner` | | `ITemporalRegistry` | `IRegistry` | `findExpiry` | | `ITokenizedRegistry` | `IOwnedRegistry`, `IERC1155Singleton` | `findTokenId` | | `IStandardRegistry` | `ITemporalRegistry`, `ITokenizedRegistry` | `register`, `renew`, `unregister`, `setSubregistry`, `setResolver`, `setParent`, `getExpiry` | | `IPermissionedRegistry` | `IStandardRegistry`, `IEnhancedAccessControl`, `IUnsafeTransferable`, `IContractNamer` | `latestOwnerOf`, `getOwner`, `getState`, `getStatus`, `getResource`, `getTokenId`, `isEmancipated`, `setURI`, `getURI` | `IRegistry` is the minimum for participating in ENS resolution: the [Universal Resolver V2](/ensv2/universal-resolver-v2) only needs `getSubregistry` and `getResolver` to walk the hierarchy. The intermediate interfaces are opt-in capability layers that the [UniversalHelper](/ensv2/universal-resolver-v2#universalhelper) detects via [ERC-165](https://eips.ethereum.org/EIPS/eip-165) (for example, `findExactOwner` checks for `IOwnedRegistry` before calling it). Most custom registries should extend PermissionedRegistry directly for the full feature set. #### Which Interface to Target | Goal | Interface | What you get | | ---------------------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------- | | Resolution only (no ownership or tokens) | `IRegistry` | Participates in the hierarchy, URv2 can resolve through it | | Resolution + ownership queries | `IOwnedRegistry` | [UniversalHelper](/ensv2/universal-resolver-v2#universalhelper)'s `findExactOwner` works | | Full ENS-compatible registry | `IStandardRegistry` | Tokens, expiry, lifecycle, compatible with ENSjs and indexers | | Full registry + permissions | Extend `PermissionedRegistry` | Everything above, plus EAC roles out of the box | PermissionedRegistry registers all of these interfaces via ERC-165 (`supportsInterface`), so external contracts can detect exactly which capabilities a given registry supports at runtime. ### Configuration Patterns While every registry uses the same base contract, the way roles are configured determines the trust model. The two main patterns are: #### Fully Controlled (Managed) The registry operator keeps operational roles on `ROOT_RESOURCE` and configures each name's token roles at registration via the `roleBitmap` parameter of `register()`. This gives the operator flexibility to decide exactly how much control each name owner gets. For example, a company managing `xyzcompany.eth` subnames for its members could: **Operator roles on `ROOT_RESOURCE`:** * `ROLE_REGISTRAR`: register new member names * `ROLE_UNREGISTER`: remove members who leave * `ROLE_RENEW`: extend member name expiry * `ROLE_SET_RESOLVER`: set or override resolvers for any member * `ROLE_SET_SUBREGISTRY`: override or set subregistry for any member **Member token roles (set per name at registration):** * Give `ROLE_SET_RESOLVER` if members should control their own records * Withhold `ROLE_CAN_TRANSFER_ADMIN` if members shouldn't transfer their name (admin-only role; there is no non-admin `ROLE_CAN_TRANSFER`) * Withhold `ROLE_SET_SUBREGISTRY` if members shouldn't create sub-subnames Since the roles on `ROOT_RESOURCE` overlap with member token roles (e.g. the operator also holds `ROLE_SET_RESOLVER`), the operator retains the ability to override individual members. This is intentional for managed setups where the operator needs administrative access. #### Emancipated (ETH-like) An emancipated registry separates operator and owner roles so that no `ROOT_RESOURCE` role can interfere with individual name owners. This is how the `.eth` registry works: the registrar holds only `ROLE_REGISTRAR` and `ROLE_RENEW`, while name owners hold `ROLE_SET_RESOLVER`, `ROLE_SET_SUBREGISTRY`, and `ROLE_CAN_TRANSFER_ADMIN` on their own tokens. See [Permissioned Registry: Emancipation](/ensv2/permissioned-registry#emancipation) for the full definition, verification steps, and how emancipation works across the hierarchy. ### Building Your Own Registry To build a custom registry for your project, extend `PermissionedRegistry` and override what you need. Common customization points include: | Override | Purpose | Example | | -------------------------------------------------- | -------------------------- | --------------------------------------------- | | `register()` | Custom registration logic | Add allowlists, custom pricing, or validation | | `getResolver()` / `getSubregistry()` | Custom resolution behavior | Fallback to external data sources | | `_authorizeUpgrade()` (requires `UUPSUpgradeable`) | Upgrade control | Gate upgrades behind a multisig or governance | All of the inherited infrastructure (EAC roles, ERC1155 tokens, anyId polymorphism, the name lifecycle state machine) works out of the box. You only override the parts you want to change. ## Reverse Resolution Reverse resolution maps an address back to an ENS name (the "primary name"). ENSv1 already supports multi-chain reverse resolution via per-chain [L2 Reverse Registrars](/registry/reverse) with signature-based claims ([ENSIP-19](/ensip/19)). ENSv2 refines the signature-based claim system and integrates reverse resolution into the v2 registry hierarchy. ### At Launch At launch, the reverse namespace (`addr.reverse`, `default.reverse`) stays on v1 infrastructure. The v2 `ReverseRegistry` holds entries for these names, but resolution is handled by v1 contracts. Existing primary names continue to work without any user action. **`addr.reverse`**: Registered in the `ReverseRegistry` with `ENSV1Resolver` as its resolver. This mirrors resolution through the v1 ENS registry, so existing v1 reverse records are automatically visible in v2. Users update their reverse record via the v1 `ReverseRegistrar.claimForAddr()`. **`default.reverse`**: Uses the v1 `DefaultReverseRegistrar`, which stores primary names directly and resolves them via wildcard resolution on-contract. Users set their name via `DefaultReverseRegistrar.setNameForAddr()`. #### Contract Account Adapters Contract accounts (multisigs, smart wallets, protocol contracts) can't always interact with the v1 reverse registrars directly, because those contracts authorize via `msg.sender`. Two adapter contracts, added as controllers on the v1 registrars, forward reverse-record updates on behalf of a contract: | Adapter | Method | Forwards to | | -------------------------------- | -------------------------- | ------------------------------------------ | | `ReverseRegistrarAdapter` | `claim(account, resolver)` | `ReverseRegistrar.claimForAddr()` | | `DefaultReverseRegistrarAdapter` | `setName(account, name)` | `DefaultReverseRegistrar.setNameForAddr()` | Both adapters authorize the caller with the same "namer" check: the caller must be the account itself, the account's `Ownable` owner, or approved by the account's own `IContractNamer.isContractNamer()` implementation. #### Migration to v2-native The reverse namespace will be migrated to v2-native infrastructure post-launch. The same migration pattern applies to both testnet and mainnet. The full multi-chain reverse resolution system described below will be rolled out as L2 partner integrations are completed. ### Multi-Chain Reverse Resolution (Upcoming) ENSv2 introduces a new `L2ReverseRegistrar` designed to be deployed on each chain individually. Each deployment stores the mapping from addresses to their primary names for that chain. The [Universal Resolver V2](/ensv2/universal-resolver-v2) resolves reverse lookups via the inherited `reverse(lookupAddress, coinType)` function, which queries the appropriate reverse registrar based on the coin type. #### Setting a Primary Name The L2ReverseRegistrar provides four methods for setting a primary name, covering different authorization models: | Method | Authorization | Use case | | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- | | `setName(name)` | `msg.sender` only | EOA setting its own primary name | | `setNameForAddr(addr, name)` | Caller is the address, its `Ownable` owner, or approved via the address's `IContractNamer` | Setting from a different caller context | | `setNameForAddrWithSignature(claim, signature)` | ERC-191 signature from the address | Gasless or cross-chain claims for EOAs | | `setNameForContractWithSignature(claim, owner, signature)` | `owner` passes the namer check (Ownable or `IContractNamer`) and provides an ERC-191 signature (ERC-1271/6492 supported) | Contracts owned by smart contract wallets (Safe, ERC-4337) | #### Signature-Based Claims For gasless or cross-chain primary name claims, the signature methods accept a `NameClaim` struct: ```solidity struct NameClaim { string name;
프로젝트로 돌아가기