Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
ERC-5982 proposes a role-based access control mechanism for smart contracts.
This article translates, summarizes, and expands on the following proposal.
ERC-5982 was in Review status as of September 22, 2023.
Overview
The proposal defines a common approach to access control in Ethereum smart contracts. Access control determines which accounts are permitted to perform particular operations.
The proposal includes the following elements.
Roles
A role represents a group of accounts with particular permissions. Roles are identified by bytes32 values and can represent categories such as administrators or moderators.
Method selectors
A four-byte method selector (bytes4) identifies a contract function. A role's permissions can be associated with selectors to determine which operations members of that role may perform.
Granting and revoking permissions
The proposal defines ways to grant and revoke roles and manage their permissions. For example, assigning an administrator role to an account can enable it to perform restricted operations.
Role metadata
The proposal also defines interfaces for retrieving descriptive information about roles, making it easier for applications to present and manage them.
Together, these interfaces provide a common framework for restricting access to smart contract functionality. Security still depends on the implementation actually enforcing the relevant checks.
Motivation
Role-based access control is a common approach to protecting privileged operations. Each user can be assigned one or more roles, and those roles determine the operations the user is authorized to perform.
Roles
Roles represent groups of users, such as administrators or moderators. Each role can be associated with access to particular operations.
Granting and revoking access
Accounts can receive permissions by being assigned roles. An administrator, for example, may be authorized to perform sensitive operations. Permissions can also be revoked when they are no longer needed.
Principle of least privilege
Accounts should receive only the permissions needed to perform their responsibilities. Avoiding unnecessary privileges limits the potential impact of mistakes or compromised accounts.
Flexibility
Role assignments make it easier to add users or change existing permissions as an organization's requirements evolve.
These properties are useful for decentralized applications and smart contracts that need to restrict privileged operations while allowing permissions to be managed over time.
Specification
The interfaces are defined as follows.
IERC_ACL_CORE
interface IERC_ACL_CORE {
function hasRole(bytes32 role, address account) external view returns (bool);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
}hasRole(bytes32 role, address account)- Checks whether an account has the specified role.
grantRole(bytes32 role, address account)- Grants the specified role to an account.
revokeRole(bytes32 role, address account)- Revokes the specified role from an account.
IERC_ACL_GENERAL
interface IERC_ACL_GENERAL {
event RoleGranted(address indexed grantor, bytes32 indexed role, address indexed grantee, bytes _data);
event RoleRevoked(address indexed revoker, bytes32 indexed role, address indexed revokee, bytes _data);
event RoleCreated(address indexed roleGrantor, bytes32 role, bytes32 adminOfRole, string name, string desc, string uri, bytes32 calldata _data);
event RoleDestroyed(address indexed roleDestroyer, bytes32 role, bytes32 calldata _data);
event RolePowerSet(address indexed rolePowerSetter, bytes32 role, bytes4 methods, bytes calldata _data);
function grantRole(bytes32 role, address account, bytes calldata _data) external;
function revokeRole(bytes32 role, address account, bytes calldata _data) external;
function createRole(bytes32 role, bytes32 adminOfRole, string name, string desc, string uri, bytes32 calldata _data) external;
function destroyRole(bytes32 role, bytes32 calldata _data) external;
function setRolePower(bytes32 role, bytes4 methods, bytes calldata _data) view external returns(bool);
function hasRole(bytes32 role, address account, bytes calldata _data) external view returns (bool);
function canGrantRole(bytes32 grantor, bytes32 grantee, bytes calldata _data) view external returns(bool);
function canRevokeRole(bytes32 revoker, bytes32 revokee, address account, bytes calldata _data) view external returns(bool);
function canExecute(bytes32 executor, bytes4 methods, bytes32 calldata payload, bytes calldata _data) view external returns(bool);
}This interface provides additional role-management operations and events.
- Events
- Record role grants, revocations, creation, destruction, and changes to role permissions.
grantRole(bytes32 role, address account, bytes calldata _data)- Grants a role to an account with additional contextual data.
revokeRole(bytes32 role, address account, bytes calldata _data)- Revokes a role from an account with additional contextual data.
createRole(bytes32 role, bytes32 adminOfRole, string name, string desc, string uri, bytes32 calldata _data)- Creates a role with administrative and descriptive information.
destroyRole(bytes32 role, bytes32 calldata _data)- Destroys a role, with additional data as defined by the interface.
setRolePower(bytes32 role, bytes4 methods, bytes calldata _data)- Describes an operation for setting a role's permissions for particular methods.
The interface also exposes queries for role membership, granting or revoking roles, and execution permissions.
The declarations above reproduce the original article's code unchanged. Some declarations are not valid Solidity as written: for example, data locations are specified on value types or event parameters, and setRolePower is declared view despite its apparent state-changing purpose. Consult the authoritative specification and validate the interface before implementing it.
IERC_ACL_METADATA
interface IERC_ACL_METADATA {
function roleName(bytes32) external view returns(string);
function roleDescription(bytes32) external view returns(string);
function roleURI(bytes32) external view returns(string);
}This interface exposes descriptive information associated with roles.
roleName(bytes32)- Returns a role's name.
roleDescription(bytes32)- Returns a role's description.
roleURI(bytes32)- Returns a URI associated with the role.
Additional specification requirements
Implementing IERC_ACL_CORE
Contracts supporting the standard must implement the core interface, which includes operations for checking, granting, and revoking roles.
Implementing IERC_ACL_GENERAL
The general interface is recommended but optional. It provides additional operations and event tracking for more flexible access control.
Implementing IERC_ACL_METADATA
The metadata interface is optional. Implementations can expose role names, descriptions, and URIs when descriptive information is useful to consumers.
Representing roles as bytes32 values
Roles use bytes32 identifiers. Hashing role names with keccak256 is one way to derive deterministic identifiers with a negligible probability of accidental hash collisions. Applications must still manage naming conventions and avoid assigning the same identifier to different intended roles.
ERC-165 interface detection
ERC-165 interface detection is recommended to improve interoperability with contracts and tools. It allows a caller to discover which interfaces a contract supports.
Rationale
IERC_ACL_CORE method names and parameters
The core interface's method names and parameters were selected to maintain compatibility with OpenZeppelin's existing access control interface. This facilitates integration and reuse of existing code. Compatibility with individual implementations still depends on their behavior and authorization rules.
IERC_ACL_GENERAL and ERC-5750
The general interface follows the design conventions of ERC-5750, which describes extensibility through additional data parameters. These parameters allow implementations to introduce contextual information and additional behavior while retaining a shared interface.
Combining renounceRole and revokeRole
The proposal does not define a separate renounceRole operation. Instead, it combines role relinquishment with the revokeRole operation to simplify the interface.
Implementations must distinguish authorized revocation from unauthorized attempts to remove another account's role. The ability to relinquish one's own role should not be confused with authority to revoke roles belonging to others.
These design choices seek to simplify integration while allowing flexibility in how roles and permissions are managed.
Backward compatibility
The version of the proposal discussed in the original article leaves backward compatibility open for discussion.
Security considerations
The original article notes that security considerations require further discussion. Role administration, authorization checks, permission changes, and administrative recovery should be evaluated independently in any concrete implementation.
Citation
Zainan Victor Zhou (@xinbenlv), "ERC-5982: Role-based Access Control [DRAFT]," Ethereum Improvement Proposals, no. 5982, November 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5982.
Conclusion
ERC-5982 proposes core, general, and metadata interfaces for managing role-based access control in smart contracts.
Questions are welcome via Twitter @cardene777.
Other publications:


