/Solidity Deep Dive
🔐
Solidity Deep Dive
Day 1 · Smart Contracts · 45 min
Transparent Proxy (OpenZeppelin):
- Proxy contract delegates all calls to implementation
- Admin can upgrade implementation address
ifAdminmodifier prevents admin from accidentally calling implementation functions- Storage lives in proxy, logic lives in implementation
- Upgrade logic lives in the implementation, not the proxy
- Lighter proxy contract (cheaper deployment)
- Risk: if implementation doesn't include upgrade function, contract becomes non-upgradeable forever
- Preferred by OpenZeppelin for new projects
- Multiple proxies point to a single beacon
- Beacon stores implementation address
- Upgrade beacon → all proxies upgrade simultaneously
- Perfect for factory patterns (many instances of same logic)
// BAD: Implementation V1
contract V1 {
uint256 public value; // slot 0
}
// BAD: Implementation V2
contract V2 {
address public owner; // slot 0 — COLLISION!
uint256 public value; // slot 1
}
// GOOD: Always append new variables
contract V2 {
uint256 public value; // slot 0 (preserved)
address public owner; // slot 1 (new)
}
Use EIP-1967 storage slots for proxy admin/implementation to avoid collision with implementation storage.
Key Points
- ▸Transparent Proxy: admin in proxy, ifAdmin modifier
- ▸UUPS: upgrade logic in implementation, lighter proxy
- ▸Beacon: one upgrade updates all proxy instances
- ▸Never reorder storage variables in upgrades
- ▸Use EIP-1967 storage slots for proxy metadata