Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-3561, a proposal for introducing a delay before smart contract upgrades take effect.

The explanation below translates, summarizes, and expands on the original proposal.

I also cover a range of other EIPs.

Overview

ERC-3561 proposes a trust-minimized design for upgradeable proxies. It specifically addresses the difficulty anonymous developers face in earning external trust when using proxy upgrade functionality. Instead of allowing upgrades to take effect immediately, the proposed mechanism makes an upgrade effective only after a waiting period called the Zero Trust Period.

The mechanism aims to prevent intentional or malicious immediate upgrades and make smart contract operation more trustworthy. It introduces additional storage slots for managing the upgrade process.

Motivation

Many anonymous developers use upgradeable proxies to build smart contracts, but gaining the trust of their communities can be difficult. At the same time, upgradeability is important for incorporating innovations quickly and responding to vulnerabilities.

The mechanism proposed in ERC-3561 offers a way to build trust while preserving developer anonymity. Introducing a Zero Trust Period prevents developers from immediately applying malicious upgrades and makes it easier to establish external trust. The proposal is based on the belief that anonymous developers are important to building a fair and sustainable future.

Specification

Next logic contract

js
// Sets next logic contract address. Emits NextLogicDefined
// If current implementation is address(0), then upgrades to IMPLEMENTATION_SLOT
// immedeatelly, therefore takes data as an argument
function proposeTo(address implementation, bytes calldata data) external IfAdmin
// As soon UPGRADE_BLOCK_SLOT allows, sets the address stored as next implementation
// as current IMPLEMENTATION_SLOT and initializes it.
function upgrade(bytes calldata data) external IfAdmin
// cancelling is possible for as long as upgrade() for given next logic was not called
// emits NextLogicCanceled
function cancelUpgrade() external onlyAdmin;

event NextLogicDefined(address indexed nextLogic, uint earliestArrivalBlock); // important to have
event NextLogicCanceled(address indexed oldLogic);

NextLogicDefined

javascript
event NextLogicDefined(address indexed nextLogic, uint earliestArrivalBlock);

An event announcing the address of the proposed logic contract and the earliest block at which the upgrade can take effect. It is emitted when a new logic contract is proposed through proposeTo.

Parameters

  • nextLogic
    • The address of the newly proposed logic contract.
  • earliestArrivalBlock
    • The earliest block number at which the upgrade is permitted.

NextLogicCanceled

javascript
event NextLogicCanceled(address indexed oldLogic);

An event announcing that a proposed logic upgrade has been canceled. It is emitted when cancelUpgrade cancels an upgrade that has been proposed but not yet applied.

Parameters

  • oldLogic
    • The address of the canceled logic contract.

onlyAdmin

js
modifier onlyAdmin;

A modifier restricting operations to the administrator (admin). Only an address with administrative authority over the contract can execute functions using this modifier. This restriction is essential for controlling privileged operations.

proposeTo

js
function proposeTo(address implementation, bytes calldata data) external onlyAdmin;

Proposes a new logic contract. The specified address becomes the next logic contract. If the current implementation has not been set (address(0)), the upgrade takes place immediately. Otherwise, the proposed logic is normally activated through the upgrade function after the Zero Trust Period.

Arguments

  • implementation
    • The address of the proposed logic contract.
  • data
    • Initialization calldata, equivalent to that used during upgrade.

upgrade

js
function upgrade(bytes calldata data) external onlyAdmin;

Applies the logic contract previously selected through proposeTo.

Details

Once the configured Zero Trust Period has elapsed and earliestArrivalBlock has been reached, the logic address is written to the ERC-1967-compatible IMPLEMENTATION_SLOT, switching contract behavior to the new implementation.

For more on ERC-1967, see the following article.

[ERC-1967] Understanding Smart Contract Upgrades

Arguments

  • data
    • Calldata for the initialization operation performed after upgrading.

cancelUpgrade

js
function cancelUpgrade() external onlyAdmin;

Cancels the proposed logic upgrade. It can only be used to cancel a proposal made through proposeTo that has not yet been applied through upgrade. It allows the administrator to discard an upgrade proposal that is no longer needed.

Proposing upgrades

js
function prolongLock(uint b) external onlyAdmin;
event ProposingUpgradesRestrictedUntil(uint block, uint nextProposedLogicEarliestArrival);

ProposingUpgradesRestrictedUntil

javascript
event ProposingUpgradesRestrictedUntil(uint block, uint nextProposedLogicEarliestArrival);

An event announcing the block restriction on subsequent logic proposals and the earliest block at which the next proposed logic can take effect. It is emitted when prolongLock is executed.

Parameters

  • block
    • The block number from which another proposal is permitted.
  • nextProposedLogicEarliestArrival
    • The earliest block number at which the proposed logic can become effective.

prolongLock

js
function prolongLock(uint b) external onlyAdmin;

Prevents upgrade proposals themselves until a specified future block. This allows proposals to be restricted temporarily or, in practice, permanently. The proposal describes setting b to the maximum uint256 value as an extreme way to disable future upgrades.

Arguments

  • b
    • The block number from which the next upgrade proposal is permitted.

Zero Trust Period

js
function setZeroTrustPeriod(uint blocks) external onlyAdmin;
event ZeroTrustPeriodSet(uint blocks);

ZeroTrustPeriodSet

javascript
event ZeroTrustPeriodSet(uint blocks);

An event announcing that the Zero Trust Period has been set or updated. It is emitted when setZeroTrustPeriod is executed. The period provides advance notice of logic changes and is central to preventing immediate upgrades.

Parameters

  • blocks
    • The configured Zero Trust Period, expressed in blocks.

setZeroTrustPeriod

js
function setZeroTrustPeriod(uint blocks) external onlyAdmin;

Sets or updates the Zero Trust Period. The period improves trust by imposing a mandatory delay before logic contract changes take effect. Once set, the period cannot be shortened.

Arguments

  • blocks
    • The Zero Trust Period to configure, expressed in blocks.

Reference implementation

TrustMinimizedProxy.sol
pragma solidity >=0.8.0; //important

// EIP-3561 trust minimized proxy implementation https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3561.md
// Based on EIP-1967 upgradeability proxy: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1967.md

contract TrustMinimizedProxy {
    event Upgraded(address indexed toLogic);
    event AdminChanged(address indexed previousAdmin, address indexed newAdmin);
    event NextLogicDefined(address indexed nextLogic, uint earliestArrivalBlock);
    event ProposingUpgradesRestrictedUntil(uint block, uint nextProposedLogicEarliestArrival);
    event NextLogicCanceled();
    event ZeroTrustPeriodSet(uint blocks);

    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
    bytes32 internal constant LOGIC_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
    bytes32 internal constant NEXT_LOGIC_SLOT = 0x19e3fabe07b65998b604369d85524946766191ac9434b39e27c424c976493685;
    bytes32 internal constant NEXT_LOGIC_BLOCK_SLOT = 0xe3228ec3416340815a9ca41bfee1103c47feb764b4f0f4412f5d92df539fe0ee;
    bytes32 internal constant PROPOSE_BLOCK_SLOT = 0x4b50776e56454fad8a52805daac1d9fd77ef59e4f1a053c342aaae5568af1388;
    bytes32 internal constant ZERO_TRUST_PERIOD_SLOT = 0x7913203adedf5aca5386654362047f05edbd30729ae4b0351441c46289146720;

    constructor() payable {
        require(
            ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1) &&
                LOGIC_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1) &&
                NEXT_LOGIC_SLOT == bytes32(uint256(keccak256('eip3561.proxy.next.logic')) - 1) &&
                NEXT_LOGIC_BLOCK_SLOT == bytes32(uint256(keccak256('eip3561.proxy.next.logic.block')) - 1) &&
                PROPOSE_BLOCK_SLOT == bytes32(uint256(keccak256('eip3561.proxy.propose.block')) - 1) &&
                ZERO_TRUST_PERIOD_SLOT == bytes32(uint256(keccak256('eip3561.proxy.zero.trust.period')) - 1)
        );
        _setAdmin(msg.sender);
    }

    modifier IfAdmin() {
        if (msg.sender == _admin()) {
            _;
        } else {
            _fallback();
        }
    }

    function _logic() internal view returns (address logic) {
        assembly {
            logic := sload(LOGIC_SLOT)
        }
    }

    function _nextLogic() internal view returns (address nextLogic) {
        assembly {
            nextLogic := sload(NEXT_LOGIC_SLOT)
        }
    }

    function _proposeBlock() internal view returns (uint b) {
        assembly {
            b := sload(PROPOSE_BLOCK_SLOT)
        }
    }

    function _nextLogicBlock() internal view returns (uint b) {
        assembly {
            b := sload(NEXT_LOGIC_BLOCK_SLOT)
        }
    }

    function _zeroTrustPeriod() internal view returns (uint ztp) {
        assembly {
            ztp := sload(ZERO_TRUST_PERIOD_SLOT)
        }
    }

    function _admin() internal view returns (address adm) {
        assembly {
            adm := sload(ADMIN_SLOT)
        }
    }

    function _setAdmin(address newAdm) internal {
        assembly {
            sstore(ADMIN_SLOT, newAdm)
        }
    }

    function changeAdmin(address newAdm) external IfAdmin {
        emit AdminChanged(_admin(), newAdm);
        _setAdmin(newAdm);
    }

    function upgrade(bytes calldata data) external IfAdmin {
        require(block.number >= _nextLogicBlock(), 'too soon');
        address logic;
        assembly {
            logic := sload(NEXT_LOGIC_SLOT)
            sstore(LOGIC_SLOT, logic)
        }
        (bool success, ) = logic.delegatecall(data);
        require(success, 'failed to call');
        emit Upgraded(logic);
    }

    fallback() external payable {
        _fallback();
    }

    receive() external payable {
        _fallback();
    }

    function _fallback() internal {
        require(msg.sender != _admin());
        _delegate(_logic());
    }

    function cancelUpgrade() external IfAdmin {
        address logic;
        assembly {
            logic := sload(LOGIC_SLOT)
            sstore(NEXT_LOGIC_SLOT, logic)
        }
        emit NextLogicCanceled();
    }

    function prolongLock(uint b) external IfAdmin {
        require(b > _proposeBlock(), 'can be only set higher');
        assembly {
            sstore(PROPOSE_BLOCK_SLOT, b)
        }
        emit ProposingUpgradesRestrictedUntil(b, b + _zeroTrustPeriod());
    }

    function setZeroTrustPeriod(uint blocks) external IfAdmin {
        // before this set at least once acts like a normal eip 1967 transparent proxy
        uint ztp;
        assembly {
            ztp := sload(ZERO_TRUST_PERIOD_SLOT)
        }
        require(blocks > ztp, 'can be only set higher');
        assembly {
            sstore(ZERO_TRUST_PERIOD_SLOT, blocks)
        }
        _updateNextBlockSlot();
        emit ZeroTrustPeriodSet(blocks);
    }

    function _updateNextBlockSlot() internal {
        uint nlb = block.number + _zeroTrustPeriod();
        assembly {
            sstore(NEXT_LOGIC_BLOCK_SLOT, nlb)
        }
    }

    function _setNextLogic(address nl) internal {
        require(block.number >= _proposeBlock(), 'too soon');
        _updateNextBlockSlot();
        assembly {
            sstore(NEXT_LOGIC_SLOT, nl)
        }
        emit NextLogicDefined(nl, block.number + _zeroTrustPeriod());
    }

    function proposeTo(address newLogic, bytes calldata data) external payable IfAdmin {
        if (_zeroTrustPeriod() == 0 || _logic() == address(0)) {
            _updateNextBlockSlot();
            assembly {
                sstore(LOGIC_SLOT, newLogic)
            }
            (bool success, ) = newLogic.delegatecall(data);
            require(success, 'failed to call');
            emit Upgraded(newLogic);
        } else {
            _setNextLogic(newLogic);
        }
    }

    function _delegate(address logic_) internal {
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), logic_, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }
}

Rationale

The argument that contracts should simply be non-upgradeable from the outset may sound reasonable, but it is impractical for complex systems. For protocols that depend in part on human judgment and operational decisions, designing a perfect model on the first attempt is difficult.

Combining an ERC-1967 proxy with decentralized governance for upgrades can create a significant bottleneck while a protocol matures and sufficient operational data becomes available.

ERC-3561 introduces a mandatory delay for logic upgrades to reduce the risk of abuse through immediate upgrades. Even if the design might seem unfamiliar to less experienced developers, providing such trust-minimized options is important in smart contract development.

Security considerations

Users of this Zero Trust proxy should carefully verify the following conditions.

  • The implementation is free from vulnerabilities such as overflows.
  • The code conforms to the proposed specification, for example by following the structure of the reference implementation.
  • The configured Zero Trust Period is sufficiently long.

The suggested Zero Trust Period is at least two weeks when upgrade contents are disclosed in advance, and at least one month otherwise. If the period is too short, users may not have enough time to inspect the changes and respond, leaving them insufficiently protected against malicious upgrades.

Citation

Sam Porter (@SamPorter1984), "ERC-3561: Trust Minimized Upgradeability Proxy [DRAFT]," Ethereum Improvement Proposals, no. 3561, May 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3561.

Conclusion

This article covered ERC-3561, a proposal for imposing a delay on smart contract upgrades.

If you have any questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/