Overview
TheRegistryRolesLib library defines the role constants and admin role mappings used by the ENS v2 Registry contract. Each role is represented as a bit position in a uint256 bitmap, enabling efficient storage and permission checks.
Role Organization
Roles are organized by their scope:- Root-only roles: Can only be granted/used in
ROOT_RESOURCE(resource ID 0) - Root or token roles: Can be granted in either
ROOT_RESOURCEor specific name token resources - Token-only roles: Can only be granted for specific name token resources
Role Constants
ROLE_REGISTRAR
Scope: Root-only
Permissions: Allows registering new names in the registry This role is restricted to the root resource level only. Accounts with this role can register new top-level or subdomains depending on the registry configuration.
ROLE_REGISTRAR_ADMIN
Scope: Root-only
Permissions: Can grant and revoke
ROLE_REGISTRAR
The admin role for ROLE_REGISTRAR. Accounts with this role can manage who has registration privileges.
ROLE_REGISTER_RESERVED
Scope: Root-only
Permissions: Allows registering reserved names This role grants the ability to register names that are marked as reserved in the system. Reserved names typically include premium names or names with special restrictions.
ROLE_REGISTER_RESERVED_ADMIN
Scope: Root-only
Permissions: Can grant and revoke
ROLE_REGISTER_RESERVED
ROLE_SET_PARENT
Scope: Root-only
Permissions: Allows setting the parent relationship for names This role enables modifying the hierarchical parent-child relationships between names in the registry.
ROLE_SET_PARENT_ADMIN
Scope: Root-only
Permissions: Can grant and revoke
ROLE_SET_PARENT
ROLE_UNREGISTER
Scope: Root or token
Permissions: Allows unregistering names This role can be granted either globally (in
ROOT_RESOURCE) or for specific name tokens. When granted for a specific name, the holder can only unregister that particular name.
ROLE_UNREGISTER_ADMIN
Scope: Root or token
Permissions: Can grant and revoke
ROLE_UNREGISTER
ROLE_RENEW
Scope: Root or token
Permissions: Allows renewing name registrations Accounts with this role can extend the expiration time of registered names. Can be granted globally or per-name.
ROLE_RENEW_ADMIN
Scope: Root or token
Permissions: Can grant and revoke
ROLE_RENEW
ROLE_SET_SUBREGISTRY
Scope: Root or token
Permissions: Allows setting a subregistry for a name This role enables designating a name as a subregistry, allowing it to have its own registration rules and controllers.
ROLE_SET_SUBREGISTRY_ADMIN
Scope: Root or token
Permissions: Can grant and revoke
ROLE_SET_SUBREGISTRY
ROLE_SET_RESOLVER
Scope: Root or token
Permissions: Allows setting the resolver contract for a name This role grants permission to update which resolver contract is responsible for resolving a name to its associated data (addresses, content hashes, etc.).
ROLE_SET_RESOLVER_ADMIN
Scope: Root or token
Permissions: Can grant and revoke
ROLE_SET_RESOLVER
ROLE_CAN_TRANSFER_ADMIN
Scope: Token-only
Permissions: Can grant and revoke the ability to transfer a name token Note: This is an admin-only role (no corresponding regular role at bit 28). It controls whether a name token can be transferred. This provides fine-grained control over name transferability on a per-name basis.
ROLE_UPGRADE
Scope: Root-only
Permissions: Allows upgrading the registry contract This is a highly privileged role that permits upgrading the registry contract implementation. Should be carefully controlled.
ROLE_UPGRADE_ADMIN
Scope: Root-only
Permissions: Can grant and revoke
ROLE_UPGRADE
Role Hierarchy
The admin role system creates a hierarchical permission structure: An account with an admin role can:- Grant the corresponding regular role to other accounts
- Revoke the corresponding regular role from other accounts
- Grant the admin role itself to other accounts (if they hold that admin role)
Usage Examples
Checking a Single Role
Checking Multiple Roles
Granting a Role
Granting Resource-Specific Roles
Setting Up Initial Permissions
Delegating Name-Specific Permissions
Transfer Control Example
Checking Admin Capabilities
Role Bitmap Layout
The role bitmap is structured as follows:ROLE_REGISTRAR= bit 0 (value:0x1)ROLE_REGISTRAR_ADMIN= bit 128 (value:0x100000000000000000000000000000000)
Best Practices
1. Principle of Least Privilege
Only grant the minimum roles necessary for an account to perform its function:2. Separate Admin Accounts
Keep admin roles on separate, more secure accounts:3. Use Resource-Specific Roles When Possible
Prefer granting roles for specific resources rather than globally:4. Role Combination for Complex Permissions
Combine roles for accounts that need multiple permissions:5. Audit Role Assignments
Regularly check who has critical roles:Role Scope Reference
| Role | Bit Position | Scope | Description |
|---|---|---|---|
ROLE_REGISTRAR | 0 | Root-only | Register new names |
ROLE_REGISTRAR_ADMIN | 128 | Root-only | Manage registrar role |
ROLE_REGISTER_RESERVED | 4 | Root-only | Register reserved names |
ROLE_REGISTER_RESERVED_ADMIN | 132 | Root-only | Manage reserved registration role |
ROLE_SET_PARENT | 8 | Root-only | Set parent relationships |
ROLE_SET_PARENT_ADMIN | 136 | Root-only | Manage parent role |
ROLE_UNREGISTER | 12 | Root or token | Unregister names |
ROLE_UNREGISTER_ADMIN | 140 | Root or token | Manage unregister role |
ROLE_RENEW | 16 | Root or token | Renew registrations |
ROLE_RENEW_ADMIN | 144 | Root or token | Manage renew role |
ROLE_SET_SUBREGISTRY | 20 | Root or token | Set subregistries |
ROLE_SET_SUBREGISTRY_ADMIN | 148 | Root or token | Manage subregistry role |
ROLE_SET_RESOLVER | 24 | Root or token | Set resolver contracts |
ROLE_SET_RESOLVER_ADMIN | 152 | Root or token | Manage resolver role |
ROLE_CAN_TRANSFER_ADMIN | 156 | Token-only | Control transfer ability |
ROLE_UPGRADE | 124 | Root-only | Upgrade registry |
ROLE_UPGRADE_ADMIN | 252 | Root-only | Manage upgrade role |
See Also
- EnhancedAccessControl - Base access control contract
- Source:
contracts/src/registry/libraries/RegistryRolesLib.sol:4