Ethereum Name Service 백서

Ethereum Name Service

원문

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

Name: 'getState', args: [labelhash], }) // state.tokenId is the current token ID // state.resource is the current EAC resource // state.status is AVAILABLE (0), RESERVED (1), or REGISTERED (2) // state.latestOwner is the current owner // state.expiry is the expiration timestamp ``` import { FrenCallout } from '../../components/ensv2/FrenCallout' ## ENSv2 Overview <FrenCallout fren="bittu" variant="tip"> ENSv2 is deployed on the Sepolia testnet, where you can already try the new contracts with the [ENS Explorer](https://explorer.ens.dev). </FrenCallout> Welcome to the next evolution of the Ethereum Name Service! ENSv2 introduces a suite of upgraded smart-contracts designed to make the protocol more scalable, modular and future-proof. This section will outline the high-level architecture, guiding principles and migration strategy for ENSv2. <iframe width="100%" style={{ aspectRatio: '16/9' }} src="https://www.youtube.com/embed/gLT1Wsu9Hu8" title="ENSv2 Explainer" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen /> ### What's new in ENSv2? * **Hierarchical Registries** - While ENSv1 used a single flat registry for all names, ENSv2 uses a [hierarchical model](/ensv2/registry-hierarchy) where a full name like `sub.alice.eth` is a chain of entries across registries linked by subregistry pointers. Name owners can deploy their own subname registry on demand. Registries and resolvers are deployed as proxies via the [Verifiable Factory](/ensv2/verifiable-factory). * **Permissions as Standard** - All of the functionality enabled by the [Name Wrapper in ENSv1](/wrapper/overview) has been integrated into the core of ENSv2 via a new role-based permission system called [Enhanced Access Control](/ensv2/enhanced-access-control). * **Shorter Grace Period** - The grace period has been reduced from 90 days in ENSv1 to 28 days. During this window, the expired name can still be renewed (by anyone, not just the owner). After the grace period, names enter a temporary premium period. * **Per-Account Resolvers** - Rather than sharing a single Public Resolver, every account gets its own [Permissioned Resolver](/ensv2/permissioned-resolver) proxy with fine-grained per-record permissions and [record linking](/ensv2/permissioned-resolver#records-and-linking). ```mermaid flowchart LR subgraph once ["One-time setup"] VF["Verifiable\nFactory"] PR["PermissionedResolver\n(per account)"] VF -->|"deploy proxy"| PR end subgraph names ["Name registration"] N1["alice.eth"] N2["bob.eth"] N3["wallet.eth"] end subgraph subnames ["On demand"] UR["UserRegistry"] end N1 & N2 & N3 -.->|"resolver"| PR N1 -->|"subregistry"| UR ``` ### What hasn't changed? * **Resolvers** - while we have developed new resolver contracts to take advantage of the changed environment enabled by ENSv2, the resolver interface remains the same. Custom resolver implementations are fully supported. * **True Ownership** - ENSv2 continues to prioritize trust minimization, enabling you to own your name fully, without having to worry about interference from centralized third-parties. ### Architecture | Page | Description | | --------------------------------------------------------- | --------------------------------------------------------------------------- | | [Registry Hierarchy](/ensv2/registry-hierarchy) | Hierarchical registry model, tree structure, resolution, namespace aliasing | | [Enhanced Access Control](/ensv2/enhanced-access-control) | Role-based permission system replacing ENSv1 fuses | | [ERC1155Singleton](/ensv2/erc1155-singleton) | Gas-optimized token standard with single ownership per token | | [Mutable Token IDs](/ensv2/mutable-token-ids) | Dynamic token IDs that protect against permission leaks and griefing | | [Verifiable Factory](/ensv2/verifiable-factory) | Deterministic CREATE2 proxy deployment with on-chain verification | ### Contracts | Page | Description | | ----------------------------------------------------- | ------------------------------------------------------------------ | | [Permissioned Registry](/ensv2/permissioned-registry) | Tokenized registry managing name ownership, state, and permissions | | [Permissioned Resolver](/ensv2/permissioned-resolver) | Per-account resolver with per-record roles and record linking | | [ETH Registrar](/ensv2/eth-registrar) | Commit-reveal registration and renewal for .eth names | | [Universal Resolver V2](/ensv2/universal-resolver-v2) | Single entry point for name resolution across the hierarchy | | [DNS Name Resolution](/ensv2/dns-resolvers) | Resolving DNS domain names through the ENS protocol | | [Reverse Resolution](/ensv2/reverse-resolution) | Primary names and multi-chain reverse resolution | ### Guides | Page | Description | | -------------------------------------------------------------- | --------------------------------------------------------------------- | | [Migration](/ensv2/migration) | Guide to migrating ENSv1 names (locked, unlocked, unwrapped) to ENSv2 | | [For App Developers](/ensv2/tutorial-app-developers) | What changes for apps that resolve ENS names | | [For Contract Developers](/ensv2/tutorial-contract-developers) | Tutorial: build a subname registrar on the Permissioned Registry | | [Registry Template](/ensv2/registry-template) | Building custom registries, configuration patterns, emancipation | | [Indexing](/ensv2/indexing) | Events and functions for building indexers and subgraphs | ### Deployments (Sepolia) The ENSv2 contract addresses on Sepolia are listed in the canonical [Deployments](/learn/deployments#sepolia-ensv2) section. import { Card } from '../../components/ui/Card' import { FrenCallout } from '../../components/ensv2/FrenCallout' import { RoleBitmapComposer } from '../../components/ensv2/RoleBitmapComposer' import { ContractReference } from '../../components/ensv2/ContractReference' import { MonoDiagram } from '../../components/ensv2/MonoDiagram' ## Permissioned Registry The Permissioned Registry is the tokenized registry at the heart of ENSv2 name management. Each registered name becomes an [ERC1155Singleton](/ensv2/erc1155-singleton) token with exactly one owner, and all permissions are managed through [Enhanced Access Control](/ensv2/enhanced-access-control). ### What Changed from ENSv1 In ENSv1, name management was split across three separate contracts: the ENS Registry (flat mapping of all names), the BaseRegistrar (ERC721 tokens for .eth), and the Name Wrapper (ERC1155 wrapping + fuses). ENSv2 replaces all three with a single unified contract. The table below summarizes the key differences; each concept is explained in the sections that follow. | Feature | ENSv1 | ENSv2 Permissioned Registry | | --------------- | ------------------------------------------------ | ------------------------------------------------------------------------------- | | Architecture | Single flat registry for all names | [Hierarchical](/ensv2/registry-hierarchy): each name can have its own registry | | Token standard | ERC721 (BaseRegistrar) or ERC1155 (Name Wrapper) | [ERC1155Singleton](/ensv2/erc1155-singleton) with single ownership | | Permissions | One-way fuse burning (Name Wrapper) | Reversible role-based [EAC](/ensv2/enhanced-access-control) | | Token IDs | Fixed (derived from namehash/labelhash) | [Mutable](/ensv2/mutable-token-ids): change on role updates and re-registration | | Subname control | Requires Name Wrapper + fuse configuration | Built-in via subregistry pointer + per-name roles | | Upgradeability | Not upgradeable | UUPS proxy pattern (for [UserRegistry](/ensv2/registry-template#userregistry)) | | Name states | Registered or not | Three-state lifecycle (see [Name Lifecycle](#name-lifecycle)) | ### Names Each name in the registry is identified by its **labelhash** (the `keccak256` hash of the label string). The on-chain data for a name is stored in an `Entry` struct: | Field | Type | Purpose | | ---------------- | ----------- | ----------------------------------------------------------------------------------------------------- | | `eacVersionId` | `uint32` | Isolates permissions across registrations (see [Mutable Token IDs](/ensv2/mutable-token-ids)) | | `tokenVersionId` | `uint32` | Invalidates marketplace approvals on role changes (see [Mutable Token IDs](/ensv2/mutable-token-ids)) | | `subregistry` | `IRegistry` | Pointer to a subregistry for managing subnames | | `expiry` | `uint64` | Timestamp after which the name is considered expired (`block.timestamp >= expiry`) | | `resolver` | `address` | Resolver contract that holds this name's records | Entries are stored in a mapping keyed by the [canonical ID](/ensv2/mutable-token-ids#canonical-id), the labelhash with its lower 32 bits zeroed. ### Name Lifecycle Names exist in one of three states: ```mermaid stateDiagram-v2 [*] --> AVAILABLE AVAILABLE --> REGISTERED: register() or renew() AVAILABLE --> RESERVED: register() with owner=0 or renew() RESERVED --> REGISTERED: register() REGISTERED --> AVAILABLE: unregister() or expiry RESERVED --> AVAILABLE: unregister() or expiry ``` * `AVAILABLE`: never registered or expired. Open for registration. * `RESERVED`: placeholder with no owner and no token. Useful for pre-allocating names before assigning them. * `REGISTERED`: has an owner, a token, and active permissions. **State transitions:** each transition requires a specific [EAC role](#roles) with the indicated scope. | From | To | Required role | [Scope](/ensv2/enhanced-access-control#resources) | | --------------------- | --------------------- | ------------------------ | ------------------------------------------------- | | AVAILABLE | REGISTERED | `ROLE_REGISTRAR` | root | | AVAILABLE | RESERVED | `ROLE_REGISTRAR` | root | | AVAILABLE (expired) | REGISTERED / RESERVED | `ROLE_RENEW` | root | | RESERVED | REGISTERED | `ROLE_REGISTER_RESERVED` | root | | REGISTERED / RESERVED | AVAILABLE | `ROLE_UNREGISTER` | root or name | #### Registration `register()` accepts a `label` (string), `owner`, `registry` (subregistry), `resolver`, `roleBitmap` (initial roles granted to the owner), and `expiry`. Labels are validated for size before registration. If `owner` is `address(0)`, the name is reserved instead of registered, and `roleBitmap` must be `0`. * A non-expired registered name cannot be re-registered; it must be unregistered first. * A reserved name cannot be re-reserved; it can only be promoted to registered. * When promoting a `RESERVED` name to `REGISTERED`, if `expiry` is `0` the current expiry is preserved. * Re-registering an expired name that had a previous owner burns the old token and increments both version counters. This ensures stale permissions and token approvals don't carry over. #### Unregistration `unregister()` sets the name's expiry to `block.timestamp`, making it immediately available. If the name was `REGISTERED` (has an owner), the token is burned and both version counters are incremented. #### Renewal `renew()` extends a name's expiry but cannot reduce it. Both `REGISTERED` and `RESERVED` names can be renewed. An expired name can also be revived by calling `renew()` on it, restoring it with its previous owner, token, and roles; re-registering the expired name instead starts fresh, with a new token and whatever owner and roles the new registration assigns. Reviving requires `ROLE_RENEW` on `ROOT_RESOURCE`; a name-scoped `ROLE_RENEW` grant works only while the name is unexpired. Names that were never registered cannot be renewed. ### anyId Polymorphism Most functions accept an `anyId` parameter that can be a `labelhash`, [token ID](/ensv2/mutable-token-ids#id-types), or [resource](/ensv2/enhanced-access-control#resources) interchangeably. Internally, `_entry()` zeroes the version bits to find the canonical storage slot for the name. This means you can pass whichever identifier you have on hand, and the registry resolves it to the same underlying entry. See [Mutable Token IDs](/ensv2/mutable-token-ids#anyid-polymorphism) for the full explanation and diagram. ### Ownership The token ID for a name changes when it is re-registered or when roles change (see [Mutable Token IDs](/ensv2/mutable-token-ids)). `ownerOf()` returns `address(0)` for: * Expired names (ownership is time-bounded) * Stale token IDs (after versioning changes, old token IDs are no longer valid) `latestOwnerOf()` returns the recorded owner of a token even after the name has expired. Burned token IDs, including stale IDs from earlier versions, return the zero address. ### EAC Integration All permissions are managed through [Enhanced Access Control](/ensv2/enhanced-access-control). #### Roles | Role | Value | Scope | Purpose | | ------------------------- | ------------------ | ------------ | ------------------------------------ | | `ROLE_REGISTRAR` | `1 << 0` | root | Register or reserve names | | `ROLE_REGISTER_RESERVED` | `1 << 4` | root | Promote reserved names to registered | | `ROLE_SET_PARENT` | `1 << 8` | root | Set parent registry | | `ROLE_UNREGISTER` | `1 << 12` | root or name | Unregister names | | `ROLE_RENEW` | `1 << 16` | root or name | Extend expiry | | `ROLE_SET_SUBREGISTRY` | `1 << 20` | root or name | Set subregistry | | `ROLE_SET_RESOLVER` | `1 << 24` | root or name | Set resolver | | `ROLE_CAN_TRANSFER_ADMIN` | `(1 << 28) << 128` | root or name | Authorize ERC1155 token transfers | | `ROLE_SET_URI` | `1 << 36` | root | Set metadata URI and renderer | | `ROLE_UPGRADE` | `1 << 124` | root | Authorize proxy upgrades | Each role has a corresponding admin role at `role << 128` (e.g., `ROLE_SET_RESOLVER_ADMIN = (1 << 24) << 128`), except `ROLE_CAN_TRANSFER_ADMIN` which exists only as an admin role. In TypeScript, use `1n << 24n` for the bigint equivalent. `ROLE_CAN_TRANSFER_ADMIN` has no regular (non-admin) variant and is checked against the token owner, not the operator. See [Transfers](#transfers) for details. "Root" scope means the role only works on `ROOT_RESOURCE`. "Root or name" means it can be granted on either scope, and the two compose: a root grant applies to all names. Admin roles on individual names are restricted to registration time (see [EAC Hook Overrides](#eac-hook-overrides)). #### Role Bitmap Composer <FrenCallout fren="peanut" variant="tip" title="Interactive Widget"> Select roles to compose a bitmap value for use with `grantRoles` and `revokeRoles`. </FrenCallout> <Card> <RoleBitmapComposer contract="registry" /> </Card> #### Granting and Revoking Roles The registry uses the standard EAC [`grantRoles` and `revokeRoles`](/ensv2/enhanced-access-control#granting-and-revoking) functions with [anyId polymorphism](#anyid-polymorphism). See [Code Examples](#code-examples) for usage. <FrenCallout fren="peanut" variant="note"> You can only grant roles for which you hold the corresponding admin role. The set of roles granted at registration determines what the owner can delegate; see [Emancipation](#emancipation) for the default bitmap. </FrenCallout> #### EAC Hook Overrides The Permissioned Registry overrides several [EAC callback hooks](/ensv2/enhanced-access-control#callback-hooks) to enforce registry-specific invariants: **Token regeneration on role changes**: when roles are granted or revoked via `grantRoles()` / `revokeRoles()`, the `_onRolesGranted` and `_onRolesRevoked` hooks trigger a token regeneration (burn + mint with a new token ID). This invalidates any pending ERC1155 transfer approvals tied to the old token ID, preventing an attacker from racing to transfer a token after their roles have been revoked. **Admin role restriction on names**: `_getSettableRoles` is overridden so that admin roles on individual names can only be assigned at registration time. After registration, only regular (non-admin) roles can be granted on a name, but admin roles can still be revoked (including by the holder revoking their own). On `ROOT_RESOURCE`, admin roles work normally. This prevents a name owner from escalating their own permissions after registration. #### Resource Scheme <FrenCallout fren="bittu" variant="tip" title="Developer tip"> This section explains how [EAC resources](/ensv2/enhanced-access-control#resources) are computed internally. You don't need this for normal use. `grantRoles` and `revokeRoles` handle resource computation automatically via [anyId polymorphism](/ensv2/mutable-token-ids#anyid-polymorphism). </FrenCallout> The registry derives each EAC resource from the name's labelhash and its current `eacVersionId`, so permissions are scoped per-name and automatically invalidated on re-registration: <MonoDiagram content={`255 32 31 0\n ┌──────────────────────────────────────┬─────────────────┐\n │ labelhash upper bits │ eacVersionId │\n │ (224 bits) │ (32 bits) │\n └──────────────────────────────────────┴─────────────────┘`} /> Registry resources participate in [anyId polymorphism](/ensv2/mutable-token-ids#anyid-polymorphism). See [Mutable Token IDs](/ensv2/mutable-token-ids) for how resources, token IDs, and canonical IDs relate. ### Transfers Transferring a name's token requires `ROLE_CAN_TRANSFER_ADMIN` on the **current owner** of the token (the transfer reverts with `TransferDisallowed` otherwise). It does not matter who initiates the transfer, the role is always checked against the owner. When a token transfers, all roles are atomically moved from the old owner to the new owner: the old owner's roles are revoked first (freeing assignee slots), then granted to the new owner. Roles granted to other accounts on the same name are unaffected. `safeTransferFrom` additionally protects the receiver in two situations: * The transfer reverts with `TransferUnsafeUntilRegistryIsEmancipated` if the registry is not [emancipated](#emancipation), meaning an account with dangerous root roles could override the new owner. * The transfer reverts with `TransferUnsafeWithMultipleAssignees` if an account other than the owner holds roles on the token, meaning the name would arrive with third parties still in control of parts of it. To transfer without these two checks, the registry implements `unsafeTransfer` and `unsafeBatchTransfer`. #### Operator Approval The owner of a name can call `setApprovalForAll(operator, true)` to approve an operator. An approved operator inherits the owner's EAC roles on every name the owner holds, allowing them to perform any role-gated action (set resolver, set subregistry, transfer, etc.) on the owner's behalf. This is an all-or-nothing delegation: an approved operator can act on every name the owner holds, with the owner's full set of roles. There is no way to scope operator approval to specific names or roles. ### Token Metadata The registry's `uri(tokenId)` function returns token metadata following the [EIP-1155](https://eips.ethereum.org/EIPS/eip-1155) standard. It supports two modes: * **Static URI:** a single string returned for all tokens. Clients substitute `{id}` with the hex token ID per the [EIP-1155 metadata spec](https://eips.ethereum.org/EIPS/eip-1155#metadata). Suitable when an off-chain service resolves per-token data from the URL template. * **Dynamic renderer:** an `IRegistryURIRenderer` contract that generates metadata per token. The registry calls `renderURI(registry, tokenId)`, passing itself so the renderer can query on-chain state (owner, expiry, records) to compose SVGs or JSON. The renderer takes precedence: if set, the static URI is ignored. If neither is set, `uri()` returns an empty string. `setURI(uri_, renderer)` sets both atomically and requires `ROLE_SET_URI` on `ROOT_RESOURCE`. #### Building a Custom Renderer Implement `IRegistryURIRenderer`: ```solidity interface IRegistryURIRenderer { function renderURI(IRegistry registry, uint256 tokenId) external view returns (string memory); } ``` The registry passes itself as the first argument, so the renderer can call `
프로젝트로 돌아가기