Lab: free tools · size first · stock scanner · crypto scanner · journal
Solidity Proxy Patterns: Upgradeable Smart Contracts Explained
Proxy patterns in Solidity allow smart contracts to be upgraded by separating storage (in the proxy contract) from logic (in the implementation contract). The proxy delegates all calls to the implementation using delegatecall. Major patterns include Transparent Proxy (OpenZeppelin), UUPS (EIP-1822), and Beacon Proxy. Each has different tradeoffs in gas cost, security, and upgrade complexity.
Solidity proxy patterns separate a contract's storage, held in a proxy, from its logic, held in an implementation contract that can be replaced. Common patterns are Transparent proxies, UUPS and Beacon proxies. They allow upgrades but introduce risks like storage collisions and uninitialized implementations, both of which have caused real exploits.
How a proxy works
Users call the proxy. The proxy has almost no logic of its own and passes every call to the implementation using delegatecall, which runs the implementation's code against the proxy's storage. To upgrade, an admin points the proxy at a new implementation, and the address and stored balances stay the same. ERC-1967 sets fixed storage slots for the implementation address, the admin and the beacon, chosen from hashes so they won't collide with the contract's own variables. Block explorers read those slots, which is how they can show a proxy's real functions and its current implementation.
The three common patterns
A transparent proxy keeps the upgrade logic in the proxy and only lets the admin call it; every other caller is passed through. UUPS puts the upgrade function in the implementation, which is cheaper to deploy and is now OpenZeppelin's recommendation, but an upgrade to code without that function would lock the contract on that version for good, which OpenZeppelin's version checks for by default. A beacon proxy reads its implementation from a separate beacon contract, so one transaction upgrades many proxies at once.
Storage clashes and setup bugs
Proxies can't use constructors, so setup moves to an initialize function. If that function is left uncalled on the proxy or the implementation, an attacker can call it first and take control. OpenZeppelin's docs say to lock implementation contracts on deployment for that reason. Changing the order of storage variables between versions can scramble data. For users, the larger point is that an upgradeable contract can change under you. Check who holds the upgrade key, whether a timelock sits in front of it, and when the implementation last changed.