Solidity theorytheory 0/50 · 0%
Security · medium

26. Access control patterns

Ownable, two-step transfer and role-based access.

The simplest pattern is a single `owner` with an `onlyOwner` modifier. Two-step ownership transfer prevents locking the contract with a typo. Larger systems use roles: a mapping from role id to member set.

mapping(bytes32 => mapping(address => bool)) public hasRole;

modifier onlyRole(bytes32 r) {
    require(hasRole[r][msg.sender], "denied");
    _;
}

Document who can do what, and put privileged keys behind a multisig or timelock in production.

Check your understanding

  1. 1. Why use a two-step ownership transfer?

  2. 2. What is stored for role-based access?

  3. 3. What protects an admin key in production?