EIPs Explained

ERC-897 · Stagnant · ERC · 2018-02-21

ERC-897: DelegateProxy

An early, stagnant interface letting proxy contracts report that they are proxies, whether they are fixed or upgradeable, and where their logic lives, so tools could see through them; ERC-1967 storage slots took over this role.

What problem does it solve?

By 2018, delegate proxies were common. A small contract forwards every call with DELEGATECALL (EIP-7) to an implementation contract that holds the real logic. Projects used them for two reasons: to upgrade logic without changing the address, and to deploy many cheap clones of one contract.

Each project built its proxy differently. A block explorer or wallet looking at a proxy saw only the forwarding code and had no standard way to find the real contract's code and ABI. EIP-897, by authors from Aragon and Zeppelin, does not standardize how a proxy works internally. It standardizes how a proxy describes itself.

How it works

A compliant proxy exposes two functions:

interface ERCProxy {
    function proxyType() external pure returns (uint256 proxyTypeId);
    function implementation() external view returns (address codeAddr);
}
  • implementation() returns the address the proxy would delegate to at this moment, for this message.
  • proxyType() is a pure function, so its answer never changes. It says what kind of proxy this is:
    • 1, forwarding proxy. Once it returns a non-zero implementation, that address never changes. This fits clones.
    • 2, upgradeable proxy. The implementation can change, according to logic in the proxy or in the implementation.
  • If a contract does not answer proxyType(), or answers 0, treat it as not a proxy.

The main benefit the spec names is source verification. Explorers could show the implementation's code and ABI for a proxy address, not just the forwarding stub.

Sample code

A minimal upgradeable proxy that implements the interface (no access-control hardening, for illustration only):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract UpgradeableProxy {
    address private _impl;  // real proxies keep this in a collision-safe slot (ERC-1967)
    address private _admin;

    constructor(address impl) { _impl = impl; _admin = msg.sender; }

    function proxyType() external pure returns (uint256) { return 2; }
    function implementation() external view returns (address) { return _impl; }

    function upgradeTo(address impl) external {
        require(msg.sender == _admin, "not admin");
        _impl = impl;
    }

    fallback() external payable {
        address impl = _impl;
        assembly {
            calldatacopy(0, 0, calldatasize())
            let ok := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch ok case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) }
        }
    }
}

Detecting a proxy off-chain (ethers v6):

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const p = new Contract(addr, [
  "function proxyType() view returns (uint256)",
  "function implementation() view returns (address)",
], provider);
const kind = await p.proxyType().catch(() => 0n);   // 0 = not a proxy
if (kind !== 0n) console.log("logic at", await p.implementation());

Things to know

  • This proposal is Stagnant. Widely used proxy libraries, such as OpenZeppelin's, instead store the implementation address in the standard storage slots defined by ERC-1967, which tools can read directly.
  • Public functions on a proxy can clash with functions in the implementation, because a matching selector stops the call from being forwarded. ERC-1967-style proxies avoid adding public functions for this reason.
  • For non-upgradeable clones, see ERC-1167 minimal proxies. For upgrade logic placed in the implementation, see ERC-1822 (UUPS).
  • Storing _impl in a regular slot, as in the sample, can collide with the implementation's own storage. Use audited libraries in production.

#proxy #upgradeability #delegatecall #interface #stagnant

Details

Authors
Jorge Izquierdo <[email protected]>, Manuel Araoz <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2018-02-21

Machine-readable: Markdown · JSON