Skip to main content

Access Control Visualizer

Explore four battle-tested Solidity access control patterns — from simple ownership to time-delayed governance.

Start Simple

Use Ownable2Step for basic contracts. Only upgrade to AccessControl when you need multiple roles.

Never Skip Access Control

Missing access control is the #1 exploit vector. Every sensitive function needs a modifier.

Use OpenZeppelin

Battle-tested implementations with millions of dollars secured. Don't roll your own access control.

Key Features
  • Single owner address
  • onlyOwner modifier
  • transferOwnership / renounceOwnership
  • Ownable2Step: two-step transfer with acceptOwnership
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.20;
3
4import "@openzeppelin/contracts/access/Ownable2Step.sol";
5
6contract MyToken is Ownable2Step {
7 constructor() Ownable(msg.sender) {}
8
9 // Only owner can mint
10 function mint(address to, uint256 amount)
11 external onlyOwner
12 {
13 _mint(to, amount);
14 }
15
16 // Two-step transfer:
17 // 1. owner calls transferOwnership(newOwner)
18 // 2. newOwner calls acceptOwnership()
19}
Permission Hierarchy Diagrams
Ownable Hierarchy
Owner
All permissions
onlyOwner modifier
mint()
pause()
withdraw()
upgrade()
AccessControl Hierarchy
DEFAULT_ADMIN
Manages all roles
MINTER_ROLE
mint()
PAUSER_ROLE
pause()
UPGRADER_ROLE
upgrade()
Multi-Signature Flow
Signer A
Signer B
Signer C
2-of-3 Threshold
Requires majority approval
Propose
Approve
Execute
TimelockController Flow
PROPOSER
Schedules transactions
schedule()
Delay Period
e.g. 2 days
EXECUTOR
Runs after delay
execute()
cancel()
Did You Know?

The Parity Wallet hack froze $150M because a library contract had an unprotected initWallet() function — anyone could call it and become the owner.

Previous: Integer Overflow Demo
Back to integer overflow demo