Proxy Pattern
1 min read
Pronunciation
[prok-see pat-ern]
Analogy
Think of a proxy contract as a receptionist forwarding calls to the actual department that handles the request.
Definition
A smart contract design pattern that separates logic and storage by routing calls through a proxy contract which delegates execution to an implementation contract.
Key Points Intro
The proxy pattern enables upgradeability and separation of concerns in smart contracts.
Key Points
Upgradability: contract logic can be replaced without altering storage
Delegatecall: forwards calls and context to implementation
Storage layout: must remain consistent across versions
Gas overhead: additional cost from indirection
Example
OpenZeppelin’s Transparent Proxy routes user calls to an implementation contract while preserving state in the proxy.
Technical Deep Dive
Proxy contracts use EIP-1967 or EIP-1822 slots to store the address of the implementation. On invocation, the proxy’s fallback function executes delegatecall to the implementation, preserving msg.sender and storage context. Transparent proxies restrict admin from calling implementation functions to avoid clashes. UUPS proxies shift upgrade logic into the implementation for gas efficiency.
Security Warning
Incorrect storage layout or delegatecall misuse can lead to storage collision vulnerabilities and potential loss of funds.
Caveat
Introduces complexity and potential security risks; requires careful version management and thorough testing.
Proxy Pattern - Related Articles
No related articles for this term.