How do upgradeable smart contracts work, and what are the trade-offs?
What the interviewer wants to hear
- Proxy holds state and delegates calls to an implementation
- Transparent, UUPS and beacon proxy patterns
- Initializer functions instead of constructors
- Storage layout compatibility rules
- Trust and governance trade-off: who can upgrade
- Timelocks and multisig for upgrades
Model answer
An upgradeable contract is split in two. Users talk to a proxy contract, which holds all the state and funds and forwards each call using delegatecall to an implementation contract that contains the logic. To upgrade, an admin points the proxy to a new implementation, and the state stays in place. Common patterns are Transparent proxies, where upgrade logic sits in the proxy, UUPS, where it sits in the implementation and is cheaper, and Beacon proxies for many proxies sharing one implementation. Because constructors do not run in the proxy context, we use initializer functions protected against being called twice. New versions must keep the storage layout, only appending variables, or use namespaced storage. The big trade-off is trust: upgradeability lets you fix bugs but also lets whoever holds the key change the rules. So I put upgrades behind a multisig and timelock, so users can see and react to changes.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Blockchain Developer questions
- What is a reentrancy attack and how do you prevent it?
- What techniques do you use to reduce gas costs in Solidity contracts?
- How do you test a smart contract before deploying it to mainnet?
- What is a blockchain oracle and how do you use price data safely?
- How do signature-based approvals like ERC-2612 permit and Permit2 work, and what are their risks?
- How do you build a reliable dApp frontend that reads and writes contracts with viem and wagmi?
- How do chain reorganizations affect a dApp or backend service, and how do you handle them?
- How do you design admin control for a protocol so it can be maintained without making users trust a single person?
- Walk me through how you deploy a set of contracts to mainnet safely.