{"eip":6617,"title":"Bit Based Permission","description":"A permission and role system based on bits","authors":["Chiro (@chiro-hiro)","Victor Dusart (@vdusart)"],"status":"Review","type":"Standards Track","category":"ERC","created":"2023-02-27","discussionsTo":"https://ethereum-magicians.org/t/bit-based-permission/13065","repo":"ERCs","label":"ERC-6617","officialUrl":"https://eips.ethereum.org/EIPS/eip-6617","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6617.md","url":"https://eips.huatuo.xyz/eip-6617/","tldr":{"en":"A minimal access-control standard where each permission is one bit of a uint256, so roles are just bitmasks and permission checks cost a single AND.","ja":"各権限を uint256 の 1 ビットで表す最小限のアクセス制御標準。ロールは単なるビットマスクとなり、権限チェックは AND 1 回で済む。","ko":"각 권한을 uint256의 비트 하나로 표현하는 최소한의 접근 제어 표준. 역할은 단순한 비트마스크이고, 권한 확인은 AND 한 번으로 끝난다.","zh":"一种极简的访问控制标准：每个权限是 uint256 中的一个比特位，角色就是位掩码，权限检查只需一次 AND 运算。"},"tags":["access-control","permissions","roles","solidity"],"explainers":{"en":{"lang":"en","tldr":"A minimal access-control standard where each permission is one bit of a uint256, so roles are just bitmasks and permission checks cost a single AND.","tags":["access-control","permissions","roles","solidity"],"related":[173,5982],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-6617/","markdown":"## What problem does it solve?\n\nMost contracts do access control with a single owner ([ERC-173](/eip-173/)) or with named `bytes32` roles ([ERC-5982](/eip-5982/)). A single owner is too coarse, and role mappings need a storage read per role you want to check.\n\nERC-6617 packs permissions into bits. A user's whole permission set is one `uint256`, so checking \"does this user have permissions A and B?\" is a bitwise `AND` against one stored value.\n\n## How it works\n\n- Each **permission** is a power of two (exactly one bit set). Every permission is unique, and `0` means \"no permission\". That gives up to 256 permissions.\n- A **role** is any OR-combination of permissions, so there are up to 2^256 possible roles, and they don't need to be predefined.\n- Bit position can encode importance: put the most important permission in the most significant bit, and permissions can be compared as integers.\n- Required interface `IEIP6617`:\n  - `hasPermission(user, required)` returns true if the user's bits are a superset of `required`.\n  - `grantPermission(user, perm)` and `revokePermission(user, perm)` return `bool`.\n  - Events `PermissionGranted` and `PermissionRevoked` must be emitted.\n- Optional (recommended) `IEIP6617Meta` attaches a name and description to base permissions and main combinations, since bits alone are not self-describing.\n\nWho may grant or revoke is left to the implementation.\n\n## Sample code\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ncontract BitPermissions {\n    uint256 public constant MINT   = 1 \u003c\u003c 0;\n    uint256 public constant PAUSE  = 1 \u003c\u003c 1;\n    uint256 public constant ADMIN  = 1 \u003c\u003c 255;      // most important = highest bit\n    uint256 public constant MINTER_PAUSER = MINT | PAUSE; // a role\n\n    mapping(address =\u003e uint256) private _perm;\n\n    event PermissionGranted(address indexed _grantor, uint256 indexed _permission, address indexed _user);\n    event PermissionRevoked(address indexed _revoker, uint256 indexed _permission, address indexed _user);\n\n    constructor() { _perm[msg.sender] = ADMIN; }\n\n    modifier only(uint256 required) {\n        require(hasPermission(msg.sender, required), \"forbidden\");\n        _;\n    }\n\n    function hasPermission(address user, uint256 required) public view returns (bool) {\n        return _perm[user] \u0026 required == required;\n    }\n\n    function grantPermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] |= p;\n        emit PermissionGranted(msg.sender, p, user);\n        return true;\n    }\n\n    function revokePermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] \u0026= ~p;\n        emit PermissionRevoked(msg.sender, p, user);\n        return true;\n    }\n}\n```\n\n## Things to know\n\n- Status is **Review**; details may still change before it is finalized.\n- 256 permissions per contract is a hard ceiling, and bit meanings are fixed in code. Changing what bit 3 means later is effectively a migration.\n- Bitmasks are opaque to humans and block explorers. The metadata extension helps, but tooling support is far thinner than for OpenZeppelin-style `AccessControl` roles.\n- Watch out for `hasPermission(user, 0)`: with the superset rule it is always true, so never use an unset constant as a guard.\n"},"ja":{"lang":"ja","tldr":"各権限を uint256 の 1 ビットで表す最小限のアクセス制御標準。ロールは単なるビットマスクとなり、権限チェックは AND 1 回で済む。","tags":["access-control","permissions","roles","solidity"],"related":[173,5982],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-6617/","markdown":"## 何を解決するのか\n\n多くのコントラクトは、単一のオーナー（[ERC-173](/eip-173/)）か、名前付きの `bytes32` ロール（[ERC-5982](/eip-5982/)）でアクセス制御を行います。単一のオーナーでは粒度が粗すぎ、ロールのマッピングは確認したいロールごとにストレージ読み取りが必要です。\n\nERC-6617 は権限をビットに詰め込みます。ユーザーの権限セット全体が 1 つの `uint256` なので、「このユーザーは権限 A と B を持っているか？」の確認は、保存された 1 つの値に対するビット単位の `AND` で済みます。\n\n## 仕組み\n\n- 各**権限**は 2 のべき乗（ちょうど 1 ビットだけが立っている）です。すべての権限は一意で、`0` は「権限なし」を意味します。これにより最大 256 個の権限を持てます。\n- **ロール**は権限の任意の OR 結合で、最大 2^256 通りのロールが可能です。事前に定義しておく必要はありません。\n- ビット位置で重要度を表現できます。最も重要な権限を最上位ビットに置けば、権限を整数として比較できます。\n- 必須インターフェース `IEIP6617`:\n  - `hasPermission(user, required)` は、ユーザーのビットが `required` の上位集合であれば true を返します。\n  - `grantPermission(user, perm)` と `revokePermission(user, perm)` は `bool` を返します。\n  - イベント `PermissionGranted` と `PermissionRevoked` を発行しなければなりません。\n- 任意（推奨）の `IEIP6617Meta` は、ビットだけでは意味が分からないため、基本の権限と主な組み合わせに名前と説明を付与します。\n\n誰が付与・剥奪できるかは実装に委ねられています。\n\n## サンプルコード\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ncontract BitPermissions {\n    uint256 public constant MINT   = 1 \u003c\u003c 0;\n    uint256 public constant PAUSE  = 1 \u003c\u003c 1;\n    uint256 public constant ADMIN  = 1 \u003c\u003c 255;      // most important = highest bit\n    uint256 public constant MINTER_PAUSER = MINT | PAUSE; // a role\n\n    mapping(address =\u003e uint256) private _perm;\n\n    event PermissionGranted(address indexed _grantor, uint256 indexed _permission, address indexed _user);\n    event PermissionRevoked(address indexed _revoker, uint256 indexed _permission, address indexed _user);\n\n    constructor() { _perm[msg.sender] = ADMIN; }\n\n    modifier only(uint256 required) {\n        require(hasPermission(msg.sender, required), \"forbidden\");\n        _;\n    }\n\n    function hasPermission(address user, uint256 required) public view returns (bool) {\n        return _perm[user] \u0026 required == required;\n    }\n\n    function grantPermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] |= p;\n        emit PermissionGranted(msg.sender, p, user);\n        return true;\n    }\n\n    function revokePermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] \u0026= ~p;\n        emit PermissionRevoked(msg.sender, p, user);\n        return true;\n    }\n}\n```\n\n## 知っておくべきこと\n\n- ステータスは **Review** です。確定するまでに詳細が変わる可能性があります。\n- コントラクトあたり 256 権限が上限で、ビットの意味はコード内で固定されます。後からビット 3 の意味を変えることは、事実上マイグレーションになります。\n- ビットマスクは人間やブロックエクスプローラーには読み取りにくいものです。メタデータ拡張が助けになりますが、OpenZeppelin 形式の `AccessControl` ロールに比べるとツールの対応ははるかに乏しい状況です。\n- `hasPermission(user, 0)` に注意してください。上位集合のルールにより常に true になるため、未設定の定数をガードに使ってはいけません。\n"},"ko":{"lang":"ko","tldr":"각 권한을 uint256의 비트 하나로 표현하는 최소한의 접근 제어 표준. 역할은 단순한 비트마스크이고, 권한 확인은 AND 한 번으로 끝난다.","tags":["access-control","permissions","roles","solidity"],"related":[173,5982],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-6617/","markdown":"## 어떤 문제를 해결하나요?\n\n대부분의 컨트랙트는 단일 오너([ERC-173](/eip-173/))나 이름 있는 `bytes32` 역할([ERC-5982](/eip-5982/))로 접근 제어를 합니다. 단일 오너는 너무 거칠고, 역할 매핑은 확인하려는 역할마다 스토리지 읽기가 필요합니다.\n\nERC-6617은 권한을 비트에 담습니다. 사용자의 전체 권한 집합이 `uint256` 하나이므로, \"이 사용자가 권한 A와 B를 모두 가지고 있는가?\"는 저장된 값 하나에 대한 비트 `AND`로 확인할 수 있습니다.\n\n## 어떻게 동작하나요?\n\n- 각 **권한**은 2의 거듭제곱(정확히 한 비트만 설정됨)입니다. 모든 권한은 고유하며 `0`은 \"권한 없음\"을 뜻합니다. 따라서 최대 256개의 권한을 가질 수 있습니다.\n- **역할**은 권한의 임의의 OR 조합이므로 최대 2^256가지 역할이 가능하며, 미리 정의할 필요가 없습니다.\n- 비트 위치로 중요도를 표현할 수 있습니다. 가장 중요한 권한을 최상위 비트에 두면 권한을 정수로 비교할 수 있습니다.\n- 필수 인터페이스 `IEIP6617`:\n  - `hasPermission(user, required)`는 사용자의 비트가 `required`의 상위 집합이면 true를 반환합니다.\n  - `grantPermission(user, perm)`과 `revokePermission(user, perm)`은 `bool`을 반환합니다.\n  - `PermissionGranted`와 `PermissionRevoked` 이벤트를 반드시 발생시켜야 합니다.\n- 선택(권장) 사항인 `IEIP6617Meta`는 비트만으로는 의미를 알 수 없으므로 기본 권한과 주요 조합에 이름과 설명을 붙입니다.\n\n누가 부여하거나 회수할 수 있는지는 구현에 맡겨져 있습니다.\n\n## 샘플 코드\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ncontract BitPermissions {\n    uint256 public constant MINT   = 1 \u003c\u003c 0;\n    uint256 public constant PAUSE  = 1 \u003c\u003c 1;\n    uint256 public constant ADMIN  = 1 \u003c\u003c 255;      // most important = highest bit\n    uint256 public constant MINTER_PAUSER = MINT | PAUSE; // a role\n\n    mapping(address =\u003e uint256) private _perm;\n\n    event PermissionGranted(address indexed _grantor, uint256 indexed _permission, address indexed _user);\n    event PermissionRevoked(address indexed _revoker, uint256 indexed _permission, address indexed _user);\n\n    constructor() { _perm[msg.sender] = ADMIN; }\n\n    modifier only(uint256 required) {\n        require(hasPermission(msg.sender, required), \"forbidden\");\n        _;\n    }\n\n    function hasPermission(address user, uint256 required) public view returns (bool) {\n        return _perm[user] \u0026 required == required;\n    }\n\n    function grantPermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] |= p;\n        emit PermissionGranted(msg.sender, p, user);\n        return true;\n    }\n\n    function revokePermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] \u0026= ~p;\n        emit PermissionRevoked(msg.sender, p, user);\n        return true;\n    }\n}\n```\n\n## 알아둘 점\n\n- 상태는 **Review**이며, 확정되기 전에 세부 내용이 바뀔 수 있습니다.\n- 컨트랙트당 권한 256개는 확고한 상한이고, 비트의 의미는 코드에 고정됩니다. 나중에 비트 3의 의미를 바꾸는 것은 사실상 마이그레이션입니다.\n- 비트마스크는 사람과 블록 익스플로러에게 불투명합니다. 메타데이터 확장이 도움이 되지만, OpenZeppelin 방식의 `AccessControl` 역할에 비해 도구 지원이 훨씬 부족합니다.\n- `hasPermission(user, 0)`을 조심하세요. 상위 집합 규칙 때문에 항상 true이므로, 설정되지 않은 상수를 가드로 사용하면 안 됩니다.\n"},"zh":{"lang":"zh","tldr":"一种极简的访问控制标准：每个权限是 uint256 中的一个比特位，角色就是位掩码，权限检查只需一次 AND 运算。","tags":["access-control","permissions","roles","solidity"],"related":[173,5982],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-6617/","markdown":"## 它解决什么问题？\n\n大多数合约使用单一所有者（[ERC-173](/eip-173/)）或具名的 `bytes32` 角色（[ERC-5982](/eip-5982/)）来做访问控制。单一所有者粒度太粗，而角色映射每检查一个角色就需要一次存储读取。\n\nERC-6617 把权限打包进比特位。用户的全部权限集合就是一个 `uint256`，因此检查\"该用户是否同时拥有权限 A 和 B？\"只需对一个存储值做按位 `AND`。\n\n## 它如何运作\n\n- 每个**权限**是 2 的幂（恰好只有一位被置位）。每个权限都是唯一的，`0` 表示\"无权限\"。这最多可以有 256 个权限。\n- **角色**是权限的任意 OR 组合，因此最多有 2^256 种可能的角色，且无需预先定义。\n- 比特位的位置可以表示重要程度：把最重要的权限放在最高位，权限就可以按整数比较。\n- 必需接口 `IEIP6617`：\n  - 如果用户的比特位是 `required` 的超集，`hasPermission(user, required)` 返回 true。\n  - `grantPermission(user, perm)` 和 `revokePermission(user, perm)` 返回 `bool`。\n  - 必须触发 `PermissionGranted` 和 `PermissionRevoked` 事件。\n- 可选（推荐）的 `IEIP6617Meta` 为基础权限和主要组合附加名称和描述，因为仅凭比特位无法自我说明。\n\n谁可以授予或撤销权限由具体实现决定。\n\n## 示例代码\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ncontract BitPermissions {\n    uint256 public constant MINT   = 1 \u003c\u003c 0;\n    uint256 public constant PAUSE  = 1 \u003c\u003c 1;\n    uint256 public constant ADMIN  = 1 \u003c\u003c 255;      // most important = highest bit\n    uint256 public constant MINTER_PAUSER = MINT | PAUSE; // a role\n\n    mapping(address =\u003e uint256) private _perm;\n\n    event PermissionGranted(address indexed _grantor, uint256 indexed _permission, address indexed _user);\n    event PermissionRevoked(address indexed _revoker, uint256 indexed _permission, address indexed _user);\n\n    constructor() { _perm[msg.sender] = ADMIN; }\n\n    modifier only(uint256 required) {\n        require(hasPermission(msg.sender, required), \"forbidden\");\n        _;\n    }\n\n    function hasPermission(address user, uint256 required) public view returns (bool) {\n        return _perm[user] \u0026 required == required;\n    }\n\n    function grantPermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] |= p;\n        emit PermissionGranted(msg.sender, p, user);\n        return true;\n    }\n\n    function revokePermission(address user, uint256 p) external only(ADMIN) returns (bool) {\n        _perm[user] \u0026= ~p;\n        emit PermissionRevoked(msg.sender, p, user);\n        return true;\n    }\n}\n```\n\n## 需要注意\n\n- 状态为 **Review**；在最终确定之前细节仍可能变化。\n- 每个合约 256 个权限是硬性上限，且比特位的含义固定在代码中。日后更改第 3 位的含义实际上等同于一次迁移。\n- 位掩码对人类和区块浏览器来说都不透明。元数据扩展有所帮助，但相比 OpenZeppelin 风格的 `AccessControl` 角色，工具支持要少得多。\n- 注意 `hasPermission(user, 0)`：按照超集规则它永远为 true，因此绝不要用未设置的常量作为守卫条件。\n"}},"requiredBy":[6366]}
