{"eip":5982,"title":"Role-based Access Control","description":"An interface for role-based access control for smart contracts.","authors":["Zainan Victor Zhou (@xinbenlv)"],"status":"Review","type":"Standards Track","category":"ERC","created":"2022-11-15","requires":[165,5750],"discussionsTo":"https://ethereum-magicians.org/t/eip-5982-role-based-access-control/11759","repo":"ERCs","label":"ERC-5982","officialUrl":"https://eips.ethereum.org/EIPS/eip-5982","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5982.md","url":"https://eips.huatuo.xyz/eip-5982/","tldr":{"en":"A standard interface for role-based access control, where bytes32 roles are granted to addresses and checked before privileged functions run.","ja":"ロールベースのアクセス制御の標準インターフェース。bytes32 のロールをアドレスに付与し、特権関数を実行する前にチェックする。","ko":"역할 기반 접근 제어를 위한 표준 인터페이스. bytes32 역할을 주소에 부여하고, 권한이 필요한 함수를 실행하기 전에 확인한다.","zh":"基于角色的访问控制的标准接口：bytes32 角色被授予地址，并在执行特权函数之前进行检查。"},"tags":["access-control","roles","security","interface"],"explainers":{"en":{"lang":"en","tldr":"A standard interface for role-based access control, where bytes32 roles are granted to addresses and checked before privileged functions run.","tags":["access-control","roles","security","interface"],"related":[165,5750],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5982/","markdown":"## What problem does it solve?\n\nMany contracts gate sensitive functions (mint, pause, upgrade) behind a single `owner`. That is simple but fragile: one key does everything, and you cannot give a bot permission to mint without also giving it permission to upgrade.\n\nRole-based access control (RBAC) assigns addresses to named roles, each allowed to do only certain things, following the principle of least privilege. The pattern is already common (OpenZeppelin's `AccessControl`), but there was no ERC describing it so tools could detect and manage roles across contracts. ERC-5982 proposes that interface, deliberately compatible with OpenZeppelin's method names.\n\n## How it works\n\nA role is a `bytes32`, recommended to be `keccak256(\"\u003cROLE_NAME\u003e\")`, for example `keccak256(\"MINTER\")`.\n\nThe spec has three layers:\n\n- **`IERC_ACL_CORE` (required):** `hasRole(role, account)`, `grantRole(role, account)`, `revokeRole(role, account)`.\n- **`IERC_ACL_GENERAL` (recommended):** versions of those calls with an extra `bytes _data` argument (following [ERC-5750](/eip-5750/)), plus `createRole`, `destroyRole`, `setRolePower` to bind a role to function selectors (`bytes4`), and `canGrantRole` / `canRevokeRole` / `canExecute` checks. Matching events (`RoleGranted`, `RoleRevoked`, `RoleCreated`, …) record changes.\n- **`IERC_ACL_METADATA` (optional):** `roleName`, `roleDescription`, `roleURI` for human-readable role information.\n\nContracts should advertise support through [ERC-165](/eip-165/). Unlike OpenZeppelin, there is no separate `renounceRole`; that case is folded into `revokeRole`.\n\n## Sample code\n\nA minimal contract implementing the core interface:\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IERC_ACL_CORE {\n    function hasRole(bytes32 role, address account) external view returns (bool);\n    function grantRole(bytes32 role, address account) external;\n    function revokeRole(bytes32 role, address account) external;\n}\n\ncontract RoleGated is IERC_ACL_CORE {\n    bytes32 public constant ADMIN  = keccak256(\"ADMIN\");\n    bytes32 public constant MINTER = keccak256(\"MINTER\");\n    mapping(bytes32 =\u003e mapping(address =\u003e bool)) private _roles;\n\n    constructor() { _roles[ADMIN][msg.sender] = true; }\n\n    modifier only(bytes32 role) {\n        require(_roles[role][msg.sender], \"missing role\");\n        _;\n    }\n\n    function hasRole(bytes32 role, address a) external view returns (bool) { return _roles[role][a]; }\n    function grantRole(bytes32 role, address a) external only(ADMIN) { _roles[role][a] = true; }\n    function revokeRole(bytes32 role, address a) external {\n        require(_roles[ADMIN][msg.sender] || a == msg.sender, \"not allowed\"); // self-revoke allowed\n        _roles[role][a] = false;\n    }\n\n    function mint(address to, uint256 amount) external only(MINTER) { /* ... */ }\n}\n```\n\n## Things to know\n\n- **Status: Review.** The interface may still change. Its Backwards Compatibility and Security Considerations sections still read \"Needs discussion\".\n- The core interface matches OpenZeppelin's `AccessControl` function signatures, so existing OZ-based contracts already expose the required methods.\n- The general extension's code in the spec has some rough edges (e.g. `bytes32 calldata` parameters and a `view` setter), so treat it as a sketch rather than copy-paste Solidity.\n- Whoever administers roles is now your critical key. Protect admin roles with a multisig or timelock.\n"},"ja":{"lang":"ja","tldr":"ロールベースのアクセス制御の標準インターフェース。bytes32 のロールをアドレスに付与し、特権関数を実行する前にチェックする。","tags":["access-control","roles","security","interface"],"related":[165,5750],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5982/","markdown":"## 何を解決するのか\n\n多くのコントラクトは、機微な関数（mint、pause、upgrade）を単一の `owner` の背後に置いています。単純ですが脆弱です。1 つの鍵がすべてを行い、ボットに mint の権限だけを与えて upgrade の権限は与えない、ということもできません。\n\nロールベースのアクセス制御（RBAC）は、アドレスを名前付きのロールに割り当て、各ロールには特定のことだけを許可します。最小権限の原則に沿ったものです。このパターンは既に一般的（OpenZeppelin の `AccessControl`）ですが、ツールがコントラクトをまたいでロールを検出・管理できるようにそれを記述した ERC はありませんでした。ERC-5982 はそのインターフェースを提案し、OpenZeppelin のメソッド名と意図的に互換にしています。\n\n## 仕組み\n\nロールは `bytes32` で、`keccak256(\"\u003cROLE_NAME\u003e\")`（たとえば `keccak256(\"MINTER\")`）とすることが推奨されます。\n\n仕様には 3 つの層があります。\n\n- **`IERC_ACL_CORE`（必須）:** `hasRole(role, account)`、`grantRole(role, account)`、`revokeRole(role, account)`。\n- **`IERC_ACL_GENERAL`（推奨）:** それらの呼び出しに、追加の `bytes _data` 引数（[ERC-5750](/eip-5750/) に従う）を付けたバージョン。加えて `createRole`、`destroyRole`、ロールを関数セレクター（`bytes4`）に結びつける `setRolePower`、そして `canGrantRole` / `canRevokeRole` / `canExecute` のチェック。対応するイベント（`RoleGranted`、`RoleRevoked`、`RoleCreated` など）が変更を記録します。\n- **`IERC_ACL_METADATA`（任意）:** 人が読めるロール情報のための `roleName`、`roleDescription`、`roleURI`。\n\nコントラクトは [ERC-165](/eip-165/) を通じてサポートを通知すべきです。OpenZeppelin とは異なり、独立した `renounceRole` はありません。そのケースは `revokeRole` に統合されています。\n\n## サンプルコード\n\nコアインターフェースを実装する最小のコントラクト:\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IERC_ACL_CORE {\n    function hasRole(bytes32 role, address account) external view returns (bool);\n    function grantRole(bytes32 role, address account) external;\n    function revokeRole(bytes32 role, address account) external;\n}\n\ncontract RoleGated is IERC_ACL_CORE {\n    bytes32 public constant ADMIN  = keccak256(\"ADMIN\");\n    bytes32 public constant MINTER = keccak256(\"MINTER\");\n    mapping(bytes32 =\u003e mapping(address =\u003e bool)) private _roles;\n\n    constructor() { _roles[ADMIN][msg.sender] = true; }\n\n    modifier only(bytes32 role) {\n        require(_roles[role][msg.sender], \"missing role\");\n        _;\n    }\n\n    function hasRole(bytes32 role, address a) external view returns (bool) { return _roles[role][a]; }\n    function grantRole(bytes32 role, address a) external only(ADMIN) { _roles[role][a] = true; }\n    function revokeRole(bytes32 role, address a) external {\n        require(_roles[ADMIN][msg.sender] || a == msg.sender, \"not allowed\"); // self-revoke allowed\n        _roles[role][a] = false;\n    }\n\n    function mint(address to, uint256 amount) external only(MINTER) { /* ... */ }\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Review。** インターフェースはまだ変わる可能性があります。Backwards Compatibility と Security Considerations の節は、今も「Needs discussion」のままです。\n- コアインターフェースは OpenZeppelin の `AccessControl` の関数シグネチャと一致するため、OZ ベースの既存のコントラクトは、必要なメソッドをすでに公開しています。\n- 仕様にある general 拡張のコードには粗い部分があるので（たとえば `bytes32 calldata` のパラメータや `view` のセッター）、コピー＆ペーストできる Solidity ではなく、スケッチとして扱ってください。\n- ロールを管理する人が、あなたの重要な鍵になります。管理者ロールはマルチシグまたはタイムロックで保護してください。\n"},"ko":{"lang":"ko","tldr":"역할 기반 접근 제어를 위한 표준 인터페이스. bytes32 역할을 주소에 부여하고, 권한이 필요한 함수를 실행하기 전에 확인한다.","tags":["access-control","roles","security","interface"],"related":[165,5750],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5982/","markdown":"## 어떤 문제를 해결하나요?\n\n많은 컨트랙트가 민감한 함수(mint, pause, upgrade)를 단일 `owner` 뒤에 둡니다. 단순하지만 취약합니다. 키 하나가 모든 것을 하고, 봇에게 mint 권한만 주고 upgrade 권한은 주지 않을 수도 없습니다.\n\n역할 기반 접근 제어(RBAC)는 주소를 이름 있는 역할에 할당하고, 각 역할에는 특정한 일만 허용합니다. 최소 권한 원칙을 따르는 것입니다. 이 패턴은 이미 흔하지만(OpenZeppelin의 `AccessControl`), 도구가 컨트랙트를 가로질러 역할을 감지하고 관리할 수 있도록 이를 기술한 ERC는 없었습니다. ERC-5982는 그 인터페이스를 제안하며, OpenZeppelin의 메서드 이름과 의도적으로 호환되게 만들었습니다.\n\n## 어떻게 동작하나요?\n\n역할은 `bytes32`이며, `keccak256(\"\u003cROLE_NAME\u003e\")`(예: `keccak256(\"MINTER\")`)으로 정하는 것을 권장합니다.\n\n명세는 세 계층으로 되어 있습니다.\n\n- **`IERC_ACL_CORE`(필수):** `hasRole(role, account)`, `grantRole(role, account)`, `revokeRole(role, account)`.\n- **`IERC_ACL_GENERAL`(권장):** 위 호출에 추가 `bytes _data` 인자를 붙인 버전([ERC-5750](/eip-5750/)을 따름), 그리고 `createRole`, `destroyRole`, 역할을 함수 셀렉터(`bytes4`)에 묶는 `setRolePower`, `canGrantRole` / `canRevokeRole` / `canExecute` 확인 함수. 대응하는 이벤트(`RoleGranted`, `RoleRevoked`, `RoleCreated` 등)가 변경을 기록합니다.\n- **`IERC_ACL_METADATA`(선택):** 사람이 읽을 수 있는 역할 정보를 위한 `roleName`, `roleDescription`, `roleURI`.\n\n컨트랙트는 [ERC-165](/eip-165/)를 통해 지원 여부를 알려야 합니다. OpenZeppelin과 달리 별도의 `renounceRole`은 없으며, 그 경우는 `revokeRole`에 통합되어 있습니다.\n\n## 샘플 코드\n\n코어 인터페이스를 구현하는 최소한의 컨트랙트:\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IERC_ACL_CORE {\n    function hasRole(bytes32 role, address account) external view returns (bool);\n    function grantRole(bytes32 role, address account) external;\n    function revokeRole(bytes32 role, address account) external;\n}\n\ncontract RoleGated is IERC_ACL_CORE {\n    bytes32 public constant ADMIN  = keccak256(\"ADMIN\");\n    bytes32 public constant MINTER = keccak256(\"MINTER\");\n    mapping(bytes32 =\u003e mapping(address =\u003e bool)) private _roles;\n\n    constructor() { _roles[ADMIN][msg.sender] = true; }\n\n    modifier only(bytes32 role) {\n        require(_roles[role][msg.sender], \"missing role\");\n        _;\n    }\n\n    function hasRole(bytes32 role, address a) external view returns (bool) { return _roles[role][a]; }\n    function grantRole(bytes32 role, address a) external only(ADMIN) { _roles[role][a] = true; }\n    function revokeRole(bytes32 role, address a) external {\n        require(_roles[ADMIN][msg.sender] || a == msg.sender, \"not allowed\"); // self-revoke allowed\n        _roles[role][a] = false;\n    }\n\n    function mint(address to, uint256 amount) external only(MINTER) { /* ... */ }\n}\n```\n\n## 알아둘 점\n\n- **상태: Review.** 인터페이스가 아직 바뀔 수 있습니다. Backwards Compatibility와 Security Considerations 항목은 아직 \"Needs discussion\"으로 되어 있습니다.\n- 코어 인터페이스는 OpenZeppelin `AccessControl`의 함수 시그니처와 일치하므로, 기존 OZ 기반 컨트랙트는 이미 필요한 메서드를 노출하고 있습니다.\n- 명세에 있는 general 확장의 코드에는 거친 부분이 있으므로(예: `bytes32 calldata` 매개변수와 `view` 세터), 복사해서 붙여 넣을 수 있는 Solidity가 아니라 스케치로 취급하세요.\n- 역할을 관리하는 쪽이 이제 여러분의 핵심 키입니다. 관리자 역할은 멀티시그나 타임락으로 보호하세요.\n"},"zh":{"lang":"zh","tldr":"基于角色的访问控制的标准接口：bytes32 角色被授予地址，并在执行特权函数之前进行检查。","tags":["access-control","roles","security","interface"],"related":[165,5750],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5982/","markdown":"## 它解决什么问题？\n\n许多合约把敏感函数（mint、pause、upgrade）放在单一的 `owner` 之后。这很简单，但很脆弱：一把密钥什么都能做，你也无法只授权某个机器人 mint，而不同时授权它 upgrade。\n\n基于角色的访问控制（RBAC）把地址分配给具名角色，每个角色只能做特定的事，遵循最小权限原则。这种模式已经很常见（OpenZeppelin 的 `AccessControl`），但此前没有 ERC 来描述它，使工具能够跨合约检测和管理角色。ERC-5982 提出了这个接口，并有意与 OpenZeppelin 的方法名保持兼容。\n\n## 它如何运作\n\n角色是一个 `bytes32`，推荐使用 `keccak256(\"\u003cROLE_NAME\u003e\")`，例如 `keccak256(\"MINTER\")`。\n\n规范分为三层：\n\n- **`IERC_ACL_CORE`（必需）：** `hasRole(role, account)`、`grantRole(role, account)`、`revokeRole(role, account)`。\n- **`IERC_ACL_GENERAL`（推荐）：** 上述调用的、带额外 `bytes _data` 参数的版本（遵循 [ERC-5750](/eip-5750/)），外加 `createRole`、`destroyRole`、把角色绑定到函数选择器（`bytes4`）的 `setRolePower`，以及 `canGrantRole` / `canRevokeRole` / `canExecute` 检查。对应的事件（`RoleGranted`、`RoleRevoked`、`RoleCreated` 等）记录变更。\n- **`IERC_ACL_METADATA`（可选）：** 用于提供人类可读角色信息的 `roleName`、`roleDescription`、`roleURI`。\n\n合约应通过 [ERC-165](/eip-165/) 声明支持。与 OpenZeppelin 不同，这里没有单独的 `renounceRole`；该情形已并入 `revokeRole`。\n\n## 示例代码\n\n一个实现核心接口的最小合约：\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IERC_ACL_CORE {\n    function hasRole(bytes32 role, address account) external view returns (bool);\n    function grantRole(bytes32 role, address account) external;\n    function revokeRole(bytes32 role, address account) external;\n}\n\ncontract RoleGated is IERC_ACL_CORE {\n    bytes32 public constant ADMIN  = keccak256(\"ADMIN\");\n    bytes32 public constant MINTER = keccak256(\"MINTER\");\n    mapping(bytes32 =\u003e mapping(address =\u003e bool)) private _roles;\n\n    constructor() { _roles[ADMIN][msg.sender] = true; }\n\n    modifier only(bytes32 role) {\n        require(_roles[role][msg.sender], \"missing role\");\n        _;\n    }\n\n    function hasRole(bytes32 role, address a) external view returns (bool) { return _roles[role][a]; }\n    function grantRole(bytes32 role, address a) external only(ADMIN) { _roles[role][a] = true; }\n    function revokeRole(bytes32 role, address a) external {\n        require(_roles[ADMIN][msg.sender] || a == msg.sender, \"not allowed\"); // self-revoke allowed\n        _roles[role][a] = false;\n    }\n\n    function mint(address to, uint256 amount) external only(MINTER) { /* ... */ }\n}\n```\n\n## 需要注意\n\n- **状态：Review。** 接口仍可能变化。其 Backwards Compatibility 和 Security Considerations 部分仍写着\"Needs discussion\"。\n- 核心接口与 OpenZeppelin 的 `AccessControl` 函数签名一致，因此现有基于 OZ 的合约已经公开了所需的方法。\n- 规范中 general 扩展的代码有一些粗糙之处（例如 `bytes32 calldata` 参数和一个 `view` 的 setter），因此请把它当作草图，而不是可以直接复制粘贴的 Solidity。\n- 管理角色的人现在成了你的关键密钥。请用多签或时间锁保护管理员角色。\n"}}}
