Walk every privileged function
Access control is verified by calling each protected function from an unauthorised account and watching it revert — reading the modifier is not evidence.
Procedure
- Enumerate role checks:
grep -nE 'onlyOwner|onlyRole|onlyAdmin|require\(msg.sender ==|hasRole\(|_checkRole' -r src/. - Map auth-related state:
cast storage <addr> <slot>for the owner slot, andforge inspect <Contract> storage-layoutto place role hashes. - Build an inventory: for each gated function — selector, modifier, intended caller, and the effect if called by an attacker.
- Compute selectors to confirm nothing is mislabeled:
cast sig "setFee(uint256)"andforge inspect MyContract methods. - For every function, write a negative test from a fresh account:
address mallory = address(0xBEEF);
vm.prank(mallory);
vm.expectRevert(bytes4(keccak256("OwnableUnauthorizedAccount(address)")));
target.setFee(9999);
- Run the negative suite:
forge test --match-test testOnlyOwner -vv. - Check initialisation: is
ownerset in the constructor, or in aninitialize()anyone can call? Callinitializetwice and confirm the second reverts. - Hunt privilege escalation: any function that can set owner/admin/role, or that
delegatecalls into a mutable target. - Check renounce/admin-transfer paths leave no orphan:
transferOwnership(address(0))must be explicitly forbidden or documented. - Confirm two-step ownership:
transferOwnershipsetspendingOwnerandacceptOwnershipfinalises (guards against a typo'd address).
Pitfalls
- An
onlyOwnerfunction that calls an unguarded internal function which is itselfpublic. - A role granted in
initializeto the deployer, and the deployer is a fresh EOA whose key later leaks. tx.originused as the check — phishable via any intermediate contract.- A modifier present but
_checkRoleuses the wrong role constant, copy-pasted from another role. - Missing negative test: a green suite that never calls a privileged function as a non-admin cannot detect the hole.
Verification
forge test --match-test "testAccessControl" -vvv | grep -c PASS
Pass: one PASS per gated function plus one PASS per expectRevert negative. A gated function with no negative test is reported as unverified.
Report the count of gated functions, the selectors, and any that revert for the wrong reason.