-
Notifications
You must be signed in to change notification settings - Fork 2
Transparent Proxy Pattern (UUPS) vs Beacon Proxy Pattern
Proxy upgradeable smart contracts are a design pattern in blockchain development that allows for the upgrade of a smart contract's logic without changing its address. This is achieved by separating the contract into two components:
- Proxy Contract: Holds the contract's state and delegates all calls to the implementation contract.
- Implementation Contract: Contains the actual logic of the contract.
The main advantage of this pattern is that it allows for contract upgrades while preserving the contract's address and state, which is crucial for maintaining contract interactions and data continuity.
UUPS proxies are a specific type of upgradeable proxy that follows the EIP-1822 standard. In this pattern:
- Proxy Contract: It includes minimal logic, primarily to delegate calls to the implementation contract and handle upgrades.
- Implementation Contract: Contains both the logic and the upgrade functionality.
The upgrade process in UUPS involves calling an upgradeTo
function within the implementation contract. This function modifies the storage of the proxy to point to a new implementation contract.
- Upgrade logic is embedded in the implementation contract.
- Lower gas costs due to reduced complexity in the proxy contract.
- Increased security as the upgrade logic is not part of the proxy.
The Beacon Proxy Pattern involves a beacon contract that manages the implementation contract addresses. The beacon provides the logic address for multiple proxy contracts.
- Beacon Contract: Manages and provides the implementation address for proxies.
- Proxy Contract: Delegates calls to the address provided by the beacon.
- Implementation Contract: Contains the logic to be executed.
In this pattern, when an upgrade is required, the beacon contract is updated to point to a new implementation. All proxies using the beacon will automatically start using the new implementation.
- Centralized upgrade management through the beacon.
- Simplifies upgrades across multiple proxies.
- Suitable for scenarios where multiple proxies need to share the same logic.
- UUPS: Upgrade logic within the implementation contract.
- Beacon Proxy: Centralized upgrade logic via the beacon.
- UUPS: Simpler, minimal logic.
- Beacon Proxy: Slightly more complex due to beacon interaction.
- UUPS: Lower, as upgrade logic is in the implementation contract.
- Beacon Proxy: Potentially higher due to beacon management.
- UUPS: Each proxy can have its upgrade path.
- Beacon Proxy: Centralized control through the beacon.
- UUPS: Individual proxies upgraded separately.
- Beacon Proxy: All proxies linked to a beacon upgraded together.
- UUPS: Suitable for individual or fewer contracts requiring independent upgrades.
- Beacon Proxy: Ideal for managing multiple contracts with shared logic.