Ethereum Name Service 백서

Ethereum Name Service

원문

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

s #### Detached Names Detached names are emancipated children of locked parents that don't have `CANNOT_UNWRAP` set (3LD+ only). They are migrated via the parent's `WrapperRegistry`. 1. Transfer the ERC-1155 token to the parent's WrapperRegistry 2. The token is unwrapped to the Graveyard and the v1 resolver is cleared (the v2 name gets the resolver from the transfer data) 3. The name is registered with the same token roles as `ETHRegistrar.register()`, plus `ROLE_RENEW` and `ROLE_RENEW_ADMIN` if the v1 token had `CAN_EXTEND_EXPIRY` set ### Fuse-to-Role Conversion When migrating locked names, ENSv1 fuses are converted to ENSv2 roles. The key principle: a burned fuse that restricts an action means the corresponding role is **not granted**. Admin roles (the `<< 128` shifted counterparts) are only granted when `CANNOT_BURN_FUSES` is **not** set. If fuses are frozen, only regular roles are granted, preventing any further permission changes in v2. The one exception is `ROLE_CAN_TRANSFER_ADMIN`: it has no non-admin counterpart and is granted whenever `CANNOT_TRANSFER` is not burned, frozen or not. #### Token Roles | ENSv1 Fuse | ENSv2 Role | Granted when fuse is... | | --------------------- | --------------------------- | ----------------------- | | `CAN_EXTEND_EXPIRY` | `ROLE_RENEW` | Set (enabled) | | `CANNOT_SET_RESOLVER` | `ROLE_SET_RESOLVER` | Not set (not burned) | | `CANNOT_TRANSFER` | `ROLE_CAN_TRANSFER_ADMIN` | Not set (not burned) | | `CANNOT_BURN_FUSES` | Admin counterparts of above | Not set (not frozen) | | `CANNOT_SET_TTL` | N/A | Ignored (no TTL in v2) | #### Subregistry Roles These roles are granted to the name owner on the WrapperRegistry's [`ROOT_RESOURCE`](/ensv2/enhanced-access-control#resources), giving them contract-wide authority over the subregistry. | ENSv1 Fuse | ENSv2 Role | Granted when fuse is... | | ------------------------- | ----------------------------------------------- | ----------------------- | | `CANNOT_CREATE_SUBDOMAIN` | `ROLE_REGISTRAR` | Not set (not burned) | | (always) | `ROLE_RENEW` + `ROLE_UPGRADE` + `ROLE_CAN_NAME` | Always granted | | `CANNOT_BURN_FUSES` | Admin counterparts of all of the above | Not set (not frozen) | ### Graveyard The `Graveyard` contract receives migrated v1 tokens and provides functionality to clear stale v1 registry entries so they no longer resolve. It has no mechanism to transfer or upgrade the tokens it holds. During migration, the resolver of the migrated name is cleared (when possible) and, for unwrapped names, v1 registry ownership is transferred to the Graveyard. However, the unemancipated subname namespace under the migrated name is left unchanged. The `clear()` function handles this cleanup separately: ```solidity // Anyone can call this to clean up v1 registry entries Graveyard.clear(names) ``` `clear()` recursively walks the v1 namespace hierarchy for each name, clearing resolvers and transferring subnode ownership to the Graveyard. It is permissionless: callers cannot harm names they don't own, because the function only succeeds for names the Graveyard controls or names that have expired past the v1 grace period. For expired 2LD names that were never migrated, `clear()` re-registers them to the Graveyard via the v1 BaseRegistrar with a near-permanent duration, then clears their resolver. This is used by an off-chain service that periodically calls `clear()` on expired names to prevent stale v1 resolution. Locked names that are not owned by the Graveyard cannot be cleared (reverts `NameNotClearable`). ### ENSv1 Continuity Not all names will migrate immediately. ENSv2 provides mechanisms to keep unmigrated names functional. #### Renewals Renewals are handled by two contracts depending on the name's status: * **`ETHRegistrar`**: renews REGISTERED names (migrated names). Does not sync v1. * **`ETHRenewerV1`**: renews RESERVED names (unmigrated names). Syncs the expiry back to the v1 BaseRegistrar so both systems stay in lockstep. **Key invariants:** * The v2 expiry is always `BONUS_PERIOD` ahead of the v1 expiry * The `ETHRegistrar` cannot register RESERVED names (it lacks `ROLE_REGISTER_RESERVED`), so unmigrated names are protected until they expire * `ENSV1Resolver` continues resolving unmigrated names until the v2 reservation expires #### Unmigratable Names Some names are structurally unable to migrate (see [Restrictions](#restrictions)). These names remain fully functional on v1: * Resolution continues via `ENSV1Resolver` as long as the v2 reservation is active * Renewals work via `ETHRenewerV1`, keeping the v1 and v2 expiries in sync * v1 fuses, resolver, and ownership remain unchanged The only v2 features unavailable to unmigratable names are per-record permissions, record linking, and the new resolver. Once the v2 reservation expires and the 28-day v2 grace period has passed, the name becomes available for fresh registration in v2 (during the grace window it can still be renewed via `ETHRenewerV1`). The `Graveyard` can clear the expired v1 namespace. #### What Happens to Unmigrated Names Names that *could* migrate but don't will eventually expire. Since v1 registrations are disabled, expired names never become available in v1 again. The v2 RESERVED slot also expires. Once expired in v2 and past the 28-day v2 grace period (during which `ETHRenewerV1` can still renew it), the name becomes available for fresh registration via the `ETHRegistrar`. An off-chain service re-registers expired names to the Graveyard, which then clears their v1 resolvers so they no longer produce stale results. ### Scenarios #### 100 days remaining *A name with 100 days left in v1 is premigrated.* The RESERVED slot has 162 days left (100 + 62 day bonus). The v1 token expires after 100 days and its grace period ends after 190 days (100 + 90). The v2 reservation expires after 162 days and becomes available for registration after 190 days (162 + 28 day grace). The v2 availability aligns with the end of the v1 grace period. #### Migrates then renews *A name with 50 days remaining is premigrated, migrated, then renewed for 50 days.* The RESERVED slot has 112 days (50 + 62). The owner migrates, promoting to REGISTERED. The v1 token goes to the Graveyard with 50 days left. The owner renews via `ETHRegistrar` for 50 days, extending the v2 registration to 162 days (50 + 62 + 50). The v2 grace period begins after 162 days and lasts 28 days. #### In grace period, renews before migrating *A name expired 61 days ago and has 29 days left in the v1 grace period (i.e., -61 days remaining). The owner cannot migrate because the name is expired in v1.* The RESERVED slot has 1 day left (-61 + 62 day bonus). The owner renews for 62 days via `ETHRenewerV1` (the minimum needed to make the name active again), which extends both expiries: * **v1 expiry**: -61 + 62 = 1 day from now. Grace period ends after 91 days (1 + 90). * **v2 expiry**: 1 + 62 = 63 days from now. Becomes available after 91 days (63 + 28). The name is active again (no longer in grace), so the token can be transferred and migrated to v2. ### Restrictions Migration is not possible in the following cases: * The v1 token is not transferable (owner or approval restrictions) * Locked names with `CANNOT_TRANSFER` burned * Locked names with `CANNOT_APPROVE` burned and a non-null `getApproved()` (reverts `FrozenTokenApproval`) * 3LD+ subnames whose parent has not migrated yet ### Contracts | Contract | Purpose | | ----------------------------- | ---------------------------------------------------------------------------------- | | `BatchRegistrar` | Batch-reserves v1 names in v2 during premigration | | `UnlockedMigrationController` | Migrates unwrapped and unlocked 2LD names | | `LockedMigrationController` | Migrates locked 2LD names | | `MigrationHelper` | Batch migration of mixed unwrapped/unlocked/locked tokens using operator approvals | | `WrapperRegistry` | Migrates locked/detached 3LD+ names; replicates fuse-based access control in v2 | | `Graveyard` | Receives migrated v1 tokens; clears stale v1 registry entries and resolvers | | `ETHRenewerV1` | Renews RESERVED (unmigrated) names with v1 BaseRegistrar sync | | `ENSV1Resolver` | Wildcard fallback resolver for premigrated names | | `PublicResolverV2` | Replacement for v1 PublicResolver that respects v2 ownership | import { Card } from '../../components/ui/Card' import { FrenCallout } from '../../components/ensv2/FrenCallout' import { IdExplorer } from '../../components/ensv2/IdExplorer' ## Mutable Token IDs Names in the [Permissioned Registry](/ensv2/permissioned-registry) are represented as [ERC1155Singleton](/ensv2/erc1155-singleton) tokens, where each registered name is a token with exactly one owner. ENSv2's [Enhanced Access Control](/ensv2/enhanced-access-control) system allows name owners to delegate fine-grained permissions to multiple accounts. This flexibility requires a mechanism to keep permissions in sync with a name's lifecycle, for example invalidating delegated roles when a name changes hands or expires. ENSv2 solves this with **mutable token IDs** that change in response to security-relevant events, providing automatic protection against two attack vectors: stale permissions and transfer griefing. ### The Problem #### Stale Permissions Imagine Alice registers `alice.eth` and grants Bob `ROLE_SET_RESOLVER`. Later, Alice's name expires, and Carol registers `alice.eth`. If permissions were tied to a fixed identifier, Bob's role grant from Alice's registration would carry over - Carol wouldn't know that Bob has resolver permissions on her newly-registered name. #### Transfer Griefing Imagine Alice owns `alice.eth` with `ROLE_CAN_TRANSFER_ADMIN` and `ROLE_SET_RESOLVER_ADMIN`, and lists it for sale on a marketplace. The marketplace holds an approval to transfer the token. A buyer submits a purchase transaction, which enters the mempool. Alice sees it and frontruns with a `revokeRoles` call that strips `ROLE_SET_RESOLVER_ADMIN` from the name. The buyer's transaction then executes - they receive the name, but it's been silently degraded: they can no longer change the resolver. Without mutable token IDs, the buyer would have no protection against this. ### How Token IDs Work #### Canonical ID Each name in the registry is internally tracked by its **canonical ID**, a stable 256-bit identifier derived from the name's **labelhash** (`keccak256` of the label string) with the lower 32 bits zeroed out. The canonical ID never changes for a given label, regardless of how many times the name is registered, transferred, or has its permissions modified. The registry uses the canonical ID as the key to look up the name's storage entry, which contains the name's current state: subregistry, resolver, expiry, and two version counters. From this entry, the registry derives the name's current **token ID** (used for ERC1155 ownership) and its current **resource** (used as the key for [EAC](/ensv2/enhanced-access-control) permission storage). Both are produced by encoding a version counter into the lower 32 bits of the canonical ID. #### Version Counters The [Permissioned Registry](/ensv2/permissioned-registry) maintains two version counters in each name's storage entry: | Counter | Incremented when | Encoded into | Purpose | | ---------------- | ------------------------------------------------------------------- | ------------ | ---------------------------------------------------------------------------- | | `tokenVersionId` | Roles are granted or revoked, name is unregistered or re-registered | Token ID | Invalidates marketplace approvals when the name's permission profile changes | | `eacVersionId` | Name is unregistered or re-registered | Resource | Isolates permissions across different registrations of the same label | When a counter increments, the derived ID changes, producing a new token ID or a new resource. Re-registration increments both counters simultaneously. #### ID Types All three identifier types share the same upper 224 bits (from the labelhash) and differ only in their lower 32 bits: | ID | Lower 32 bits | Used for | | ---------------- | ---------------- | ------------------------------------------- | | **Canonical ID** | `0x00000000` | `_entries` mapping key (name storage) | | **Token ID** | `tokenVersionId` | ERC1155 ownership and marketplace approvals | | **Resource** | `eacVersionId` | EAC `_roles` mapping (permission checks) | #### ID Explorer <FrenCallout fren="peanut" variant="tip" title="Interactive Widget"> Explore how these IDs are derived for any label. Slide the version counters to see how the token ID and resource change while the canonical ID stays fixed. </FrenCallout> <Card> <IdExplorer /> </Card> #### Regeneration When a version counter increments, the registry performs a **regeneration**: the old token is burned and a new one with the updated token ID is minted to the same owner, atomically in a single transaction. The owner doesn't change - only the ID does. The registry emits a `TokenRegenerated(oldTokenId, newTokenId)` event to signal this. #### How This Solves the Problems **Stale permissions** are solved by `eacVersionId`. When a name expires and is re-registered, both version counters increment. The new registration gets a fresh [resource](/ensv2/enhanced-access-control#resources) (because `eacVersionId` changed), and all role grants from the previous registration are effectively orphaned - they're stored under the old resource, which no longer corresponds to any active name. **Transfer griefing** is solved by `tokenVersionId`. When Alice tries to frontrun the sale by revoking roles on the listed name, the role change triggers a regeneration: the old token is burned and a new one with a new ID is minted. The marketplace's transfer still references the old token ID, so it cannot go through - the token it points to no longer exists. If the buyer still wants the name, the order must be re-created against the new token ID, at which point the roles can be inspected again. Note that legitimate transfers move roles from the old owner to the new owner without triggering regeneration, so a transfer never invalidates the token ID it is using. Regeneration is not the only safeguard: a safe transfer also makes sure the buyer actually receives what they expect. It reverts in two more situations: * `TransferUnsafeUntilRegistryIsEmancipated`: the registry holding the name is not [emancipated](/ensv2/permissioned-registry#emancipation), so an account with root roles could still override the new owner. * `TransferUnsafeWithMultipleAssignees`: an account other than the sender still holds roles on the token, so the name would arrive with third parties controlling parts of it. Users who want to knowingly bypass these checks can use the registry's unsafe transfer variants, `unsafeTransfer` and `unsafeBatchTransfer`. #### When Token IDs Change | Event | eacVersionId | tokenVersionId | Token ID changes? | Effect | | ------------------------------ | :----------: | :------------: | :--------------------------: | ----------------------------------------------------------- | | First registration | - | - | New token minted | Both counters start at 0 (storage default) | | Role grant/revoke | - | +1 | Yes (regeneration) | Invalidates marketplace approvals | | Transfer | - | - | No | Owner changes, same token ID | | Re-registration (after expiry) | +1 | +1 | Yes (old burned, new minted) | Old token burned, all prior role grants invalidated | | Unregistration (registered) | +1 | +1 | Yes (burned) | Token destroyed, versions incremented for next registration | | Unregistration (reserved) | - | - | No | No token exists to burn; counters unchanged | | Renewal | - | - | No | Only expiry changes | <FrenCallout fren="peanut" variant="note" title="Quick rule"> A token ID changes in exactly three situations: a role is granted or revoked, the name is re-registered after expiry, or the name is unregistered. Transfers and renewals never change the token ID. </FrenCallout> ### `anyId` Polymorphism Because token IDs change, you might not always have the current token ID on hand. To make this easier, most [Permissioned Registry](/ensv2/permissioned-registry) functions accept a `uint256 anyId` parameter that can be any of: * A **labelhash** (`keccak256` of the label string) * A **token ID** (current or even stale) * A **resource** (EAC resource identifier) * A **canonical ID** Internally, the registry applies `anyId ^ uint32(anyId)` to strip the lower 32 bits, resolving any of these to the same canonical ID and therefore the same storage entry. From that entry, the current token ID and resource are reconstructed as needed. This means you can pass whichever identifier you have - the registry figures out the rest. ```mermaid flowchart TD subgraph input [" "] direction LR LH(["labelhash"]) TK(["tokenId<br/><small>current or stale</small>"]) RS(["resource"]) SI(["canonicalId"]) end LH --> STRIP TK --> STRIP RS --> STRIP SI --> STRIP STRIP["<b>_entry(anyId)</b><br/>anyId ^ uint32(anyId)<br/><small>→ storageId (= canonicalId)</small>"] STRIP --> ENTRY["<b>Entry</b> storage<br/><small>subregistry · resolver · expiry<br/>eacVersionId · tokenVersionId</small>"] ENTRY --> BUILD_TK["<b>_constructTokenId</b><br/>withVersion(anyId, tokenVersionId)<br/><small>lower 32 = tokenVersionId</small>"] ENTRY --> BUILD_RS["<b>_constructResource</b><br/>withVersion(anyId, eacVersionId)<br/><small>lower 32 = eacVersionId</small>"] BUILD_TK --> USE_TK["<b>tokenId</b><br/><small>ERC1155 ownership<br/>& marketplace approvals</small>"] BUILD_RS --> USE_RS["<b>resource</b><br/><small>EAC _roles mapping<br/>& permission checks</small>"] style input fill:none,stroke:none style LH fill:#CEE1E8,stroke:#0080BC,color:#011A25 style TK fill:#CEE1E8,stroke:#0080BC,color:#011A25 style RS fill:#CEE1E8,stroke:#0080BC,color:#011A25 style SI fill:#CEE1E8,stroke:#0080BC,color:#011A25 style STRIP fill:#0080BC,stroke:#011A25,color:#fff style ENTRY fill:#011A25,stroke:#0080BC,color:#fff style BUILD_TK fill:#F5F5F5,stroke:#0080BC,color:#011A25 style BUILD_RS fill:#F5F5F5,stroke:#0080BC,color:#011A25 style USE_TK fill:#0080BC,stroke:#011A25,color:#fff style USE_RS fill:#0080BC,stroke:#011A25,color:#fff ``` Functions that accept `anyId` include: `setSubregistry()`, `setResolver()`, `renew()`, `unregister()`, `getExpiry()`, `getStatus()`, `getState()`, `getTokenId()`, `getResource()`, and all EAC role functions. :::note `anyId` polymorphism is specific to the [Permissioned Registry](/ensv2/permissioned-registry). The [Permissioned Resolver](/ensv2/permissioned-resolver) uses a [different resource scheme](/ensv2/enhanced-access-control#resources) based on `keccak256(node, part)` and does not use `anyId`. ::: ### Implications for Developers #### Don't Cache Token IDs Token IDs are not stable identifiers. If you need to reference a name, store the **labelhash** instead and use `getTokenId(anyId)` to get the current token ID when needed. #### Use `anyId` Where Possible Since most functions accept `anyId`, you can simply pass the labelhash and avoid dealing with token IDs entirely in many cases. #### Marketplace Integrations If you're building a marketplace or trading contract, be aware that: 1. Approvals tied to a specific token ID will be invalidated when the token ID changes 2. Use `getState(anyId)` to verify the current token ID before executing a trade 3. The `TokenRegenerated(oldTokenId, newTokenId)` event signals when a token ID changes #### Reading Token ID Changes ```ts [Viem] import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) // Get the current token ID for a name using its labelhash const state = await client.readContract({ address: registryAddress, abi: permissionedRegistryAbi, function
프로젝트로 돌아가기