EIPs Explained

ERC-1967 · Final · ERC · 2019-04-24

ERC-1967: Proxy Storage Slots

Fixes the exact storage slots where proxy contracts keep their implementation, beacon and admin addresses, so explorers and tools can see what any proxy really runs.

What problem does it solve?

An upgradeable proxy holds the state and forwards every call with delegatecall to a separate logic contract (the implementation). The proxy must remember the implementation address somewhere, but:

  • If it uses an ordinary storage slot, the logic contract's own variables may overwrite it, since both share the proxy's storage.
  • If it exposes a public getter, that function selector could clash with one in the logic contract, a known way to hide backdoors.

Before ERC-1967, each proxy library chose its own location, so block explorers and wallets had no reliable way to tell that a contract was a proxy or which code it delegated to.

How it works

The standard defines three well-known storage slots. Each is keccak256 of a label minus one, so the compiler will never allocate them and the hash has no known preimage:

Slot Derived from Holds Event on change
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc eip1967.proxy.implementation Logic contract address Upgraded(address indexed implementation)
0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50 eip1967.proxy.beacon Beacon contract address BeaconUpgraded(address indexed beacon)
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103 eip1967.proxy.admin Address allowed to upgrade (optional) AdminChanged(address previousAdmin, address newAdmin)
  • Use either the implementation slot or the beacon slot. A beacon is a contract with implementation() returns (address), which lets many proxies be upgraded at once. Tools should read the beacon slot only when the implementation slot is empty.
  • Any function that writes these slots, including initial setup, SHOULD emit the matching event so monitors can track upgrades.

Explorers such as Etherscan read these slots to show a proxy's logic contract ABI; the spec cites USDC as an example.

Sample code

Find the implementation behind any ERC-1967 proxy (ethers v6):

import { JsonRpcProvider, getAddress, dataSlice, Contract, ZeroAddress } from "ethers";

const IMPL   = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
const BEACON = "0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50";

const provider = new JsonRpcProvider(process.env.RPC_URL);

async function implementationOf(proxy: string): Promise<string> {
  const impl = getAddress(dataSlice(await provider.getStorage(proxy, IMPL), 12));
  if (impl !== ZeroAddress) return impl;
  const beacon = getAddress(dataSlice(await provider.getStorage(proxy, BEACON), 12));
  const b = new Contract(beacon, ["function implementation() view returns (address)"], provider);
  return b.implementation();
}

Reading and writing the slot in Solidity:

bytes32 constant IMPLEMENTATION_SLOT =
    bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1);

function _getImplementation() internal view returns (address impl) {
    bytes32 slot = IMPLEMENTATION_SLOT;
    assembly { impl := sload(slot) }
}

Things to know

  • Final and the de facto proxy layout. OpenZeppelin's ERC1967Proxy, transparent proxies and UUPS (ERC-1822) all use these slots.
  • The standard fixes only where the data lives, not who may upgrade. Access control is up to the proxy or, for UUPS, the logic contract.
  • Contracts written in assembly or in unusual languages can still collide with these slots; the guarantee relies on Solidity and Vyper storage layout rules.
  • For non-upgradeable clones see ERC-1167; for multi-facet proxies see ERC-2535; for namespacing a logic contract's own storage see ERC-7201.

#proxy #upgradeability #storage #delegatecall

Details

Authors
Santiago Palladino (@spalladino), Francisco Giordano (@frangio), Hadrien Croubois (@Amxx)
Status
Final
Type
Standards Track / ERC
Created
2019-04-24
Required by

Machine-readable: Markdown · JSON