โ†
Previous Module
Event Subscription Demo

๐Ÿ—๏ธ Proxy Patterns: Transparent vs UUPS

Compare proxy patterns from OpenZeppelin

Learn upgradeable smart contract patterns

๐Ÿ”ง Proxy Pattern Comparison

Not all proxy patterns are equal. Transparent Proxy checks if caller is admin on every call (gas cost). UUPS moves upgrade logic to implementation (lower gas, higher risk). Beacon Proxy enables batch upgrades across multiple contracts. Diamond Proxy supports modular logic across multiple contracts (most complex). Each trades off simplicity, gas costs, and flexibility.

๐ŸŽฎ Interactive: Proxy Pattern Selector

Select a proxy pattern to see its architecture, upgrade mechanism, trade-offs, gas overhead, and real-world examples. Compare patterns to choose the right approach for your project.

๐Ÿ” Transparent Proxy

Proxy distinguishes between admin calls and user calls. If msg.sender is admin, execute admin functions (upgrade). Otherwise, delegatecall to Logic.

๐Ÿ”„ Upgrade Mechanism

Admin-only function in Proxy contract. Admin calls upgradeTo(newLogic), Proxy updates implementation address.

โœ“ Advantages
  • โ€ขSimple to understand and implement
  • โ€ขClear separation: admin vs user functions
  • โ€ขAdmin can't accidentally call Logic functions
  • โ€ขWidely used and battle-tested (OpenZeppelin)
โš ๏ธ Disadvantages
  • โ€ขHigher gas costs (if-check on every call)
  • โ€ขFunction selector clashing possible
  • โ€ขAdmin address stored in Proxy (gas cost)
  • โ€ขTransparent to admin, but adds complexity
โ›ฝ Gas Overhead
+2,500 gas per call (if-check overhead)
๐ŸŽฏ Best For
General-purpose upgrades, most DeFi protocols, when security > gas costs
๐Ÿ’ผ Real Examples
Compound, Aave V2, most OpenZeppelin upgrades

๐Ÿ“Š Pattern Decision Matrix

PatternComplexityGas CostUse Case
๐Ÿ” TransparentLowMediumGeneral purpose
โฌ†๏ธ UUPSMediumLowHigh frequency
๐Ÿ”ฆ BeaconMediumMediumMulti-instance
๐Ÿ’Ž DiamondHighHighLarge protocols

๐Ÿ’ก Choosing the Right Pattern

Start with Transparent Proxy

If you're new to upgrades, use OpenZeppelin's Transparent Proxy. It's battle-tested, well-documented, and handles most use cases. Gas overhead is acceptable for most applications.

Optimize with UUPS

If gas costs matter (high-frequency contract, L2 deployment), switch to UUPS. Lower overhead, but requires careful implementation of upgrade functions in every Logic version.

Scale with Beacon

If deploying many similar contracts (token factory, NFT collections), use Beacon. Upgrade all instances at once, save gas on multiple upgrades.

Go Diamond When Necessary

Only use Diamond if hitting 24KB size limit or need modular upgrades. Most protocols don't need this complexity. Reserve for large, feature-rich systems.

๐Ÿ’ก Key Insight

Proxy patterns are trade-offs, not upgrades. Transparent is simple but costs gas. UUPS saves gas but risks bugs in upgrade logic. Beacon enables batch upgrades but creates single points of failure. Diamond bypasses size limits but introduces complexity. There's no "best" patternโ€”only the right pattern for your constraints. Most projects should start with Transparent (proven, safe) and only switch to UUPS/Beacon/Diamond when specific needs (gas, batch, size) justify the added complexity.

โ† Introduction