Access Control
Restricting who can call sensitive functions. From simple `Ownable` (one admin) to complex Role-Based Access Control (RBAC) (Minter, Burner, Admin).
Syntax Structure
Key Components
- Boilerplate structure required by the Solc compiler.
- Placement of state variables versus functions.
Practical Implementation
Implementing a basic Role Based system.
Core Concepts
Role
A label (hash) assigned to addresses.
Renounce
The ability to give up a role forever (e.g. decentralizing ownership).
MultiSig
Requiring M-of-N signatures for an action.
Mental Model
The ID Card System
Simple ownership is like a key to the house; whoever holds it opens the door. RBAC is like a corporate ID badge. The badge itself says 'Accounting' or 'Security'. The door reader checks the badge type, not just who you are.
Under the Hood
Standard access control is just `msg.sender` checking. Complex RBAC is usually a `mapping(bytes32 => mapping(address => bool))` (Role -> User -> HasRole).
Gas Analysis
Complex RBAC costs more storage.
- • Use `Ownable` for simple contracts (1 slot).
- • Use `AccessControl` for complex systems (mappings cost 20k gas to set up per user).
Security Risks
Lost keys are fatal.
- ! Centralization Risk: One key compromised = System compromised.
- ! Locked Out: Renouncing ownership accidentally means no one can manage the contract ever again.
Common Use Cases
Interactive Visualization
See exactly how the EVM handles this code in memory, storage, and the stack.
Click Run to execute the simulation
Then use the step controls to navigate