Lesson 2 of 9 · 27m
Access Control, Upgradeability, and Admin Risk
Audit privileged roles, initialization, proxy storage, timelocks, and admin compromise paths before debating subtle arithmetic bugs.
The largest losses are often boring. Not novel math, not cryptographic breakage — a private key with too much power, an initializer left open, a proxy pointing somewhere unexpected, or a role that can mint unlimited supply. In smart contracts, access control is asset custody policy written in code. Treat it that way.
Enumerate powers before judging implementation
Start with a privilege inventory. Every external function should answer three questions: who may call it, what state can it change, and what economic value can move as a result?
function caller power worst case
mint minter create supply infinite dilution
upgradeTo proxy admin replace implementation total control
setOracle operator choose price source instant manipulationA role name like operator means nothing until you enumerate its actual authority. The scariest contracts are rarely the ones with many owners; they are the ones where one innocuous configuration setter changes the security model.
Initializers are a recurring catastrophe
Proxy implementations cannot rely on constructors for deployed instance state. They use initializer functions, and those functions must be impossible to reinitialize:
contract Vault is Initializable, OwnableUpgradeable {
function initialize(address asset) external initializer {
__Ownable_init(msg.sender);
assetToken = IERC20(asset);
}
}If initialize is unprotected, anyone can become owner. If implementation contracts are left uninitialized, attackers may sometimes initialize the implementation itself and abuse delegatecall paths. OpenZeppelin's _disableInitializers() constructor pattern exists because this mistake kept happening.
Proxy storage does not forgive layout mistakes
Upgradeable contracts delegate execution into implementation code while retaining proxy storage. A new implementation must preserve storage layout. Inserting a variable before existing ones shifts every slot and can reinterpret balances as addresses or booleans as supply caps.
// v1
uint256 public totalDeposits;
address public oracle;
// v2 — catastrophic if inserted in the middle
uint256 public totalDeposits;
uint256 public newRewardIndex; // oracle is now read from this slot's neighborhood
address public oracle;Use upgrade validation tools, storage gaps in base contracts, and a repository layout that makes implementation versions explicit. "We tested the new logic" is insufficient if the storage layout changed.
Timelocks reduce surprise, not power
A timelock gives users time to exit before privileged changes execute. It does not make an unlimited mint safe. It does not protect instant configuration changes outside the timelock. It also does not help if the timelock admin can replace the implementation with one that bypasses the queue.
A credible deployment uses separation of duties: a multisig proposer, a timelock executor, an emergency pause guardian with narrow powers, and monitoring for every privileged call. Verify those arrangements onchain, not in a slide deck.
Field notes
onlyOwneris a code smell when the owner is a single externally owned account controlling user assets.- Ownership transfer should be two-step; mistyped one-step transfers can brick administration permanently.
renounceOwnershipis not automatically safer. It can leave critical parameters unfixable after integration changes.- Test initialization on the actual deployed proxy path, including constructor-like implementation state.
- During review, draw the trust graph: key holder -> timelock -> proxy admin -> implementation -> user funds.
Was this lesson helpful?