Auto-loaded by access-control-auditor agent during Phase 2...
2025 Statistics: Access Control is #1 vulnerability class with $953.2M in losses.
Understanding root causes helps detect vulnerabilities more effectively.
Developer thinks "only admin can call this" but forgets to add modifier.
// Developer INTENDED: only admin
// ACTUAL: anyone can call
function setPrice(uint256 newPrice) external {
price = newPrice; // @audit No modifier!
}
Detection: Find external/public functions without modifiers, then verify intent.
external/public means "anyone can call" - not a permission system.
// Visibility is NOT access control
function withdraw() public { // @audit public ≠ "user's own funds"
// Without checks, ANYONE withdraws ANYONE's funds
}
Detection: Every state-changing external/public function needs explicit permission checks.
Who is "admin"? What can they do? Often undocumented.
// VULNERABLE: Admin powers undefined
function emergencyWithdraw() external onlyAdmin {
// Can admin steal all user funds?
// Is this documented? Intended?
}
Detection: Map all admin powers. Flag undocumented capabilities as centralization risks.
Admin can create admins → single key compromise = total system takeover.
// VULNERABLE: Flat admin hierarchy
function addAdmin(address newAdmin) external onlyAdmin {
admins[newAdmin] = true; // @audit Compromised admin adds attacker
}
Detection: Trace role grant paths. Flag self-granting or circular hierarchies.
Build this for every contract:
| Contract | Function | Sensitivity | Required Role | Actual Check | Gap? |
|---|---|---|---|---|---|
| Vault | withdraw | CRITICAL | User (own funds) | None | YES |
| Vault | setFee | HIGH | Admin | onlyOwner | No |
| Vault | pause | HIGH | Guardian | onlyAdmin | WRONG ROLE |
| Token | mint | CRITICAL | Minter | None | YES |
| Level | Examples | Impact if Missing |
|---|---|---|
| CRITICAL | withdraw, transfer, mint, upgrade | Direct fund loss |
| HIGH | pause, setFee, setOracle | Protocol malfunction |
| MEDIUM | setParameter, whitelist | Degraded operation |
| LOW | view, pure functions | Information leak |
Root Cause: Intent-Implementation Gap
// VULNERABLE: Anyone can call
function setPrice(uint256 newPrice) external {
price = newPrice; // @audit Anyone can manipulate price!
}
function withdrawAll() external {
payable(msg.sender).transfer(address(this).balance); // @audit No modifier!
}
Search Queries:
Grep("function.*external(?!.*view)(?!.*pure)", glob="**/*.sol")
Grep("function.*public(?!.*view)(?!.*pure)", glob="**/*.sol")
Verification Questions:
Root Cause: Broken Permission Hierarchy
// VULNERABLE: Admin can add arbitrary admins
function addAdmin(address newAdmin) external {
require(admins[msg.sender], "Not admin");
admins[newAdmin] = true; // @audit Compromised admin adds attacker
}
// VULNERABLE: Self-grant role
function grantRole(bytes32 role, address account) public {
_grantRole(role, account); // @audit No permission check!
}
Search Queries:
Grep("grantRole|addAdmin|setAdmin", glob="**/*.sol")
Grep("_setupRole|_grantRole", glob="**/*.sol")
Verification Questions:
Root Cause: Confusing transaction origin with message sender
// VULNERABLE: Phishing via malicious contract
function withdraw() external {
require(tx.origin == owner); // @audit Phishing target!
// Attacker tricks owner to call malicious contract
// Malicious contract calls this function
// tx.origin is still owner!
}
Search Queries:
Grep("tx\\.origin", glob="**/*.sol")
Verification Questions:
Root Cause: Logic error in permission checks
// VULNERABLE: Should be AND, not OR
function sensitiveAction() external {
require(hasRole(ADMIN) || hasRole(GUARDIAN)); // @audit OR allows either
// Should require BOTH roles for high-sensitivity actions
}
// Also check for inverted logic
function withdraw() external {
require(!blacklisted[msg.sender]); // What if blacklist is empty?
}
Search Queries:
Grep("require.*\\|\\|", glob="**/*.sol")
Grep("require.*&&", glob="**/*.sol")
Verification Questions:
Root Cause: No confirmation for critical ownership changes
// VULNERABLE: Single transaction transfer
function transferOwnership(address newOwner) external onlyOwner {
owner = newOwner; // @audit Typo in address = permanent loss
}
// SECURE: Two-step pattern
function transferOwnership(address newOwner) external onlyOwner {
pendingOwner = newOwner;
}
function acceptOwnership() external {
require(msg.sender == pendingOwner);
owner = pendingOwner;
}
Search Queries:
Grep("transferOwnership|changeOwner|setOwner", glob="**/*.sol")
Grep("pendingOwner|acceptOwnership", glob="**/*.sol")
Verification Questions:
Root Cause: Misunderstanding of AccessControl patterns
// VULNERABLE: DEFAULT_ADMIN_ROLE can grant any role
// If compromised, attacker controls everything
contract Vault is AccessControl {
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN");
constructor() {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(ADMIN_ROLE, msg.sender);
// @audit DEFAULT_ADMIN_ROLE can grant ADMIN_ROLE to anyone
}
}
Search Queries:
Grep("DEFAULT_ADMIN_ROLE|AccessControl", glob="**/*.sol")
Grep("_setRoleAdmin|getRoleAdmin", glob="**/*.sol")
Verification Questions:
For each external/public function:
Document admin powers that can harm users:
| Admin Power | Risk Level | Impact |
|---|---|---|
| Pause withdrawals | High | Users locked out |
| Change fee to 100% | Critical | Rug pull |
| Upgrade implementation | Critical | Arbitrary code execution |
| Mint unlimited tokens | Critical | Inflation attack |
| Whitelist addresses | Medium | Censorship |
| Change oracle | Critical | Price manipulation |
Flag as finding if:
# Find all entry points
Grep("function.*external|function.*public", glob="**/*.sol")
# Find modifiers
Grep("modifier\\s+\\w+", glob="**/*.sol")
Grep("onlyOwner|onlyAdmin|only\\w+", glob="**/*.sol")
# Find role management
Grep("grantRole|revokeRole|renounceRole", glob="**/*.sol")
Grep("transferOwnership|acceptOwnership", glob="**/*.sol")
# Find dangerous patterns
Grep("tx\\.origin", glob="**/*.sol")
Grep("selfdestruct|delegatecall", glob="**/*.sol")
| Excuse | Reality |
|---|---|
| "It's an internal function" | Internal functions can be called via public entry points |
| "Only admin can call this" | Admin keys get compromised; document the risk |
| "This is by design" | Document it as centralization risk if undocumented |
| "Low likelihood" | Access control bugs caused $953M in losses |
| "I'll check later" | Check NOW or miss critical vulnerabilities |
| "The modifier exists somewhere" | Verify it's actually applied to THIS function |
| "Frontend prevents this" | On-chain must be secure standalone |