EIPs Explained

ERC-7303 · Draft · ERC · 2023-07-09

ERC-7303: Token-Controlled Token Circulation

A draft access-control scheme where holding an NFT or ERC-1155 token is the role, so permissions are granted by minting, revoked by burning, and visible in any wallet.

What problem does it solve?

Role-based access control (as in ERC-5982 or OpenZeppelin AccessControl) stores roles in a private mapping. Granting or revoking them needs a separate admin tool, and users cannot see in their wallet which privileges they hold.

ERC-7303, "Token-Controlled Token Circulation", represents each privilege as a control token: an ERC-721 or ERC-1155 token. If your account holds one, you have the role. Typical uses: minter/burner rights for ticket or membership tokens, transfer rights limited to licensed agencies, proof that a recipient address was verified, and capabilities delegated to an autonomous agent that can be revoked at any time.

How it works

  • A role is a bytes32, recommended as keccak256("<role_name>").
  • The contract associates each role with one or more already-deployed control-token contracts (and a typeId for ERC-1155).
  • An account has the role if balanceOf on any associated control token is greater than 0.
  • Granting a role means minting the control token to the account (the spec suggests ERC-5679 safeMint); revoking means burning it.
  • Compliant contracts expose IERC7303 and declare it via ERC-165:
    • hasRole(role, account) — same signature as OpenZeppelin's, so existing callers work unchanged.
    • getERC721ControlTokens(role) and getERC1155ControlTokens(role) — enumerate the role structure.
    • Events ERC721ControlTokenAdded and ERC1155ControlTokenAdded when a control token is linked to a role.

There is deliberately no grantRole / revokeRole: those happen on the control-token contracts, which the target contract does not control.

Sample code

Gating a mint function on holding a control NFT (simplified from the reference implementation):

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract Ticket is ERC721 {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    event ERC721ControlTokenAdded(bytes32 indexed role, address indexed contractId);

    mapping(bytes32 => address[]) private _controls;

    constructor(address minterBadge) ERC721("Ticket", "TKT") {
        _controls[MINTER_ROLE].push(minterBadge);
        emit ERC721ControlTokenAdded(MINTER_ROLE, minterBadge);
    }

    function hasRole(bytes32 role, address account) public view returns (bool) {
        address[] memory c = _controls[role];
        for (uint256 i = 0; i < c.length; i++) {
            if (IERC721(c[i]).balanceOf(account) > 0) return true;
        }
        return false;
    }

    function safeMint(address to, uint256 id) external {
        require(hasRole(MINTER_ROLE, msg.sender), "no control token");
        _safeMint(to, id);
    }
}

Things to know

  • Status is Draft; the IERC7303 interface was added in later revisions and may still change.
  • Security depends entirely on the control-token contract: who can mint, transfer and burn it.
  • The spec recommends control tokens be non-transferable. For agents, it requires that the issuer can burn the token without the holder's cooperation, otherwise revocation is not guaranteed.
  • The check is per account, not per key: with smart accounts using session keys, any key controlling the account passes.
  • Role gating answers "may this account do this kind of action", not "is this specific call sensible"; combine it with spending caps or other checks.

#access-control #roles #nft #permissions

Details

Authors
Ko Fujimura (@kofujimura)
Status
Draft
Type
Standards Track / ERC
Created
2023-07-09
Requires

Machine-readable: Markdown · JSON