Skip to content

ChainSecurity/real-minimal-proxy

Repository files navigation

Real Minimal EVM Proxy using EIP-7702

FOR EDUCATION PURPOSE ONLY!

This is a real minimal proxy powered by EIP-7702. The code of the proxy is only 23 bytes:

(0xef0100 || address)

Compared to the minimal proxy which is 45 bytes:

363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3

There is a nearly 50% size reduction.

The script derives the proxy address from a one-time signature generated over the following authorization tuple:

{"chainId", "implementation address", "nonce"}

Multiple mined authorization tuples can be batched in one transaction from any account to deploy the proxies.

If you want to read all the details, please visit: https://www.chainsecurity.com/blog/the-real-minimal-proxy---powered-by-eip-7702

To run

The minimal_proxy directory contains the OwnableStore simple contract as the implementation for the proxy to be deployed.

  1. Make sure you have forge and anvil installed.

  2. Compile the contracts in implementation folder:

git submodule update --init --recursive
cd implementation
forge build
  1. Run the scripts that mint a proxy, deploy the proxy, initialize the proxy, and interact with the proxy.
rye sync
rye run real-minimal-proxy

Or

uv run src/real_minimal_proxy real_minimal_proxy
  1. You should be able to see similar results as:
1. Implementation deployed at: 0x5FbDB2315678afecb367f032d93F642f64180aa3
2. [EIP-7702] Mining signature: 0xaa3d45Cdf1f4e3D01aa694167528317bD12E7fDA
    Success after 1 attempts!
    Sig-v=0,
    Sig-r=0x7702770277027702770277027702770277027702770277027702770277027702,
    Sig-s=0x7702770277027702770277027702770277027702770277027702770330de6e37
3. [EIP-7702] Proxy (authority) deployed at: 0xaa3d45Cdf1f4e3D01aa694167528317bD12E7fDA
    Authority code: 0xef01005fbdb2315678afecb367f032d93f642f64180aa3
    Proxy (authority) initialized by: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
    EIP-7702 proxy gas used: 95654
4. [EIP-7702] Owner calling setValue to: 100
    Proxy owner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
    Value Before: 0
    Value After:  100
5. [EIP-1167] Factory deployed at: 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9
    EIP-1167 minimal proxy gas used: 116357
6. [EIP-1167] Owner calling setValue to: 100
    Proxy owner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
    Pre  readValue: 0
    Post readValue: 100
7. Comparison of Proxies:
    EIP-7702 proxy code size:                 23 bytes
    EIP-1167 proxy code size:                 45 bytes
    Code Size Reduction:                   48.89 %
    EIP-7702 proxy deployment gas:         95654 gas
    EIP-1167 proxy deployment gas:        116357 gas
    Deployment Gas Reduction:              17.79 %
    EIP-7702 proxy call gas:               46008 gas
    EIP-1167 proxy call gas:               48677 gas
    Call Gas Reduction:                     5.48 %

You can switch out the implementation contract and the made calls to test your setup.