ERC-3561 Trust-minimized upgradeable proxy (Trust Minimized Upgradeability Proxy)
Stagnant · Other · created 2021-05-09
A standard that forces an upgradeable proxy contract to wait a mandatory period (the Zero Trust Period) before new implementation code actually takes effect, preventing an administrator from pushing an immediate, malicious upgrade.
Why it is needed
With the existing EIP-1967 transparent proxy, the admin can change the implementation logic address at any time. If the developer operating such a proxy is anonymous, so no one knows who wrote the code, users have no guarantee that the code they see now will remain unchanged the next moment. If the admin changes the implementation logic maliciously or hastily, draining funds or breaking functionality, users have no way to know in advance or respond. Decentralized governance could manage upgrades, but such a process can become a bottleneck in the early, unproven stage of a protocol. What is needed is a middle ground between instantly applied upgrades and completely fixed, immutable code.
What to implement
function proposeTo(address implementation, bytes calldata data) external IfAdmin: The admin designates the implementation logic address to apply next. If the current implementation is address(0), it is applied immediately to the IMPLEMENTATION_SLOT.function upgrade(bytes calldata data) external IfAdmin: Once the block allowed by UPGRADE_BLOCK_SLOT is reached, the next logic address is designated as the actual implementation logic and initialized.function cancelUpgrade() external onlyAdmin;: If upgrade() has not yet been called, the admin cancels the proposed next logic.event NextLogicDefined(address indexed nextLogic, uint earliestArrivalBlock); // important to have: Records the next logic address and the earliest block at which it becomes applicable (earliestArrivalBlock).event NextLogicCanceled(address indexed oldLogic);: Records the canceled next logic address.function prolongLock(uint b) external onlyAdmin;: The admin can only set the block at which new upgrade proposals become allowed (the Propose Block) to a later value than the existing one.event ProposingUpgradesRestrictedUntil(uint block, uint nextProposedLogicEarliestArrival);: Records the block at which the proposal restriction is lifted and the earliest block at which the next logic becomes available from that point.function setZeroTrustPeriod(uint blocks) external onlyAdmin;: The admin can only set the Zero Trust Period (in blocks) to a value greater than the previous one.event ZeroTrustPeriodSet(uint blocks);: Records the newly set Zero Trust Period block count.
In depth
Adding slots to the EIP-1967 proxy
This standard is defined as an addition of storage slots to the existing EIP-1967 transparent proxy design. All admin interactions must emit events to remain traceable, and all admin actions must be protected by the onlyAdmin() modifier. The existing EIP-1967 ADMIN_SLOT and IMPLEMENTATION_SLOT are retained as is, with four new slots added (Next Logic Contract Address, Upgrade Block, Propose Block, Zero Trust Period).
Next Logic Contract Address slot
The slot key is bytes32(uint256(keccak256('eip3561.proxy.next.logic')) - 1). The desired implementation logic address must first be designated as the 'next logic' in this slot before it actually takes effect in EIP-1967's IMPLEMENTATION_SLOT. proposeTo(address implementation, bytes calldata data) designates the next logic and emits NextLogicDefined. However, if the current implementation is address(0), it takes the data as an argument and upgrades IMPLEMENTATION_SLOT immediately. upgrade(bytes calldata data) designates the next logic address as the actual IMPLEMENTATION_SLOT and initializes it once the time allowed by UPGRADE_BLOCK_SLOT arrives. cancelUpgrade() can cancel the proposal before upgrade() is called, and emits NextLogicCanceled.
Upgrade Block slot
The slot key is bytes32(uint256(keccak256('eip3561.proxy.next.logic.block')) - 1). From this block number onward (inclusive), the next logic address can be set to EIP-1967's IMPLEMENTATION_SLOT. In other words, this is when upgrade() can be called. This value is automatically updated according to the Zero Trust Period and is shown as earliestArrivalBlock in the NextLogicDefined event.
Propose Block slot
The slot key is bytes32(uint256(keccak256('eip3561.proxy.propose.block')) - 1). From this block onward (inclusive), the next logic can be proposed. This is a convenience value; for example, it could be manually set to one year from now, or set to the maximum value to completely seal the code. It is set by the admin via prolongLock(uint b), which only allows values greater than the existing one, and emits the ProposingUpgradesRestrictedUntil event.
Zero Trust Period slot
The slot key is bytes32(uint256(keccak256('eip3561.proxy.zero.trust.period')) - 1). The value is measured in number of blocks and can only be set to a value larger than the previous one. When left at its default (0), the proxy behaves exactly like a standard EIP-1967 transparent proxy. Once set, all the rules described above are enforced. It is set via setZeroTrustPeriod(uint blocks) and emits a ZeroTrustPeriodSet event.
Detailed behavior in the reference implementation
In the reference implementation, proposeTo stores directly to LOGIC_SLOT and initializes via delegatecall, emitting Upgraded, without going through the next-logic slot, if the Zero Trust Period is 0 or the current logic is address(0). In all other cases it is designated as the next logic via _setNextLogic. _setNextLogic checks that the call occurs after the Propose Block, then updates the Upgrade Block to (current block + Zero Trust Period) and emits NextLogicDefined. fallback() blocks the case where the caller is the admin, so the admin cannot accidentally touch the logic contract through a normal call.
A Proposal Still Stalled
This proposal's status is Stagnant, meaning it is no longer being actively discussed or advanced. Since it has not been finalized as a standard, its current status must be re-checked before any practical application.
Things to watch out for
- Confirm no overflow is permitted: Users must confirm that the trust-minimized proxy code they are interacting with has no flaw that permits overflow.
- Confirm the code matches the reference implementation: Ideally, users should confirm that the code used is exactly identical to the reference implementation code in the original text.
- Confirm the Zero Trust Period length: Users should confirm that the Zero Trust Period is set reasonably: at least 2 weeks when upgrades are typically announced in advance, and at least 1 month or more in most other cases.