Ethereum Name Service 백서

Ethereum Name Service

원문

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

nclude spaces in a value, wrap it in single quotes: `t[description]='Hello World'`. Escape single quotes with a backslash: `t[notice]='it\'s ENS'`. </FrenCallout> This is the simplest approach: all record data lives in the DNS TXT record itself, with no on-chain registration required. #### Alias Resolution (DNSAliasResolver) Set the resolver to the DNSAliasResolver address and provide a rewrite rule in the context. Two modes are supported: **Suffix replacement**: rewrite the DNS suffix to an ENS suffix. For example, setting this TXT record on `example.com`: ``` ENS1 dnsalias.ens.eth com base.eth ``` The context `com base.eth` tells the resolver to strip the `com` suffix and replace it with `base.eth`. So `sub.example.com` resolves as `sub.example.base.eth`, and `example.com` itself resolves as `example.base.eth`. The resolver then looks up the rewritten name through the ENSv2 registry hierarchy. **Full replacement**: map a DNS domain to a single ENS name. When the context contains no space, the resolver ignores the queried name entirely and resolves the context as an ENS name. For example, setting this TXT record on `example.com`: ``` ENS1 dnsalias.ens.eth alice.eth ``` This makes `example.com` resolve as `alice.eth`. import { ContractReference } from '../../components/ensv2/ContractReference' import { MonoDiagram } from '../../components/ensv2/MonoDiagram' ## Enhanced Access Control Enhanced Access Control (EAC) is the permission system used throughout ENSv2. It controls who is allowed to do what, and on which names. EAC supports up to 2^256 independent resources (e.g., individual names), 64 roles per resource (32 regular + 32 admin), and up to 15 holders of a role within the context of a single resource. Think of it like a building where each room has its own set of locks: you can give someone a key to one room, or a master key that opens every room. EAC works the same way, but with ENS names and on-chain permissions. ### Resources A **resource** is the thing you're controlling access to. In most ENS contracts, a resource is a name - but it can be any `uint256` identifier that makes sense for the contract. Each ENSv2 contract defines how its resources are computed. For example, registries derive resources from a name's labelhash, while resolvers derive resources from a namehash and record type. See [How Contracts Use EAC](#how-contracts-use-eac) for the specific schemes. There's also a special resource called **`ROOT_RESOURCE`** (`0x0`) that represents the contract itself. Permissions granted on `ROOT_RESOURCE` apply everywhere - like a master key. If you have a role on `ROOT_RESOURCE`, you automatically have that role on every individual resource too. ```mermaid graph TD ROOT["ROOT_RESOURCE (0x0)\nApplies to all names"] A["alice.eth"] B["bob.eth"] C["carol.eth"] ROOT -.->|"master key"| A ROOT -.->|"master key"| B ROOT -.->|"master key"| C ``` ### Roles A **role** represents a specific permission - for example, "can set the resolver" or "can register subnames". Each ENS contract defines the roles that are relevant to it. Roles are always tied to a resource. Granting someone the "set resolver" role on `alice.eth` doesn't let them set the resolver on `bob.eth`. To give someone a permission across all names, grant the role on `ROOT_RESOURCE` instead. Up to 15 accounts can hold the same role on the same resource, enabling shared management and delegation. **How role checks work:** when a contract checks whether an account has a role on a specific name, it looks in two places - the name itself and `ROOT_RESOURCE` - and allows the action if the role is found in either. This is how the master key effect works. ### Admin Roles Every role has a corresponding **admin role** that controls who can manage it. If you hold the admin role, you can: * **Grant** the regular role to other accounts * **Grant** the admin role itself to other accounts * **Revoke** either role from other accounts ```mermaid graph LR Admin["Admin Role\n(manages access)"] Regular["Regular Role\n(performs actions)"] Admin -->|"grant / revoke"| Regular Admin -->|"grant / revoke"| Admin ``` For example, the admin role for "set resolver" controls who is allowed to grant or revoke the "set resolver" permission. Admin roles follow the same resource-scoping - you can be an admin for a specific name or for all names via `ROOT_RESOURCE`. ### Granting and Revoking Roles are managed through four functions: | Grant | Revoke | Scope | | ---------------- | ----------------- | ------------------------------- | | `grantRoles` | `revokeRoles` | Specific resource (name) | | `grantRootRoles` | `revokeRootRoles` | `ROOT_RESOURCE` (contract-wide) | The caller must hold the admin role for every role being granted or revoked. Admin role holders can also revoke the admin role itself, including from themselves. As a safety guardrail, `grantRoles` and `revokeRoles` reject `ROOT_RESOURCE`. You must use `grantRootRoles` / `revokeRootRoles` explicitly for contract-wide permissions. This prevents accidental global grants. All four functions return `true` if the account's roles actually changed, or `false` if the roles were already in the desired state. ### Callback Hooks EAC provides five internal hooks that contracts can override to customize permission behavior: #### Role Resolution Hook * **`_getRoles(resource, account)`**: returns the role bitmap for an account on a resource. By default, returns the stored roles directly. Contracts override this to inject additional role logic at read time. The [Permissioned Registry](/ensv2/permissioned-registry) overrides `_getRoles` so that ERC1155-approved operators (via `setApprovalForAll`) inherit the token owner's roles on that name. #### Role Change Callbacks * **`_onRolesGranted(resource, account, oldRoles, newRoles, roleBitmap)`**: called after a grant that changed the account's roles. Receives the role bitmap before and after the change, plus the bitmap that was passed to the grant call. `roleBitmap` is the request as made, so it may include roles the account already held; derive the actual change from `oldRoles` and `newRoles`. * **`_onRolesRevoked(resource, account, oldRoles, newRoles, roleBitmap)`**: the revoke counterpart, with the same semantics: `roleBitmap` is the requested revocation, which may include roles the account never held. Both are no-ops in the base implementation. The [Permissioned Registry](/ensv2/permissioned-registry) overrides these to [regenerate](/ensv2/mutable-token-ids#regeneration) ERC1155 tokens when roles change, invalidating stale transfer approvals. #### Grant/Revoke Restriction Hooks * **`_getSettableRoles(resource, account)`**: returns which roles the account is allowed to grant on a given resource. By default, an account can grant any role for which it holds the corresponding admin role. Contracts override this to impose additional restrictions. * **`_getRevokableRoles(resource, account)`**: returns which roles the account is allowed to revoke on a given resource. Same default behavior as settable roles. The [Permissioned Registry](/ensv2/permissioned-registry) overrides `_getSettableRoles` to prevent admin role escalation on individual names after registration. Role changes on unregistered or reserved names are blocked implicitly: the same override returns no settable roles when a name has no owner. ### Bitmap Layout Under the hood, roles are packed into a single `uint256` bitmap split into two halves. Each role occupies one nybble (4 bits), giving space for up to 32 regular roles and 32 corresponding admin roles: <MonoDiagram content={` 255 128 127 0\n ┌──────────────┬───────────────┐\n │ Admin Roles │ Regular Roles │\n └──────────────┴───────────────┘\n 63 32 31 0 ← nybble indices`} /> Each nybble is a 4-bit slot. A regular role at nybble index `N` occupies bits `4N` to `4N + 3`, so nybble 0 is bits 0–3, nybble 1 is bits 4–7, and so on. Its admin counterpart sits at the same position in the upper half (`4N + 128` to `4N + 131`). EAC tracks role assignments in two mappings: * **`_roles[resource][account]`**: stores which roles a given account holds on a given resource. Each nybble is either `0` (no role) or `1` (has role). * **`_roleCount[resource]`**: stores how many accounts hold each role on a given resource. Each nybble is a count from 0 to 15, using the same nybble-per-role layout. This is why the maximum number of assignees per role is 15: it's the largest value a 4-bit nybble can store. ### Replacing Fuses EAC replaces the one-way [fuse system](/wrapper/fuses) from the Name Wrapper. The key conceptual shift: in ENSv1, you **burned** permissions to restrict what could be done. In ENSv2, you **revoke** roles instead. Both achieve the same end result, but revoking is reversible if you hold the admin role. | Feature | ENSv1 Fuses | ENSv2 EAC | | ----------------- | ------------------------------ | ----------------------------------------------------------- | | Revocability | One-way burn — permanent | Reversible grant/revoke (while admin role is held) | | Delegation | Single owner only | Up to 15 accounts per role per resource | | Scope | Per-name only | Per-name or contract-wide via `ROOT_RESOURCE` | | Extensibility | Fixed set of 16 fuses | Each contract defines its own roles (up to 32) | | Transfer control | `CANNOT_TRANSFER` fuse | `ROLE_CAN_TRANSFER_ADMIN` (revoke to make non-transferable) | | Resolver control | `CANNOT_SET_RESOLVER` fuse | `ROLE_SET_RESOLVER` (revoke to lock resolver) | | Subdomain control | `CANNOT_CREATE_SUBDOMAIN` fuse | `ROLE_REGISTRAR` (revoke to prevent new subnames) | ### How Contracts Use EAC Each ENSv2 contract defines its own roles and its own resource scheme. See the EAC Permissions section on each contract page for details: * [Permissioned Registry: EAC Integration](/ensv2/permissioned-registry#eac-integration): 10 roles, labelhash-based resources with version isolation, anyId polymorphism * [Permissioned Resolver: EAC Integration](/ensv2/permissioned-resolver#eac-integration): 10 roles, scoped to the whole resolver or to individual keys, coin types, content types, or interface IDs ### Reference #### Write Functions <ContractReference functions={[ { name: 'grantRoles', description: 'Grant roles on a specific resource. Reverts if resource is ROOT_RESOURCE.', params: [ { name: 'resource', type: 'uint256', description: 'The resource to grant roles on' }, { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to grant' }, { name: 'account', type: 'address', description: 'Account to grant roles to' }, ], returns: [ { name: 'success', type: 'bool', description: 'Whether the roles were updated' }, ], }, { name: 'revokeRoles', description: 'Revoke roles on a specific resource. Reverts if resource is ROOT_RESOURCE.', params: [ { name: 'resource', type: 'uint256', description: 'The resource to revoke roles on' }, { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to revoke' }, { name: 'account', type: 'address', description: 'Account to revoke roles from' }, ], returns: [ { name: 'success', type: 'bool', description: 'Whether the roles were updated' }, ], }, { name: 'grantRootRoles', description: 'Grant roles on ROOT_RESOURCE (contract-wide).', params: [ { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to grant' }, { name: 'account', type: 'address', description: 'Account to grant roles to' }, ], returns: [ { name: 'success', type: 'bool', description: 'Whether the roles were updated' }, ], }, { name: 'revokeRootRoles', description: 'Revoke roles on ROOT_RESOURCE (contract-wide).', params: [ { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to revoke' }, { name: 'account', type: 'address', description: 'Account to revoke roles from' }, ], returns: [ { name: 'success', type: 'bool', description: 'Whether the roles were updated' }, ], }, ]} /> #### View Functions <ContractReference functions={[ { name: 'roles', description: 'Get the effective role bitmap for an account on a resource. Delegates to the internal _getRoles hook, so contracts that override _getRoles may return additional roles beyond those explicitly granted.', params: [ { name: 'resource', type: 'uint256', description: 'The resource to query' }, { name: 'account', type: 'address', description: 'The account to query' }, ], returns: [ { name: 'roleBitmap', type: 'uint256', description: 'Full role bitmap' }, ], }, { name: 'roleCount', description: 'Get the assignee count bitmap for a resource (nybble per role).', params: [ { name: 'resource', type: 'uint256', description: 'The resource to query' }, ], returns: [ { name: 'counts', type: 'uint256', description: 'Packed assignee counts' }, ], }, { name: 'hasRoles', description: 'Check whether an account has all specified roles. Checks both the resource and ROOT_RESOURCE.', params: [ { name: 'resource', type: 'uint256', description: 'The resource to check' }, { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to check' }, { name: 'account', type: 'address', description: 'The account to check' }, ], returns: [ { name: 'result', type: 'bool', description: 'True if account holds all specified roles' }, ], }, { name: 'hasRootRoles', description: 'Check whether an account has all specified roles on ROOT_RESOURCE only.', params: [ { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to check' }, { name: 'account', type: 'address', description: 'The account to check' }, ], returns: [ { name: 'result', type: 'bool', description: 'True if account holds all specified roles on ROOT' }, ], }, { name: 'hasAssignees', description: 'Check whether any accounts hold the specified roles on a resource.', params: [ { name: 'resource', type: 'uint256', description: 'The resource to check' }, { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to check' }, ], returns: [ { name: 'result', type: 'bool', description: 'True if any account holds the roles' }, ], }, { name: 'getAssigneeCount', description: 'Get per-role assignee counts for the specified roles.', params: [ { name: 'resource', type: 'uint256', description: 'The resource to query' }, { name: 'roleBitmap', type: 'uint256', description: 'Bitmap of roles to count' }, ], returns: [ { name: 'counts', type: 'uint256', description: 'Packed per-role assignee counts' }, { name: 'mask', type: 'uint256', description: 'Mask indicating which nybbles are relevant' }, ], }, ]} /> #### Constants <ContractReference functions={[ { name: 'ROOT_RESOURCE', description: 'The root resource constant (0). Roles on ROOT_RESOURCE apply to all resources.', }, ]} /> #### Events <ContractReference functions={[ { name: 'EACRolesChanged', description: 'Roles granted or revoked for an account on a resource.', params: [ { name: 'resource', type: 'uint256', indexed: true, description: 'The resource affected' }, { name: 'account', type: 'address', indexed: true, description: 'The account whose roles changed' }, { name: 'oldRoleBitmap', type: 'uint256', description: 'Previous role bitmap' }, { name: 'newRoleBitmap', type: 'uint256', description: 'New role bitmap' }, ], }, ]} /> For code examples of granting and revoking roles, see the [Permissioned Registry](/ensv2/permissioned-registry#code-examples) and [Permissioned Resolver](/ensv2/permissioned-resolver#code-examples) pages. ## ERC1155Singleton ENSv2 represents names as tokens using a modified ERC1155 implementation called **ERC1155Singleton**. Unlike standard ERC1155 where tokens can be fungible (multiple owners holding quantities of the same token), each ERC1155Singleton token has exactly one owner - combining the ownership semantics of ERC721 with the batching and interface compatibility of ERC1155. ### Why Not ERC721? ENSv1 used ERC721 for `.eth` names via the BaseRegistrar. ENSv2 switched to a modified ERC1155 for several reasons: * **Batch operations**: ERC1155 natively supports batch transfers and balance queries, which is useful when operating on multiple names at once * **Interface compatibility**: the ERC1155 interface is well-supported by wallets, marketplaces, and indexers * **Gas efficiency**: ERC1155Singleton removes the balance tracking overhead of standard ERC1155 while using a simpler approval model than the NameWrapper's hybrid per-token and operator approvals ### Key Differences from Standard ERC1155 | Feature | Standard ERC1155 | ERC1155Singleton | | ------------------------ | ------------------------------- | --------------------------------------- | | Tokens per ID | 0 to N (fungible) | 0 or 1 (singleton) | | `ownerOf(id)` | Not available | Returns the single owner | | `balanceOf(account, id)` | Returns quantity held | Returns `1` (owner) or `0` | | Balance tracking | Mapping of balances per account | Flat `id -> address` mapping | | Transfer value | Any amount | Must be exactly `1` (reverts otherwise) | ### Ownership Model ERC1155Singleton provides a simple ownership model: ```solidity // Returns the owner of a token, or address(0) if it doesn't exist function ownerOf(uint256 id) external view returns (address) // Returns 1 if `account` owns `id`, 0 otherwise function balanceOf(address account, uint256 id) external view returns (uint256) ``` Under the hood, ownership is stored in a flat mapping from token ID to owner address. There's no separate balance counter - `balanceOf` simply checks whether the queried account matches the stored owner. ### Gas Optimization The key gas saving comes from eliminating balance accounting. In a standard ERC1155, every transfer requires two storage writes: decrement the sender's balance and increment the receiver's balance. In ERC1155Singleton, a transfer is just a single storage write: updating the `id -> owner` mapping. This makes transfers noticeably cheaper. ### Integration with the Registry The [Permissioned Registry](/ensv2/permissioned-registry) inherits from ERC1155Singleton. Every registered name becomes a singleton token: * **Minting** happens when a name is registered via `register()` * **Burning** happens when a name is unregistered via `unregister()`, or when it expires and is re-registered * **Token regeneration** happens when roles change on a name - the old token is burned and a new one is minted to the same owner with a new ID (see [Mutable Token IDs](/ensv2/mutable-token-ids)) The singleton constraint means that standard ERC1155 operations like `safeTransferFrom` work as expected, but attempting to transfer a value greater than `1` will revert. Actual ENS registries specialize this further: [PermissionedRegistry](/ensv2/permissioned-registry#transfers) overrides the transfer logic with additional safeguards, so transfers on a deployed registry are more restricted than on this base contract. ### Marketplace Compatibility Because ERC1155Singleton implements the full `IERC1155` interface, names are compatible with standard NFT marketplaces and tools: * **Marketplaces** (OpenSea, Blur, etc.) can list and trade names * **Wallets** display names alongside other ERC1155 tokens * **Indexers** track ownership changes through standard `TransferSingle` and `TransferBatch` events One important caveat: because [token IDs can change](/ensv2/mutable-token-ids) when roles are updated, marketplace listings tied to an old token ID will become invalid. This is by design - it prevents an attack where a seller changes the name's permissions after listing it for sale. ### Interface `IERC1155Singleton` extends the standard `IERC1155` with a single addition, `ownerOf`, analogous to ERC721's function of the same name: ```solidity /// @dev Interface selector: 0x6352211e interface IERC1155Singleton is IERC1155 { /// Returns the owner of a token, or address(0) if it doesn't exist. function ownerOf(uint256 id) external view returns (address
프로젝트로 돌아가기