Upgradeable Contracts and Proxies
Upgradeability lets a team fix bugs after deployment, at the cost of complexity and trust. This lesson explains how proxies work, compares transparent, UUPS and beacon proxies, and covers initialisers, storage layout and the security risks of upgrades.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how a proxy forwards calls to an implementation.
- Compare transparent, UUPS and beacon proxies.
- Explain why upgradeable contracts use initialisers.
- Identify storage layout rules for upgrades.
- Describe the trust trade-off of upgradeability.
How a proxy works
Deployed code cannot change, but a contract can forward calls elsewhere. In the proxy pattern, users interact with a proxy contract that holds all state and ether. Its fallback function forwards every call with delegatecall to an implementation (logic) contract, whose code then runs against the proxy's storage. Upgrading means changing the implementation address stored in the proxy; the proxy's address, state and balance stay the same.
OpenZeppelin proxies store the implementation address in a standard, pseudo-random storage slot defined by ERC-1967, so it cannot collide with the implementation's own variables.
The following diagram shows a proxy before and after an upgrade.

Inside a proxy
Proxy types
The following comparison sets out the three common proxy designs.
Which proxy type?
Initialisers and storage layout
A constructor runs when the implementation is deployed, writing to the implementation's own storage, not the proxy's. Upgradeable contracts therefore replace constructors with an initialize function, protected by OpenZeppelin's initializer modifier so it can run only once, and called through the proxy at deployment. The implementation's constructor calls _disableInitializers() so nobody can initialise the implementation directly.
Because the implementation code reads the proxy's storage slot by slot, every new version must keep the existing layout. The following list gives the rules.
- Never remove, reorder or change the type of existing state variables.
- Add new variables only after the existing ones (or in a reserved gap or namespaced storage).
- Do not use
immutablefor values that must survive upgrades unless intended, and do not set state in constructors. - Use the OpenZeppelin upgrades plugins, which check layout compatibility before an upgrade.
Safe upgrades
The trade-off
Upgradeability is a trust decision
Upgradeability replaces "the code cannot change" with "the code can change whenever the upgrade key holder decides". Users must trust that key holder. Production systems protect upgrades with a multisig and a timelock, announce upgrades in advance, and some deliberately deploy immutable contracts or renounce upgrade rights once the system is mature.
A corrupted balance
Version 1 of an upgradeable token declares uint256 totalSupply; mapping(address => uint256) balances;. Version 2 adds address treasury; as the first state variable. After the upgrade, treasury returns a strange address and balances look wrong. Why?
Inserting treasury first shifted every variable by one slot: version 2 reads slot 0, which still holds version 1's totalSupply, as the treasury address, and looks for balances in the wrong place. New variables must be appended after the existing ones. The upgrades plugin's layout check would have rejected this upgrade.
The uninitialised implementation
A team deploys a UUPS implementation and initialises only the proxy. A security researcher warns that the implementation contract itself is uninitialised. Why does it matter?
Anyone could call initialize on the implementation, become its owner and, in older UUPS designs, call its upgrade function to make it delegatecall code that destroys or corrupts it, affecting every proxy that uses it. Calling _disableInitializers() in the implementation's constructor prevents this.
Why can an upgradeable implementation not use its constructor to set the owner?
Show answer
The constructor runs when the implementation is deployed and writes to the implementation's own storage, not the proxy's. An initialize function called through the proxy sets the proxy's state.
Exam Tips
Remember for the exam
- A proxy holds state and delegatecalls an implementation that can be replaced.
- Transparent: upgrade logic in the proxy; UUPS: in the implementation; beacon: shared by many proxies.
- Use initialize with the initializer modifier, not constructors; disable initialisers on implementations.
- Never reorder or remove state variables; append new ones.
- Upgrade keys need multisig and timelock protection.