---
eip: 6366
label: ERC-6366
title: Permission Token
status: Review
type: Standards Track
category: ERC
created: 2022-01-19
requires: 6617
official: https://eips.ethereum.org/EIPS/eip-6366
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6366.md
canonical: https://eips.huatuo.xyz/ko/eip-6366/
lang: ko
tldr: 각 주소의 권한을 토큰과 비슷한 컨트랙트 안의 단일 uint256에 비트로 저장하여, 역할을 비트마스크로 확인하고 잔액처럼 이전하거나 위임할 수 있게 한다.
tags: [permissions, access-control, roles, bitmask, token]
---

# ERC-6366: Permission Token

> A token that holds the permission of an address in an ecosystem

**TL;DR:** 각 주소의 권한을 토큰과 비슷한 컨트랙트 안의 단일 uint256에 비트로 저장하여, 역할을 비트마스크로 확인하고 잔액처럼 이전하거나 위임할 수 있게 한다.

## 어떤 문제를 해결하나요?

대부분의 프로토콜에는 owner, operator, manager, validator 같은 특권 역할이 있습니다. 보통 각 컨트랙트가 자체 접근 제어 목록을 유지하며, 문자열이나 `keccak256` 역할 이름을 쓰는 경우가 많습니다. 컨트랙트 생태계 전체로 보면 이는 감사하기 어려워집니다. 누가 무엇을 할 수 있는지가 여러 곳에 흩어지기 때문입니다.

ERC-6366은 **권한 토큰**을 제안합니다. 각 주소의 권한이 `uint256` "잔액"이고, 그 숫자의 각 비트가 권한 하나인 컨트랙트입니다. 접근 확인은 저렴한 비트 연산이 되며, 생태계의 모든 컨트랙트가 같은 곳에 물어볼 수 있습니다.

## 어떻게 동작하나요?

권한은 [ERC-6617](/eip-6617/)(비트 기반 권한)을 따릅니다. 각 기본 권한을 2의 거듭제곱으로 할 것을 권장하며, 그러면 권한 집합을 `|`로 합치고 `&`로 확인할 수 있습니다.

핵심 인터페이스 `IEIP6366Core`는 의도적으로 [ERC-20](/eip-20/)처럼 보이게 되어 있습니다.

| 함수 / 이벤트 | 역할 |
| --- | --- |
| `permissionOf(owner)` | owner의 권한 비트 |
| `transfer(to, permission)` | 자신의 권한 일부를 `to`에게 넘김. 부족한 권한이 있거나 `to`가 이미 그중 하나라도 가지고 있으면 revert해야 함 |
| `approve(delegatee, permission)` | `delegatee`가 자신의 권한 일부로 자신을 대신해 행동하게 함. 새 호출은 이전 부여를 덮어씀 |
| `delegated(owner, delegatee)` | `owner`가 `delegatee`에게 위임한 것 |
| `permissionRequire(permission, required)` | `required`가 `permission`의 부분집합이면 `true` |
| `hasPermission(owner, actor, required)` | `actor`가 `required`를 직접, 또는 `owner`의 위임을 통해 보유하면 `true` |
| `Transfer`, `Approval` 이벤트 | transfer와 approve 시 emit됨 |

선택 사항: 권한에 대한 사람이 읽을 수 있는 설명(ERC-6617 메타데이터 확장)과 커스텀 에러 `AccessDenied`, `DuplicatedPermission`, `OutOfRange`.

## 샘플 코드

권한을 비트로 정의하고 권한 토큰으로 함수를 보호하기:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IEIP6366Core {
    function permissionOf(address owner) external view returns (uint256);
    function hasPermission(address owner, address actor, uint256 required) external view returns (bool);
}

contract Vault {
    uint256 constant PERM_PAUSE    = 1 << 0;
    uint256 constant PERM_WITHDRAW = 1 << 1;
    uint256 constant PERM_UPGRADE  = 1 << 2;

    IEIP6366Core public immutable perms;
    error AccessDenied(address owner, address actor, uint256 permission);

    constructor(IEIP6366Core p) { perms = p; }

    // `owner` is the account whose permissions the caller is using (itself or a delegator)
    modifier need(address owner, uint256 required) {
        if (!perms.hasPermission(owner, msg.sender, required))
            revert AccessDenied(owner, msg.sender, required);
        _;
    }

    function emergencyWithdraw(address owner) external need(owner, PERM_PAUSE | PERM_WITHDRAW) {
        // ...
    }
}
```

부분집합 검사 자체는 표현식 하나입니다.

```solidity
function permissionRequire(uint256 permission, uint256 required) pure returns (bool) {
    return permission & required == required;
}
```

## 알아둘 점

- **상태: Review.** 사양의 Rationale과 Security Considerations 절은 아직 "논의 필요"로 되어 있으므로 변경을 예상하세요.
- 256비트이므로 권한 토큰 하나당 서로 다른 기본 권한은 최대 256개입니다.
- 권한은 보유한 사람이 누구든 이전할 수 있습니다. 강력한 비트를 누가 받는지 신중하게 정하세요. 옮기는 것이 ERC-20 전송만큼 쉽습니다.
- `approve`는 이전 위임에 더하지 않고 덮어씁니다.
- 이는 OpenZeppelin `AccessControl` 같은 역할 기반 라이브러리의 대안이며, 그대로 바꿔 끼울 수 있는 호환 대체품은 아닙니다.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-6366
