EIPs Explained

ERC-7613 · Draft · ERC · 2024-02-04

ERC-7613: Puppet Proxy Contract

A draft 66-byte proxy that does nothing for anyone except its deployer, who can make it delegatecall any logic, giving protocols cheap per-user deposit addresses and sub-accounts.

What problem does it solve?

Protocols often want a separate address per user: a deposit address that anyone can send tokens to without approvals, a sub-account that keeps one user's balances apart, or a predictable address that can receive funds before anything is deployed there. Writing a custom contract for this is costly to deploy and, if compiled from Solidity, its bytecode (and therefore its CREATE2 address) changes with compiler versions.

ERC-7613 defines a tiny, fixed piece of bytecode, the puppet, that a deployer can drive like a remote-controlled account.

How it works

  • To everyone except its deployer, a puppet behaves like an empty account: it accepts ETH and tokens and does nothing else. It exposes no API.
  • When the deployer calls it, the first 32 bytes of calldata must be an ABI-encoded (zero-padded) address. The puppet DELEGATECALLs that address with the remaining calldata, bubbling up return data and reverts.
  • If the caller is not the deployer, calldata is shorter than 32 bytes, or the first word is not a padded address, the puppet does nothing. So plain ETH transfers from the deployer also just succeed.
  • The behaviour is defined as raw bytecode. Creation code is 62 bytes and deployed code 66 bytes; it avoids PUSH0 for chains that lack it. Every implementation produces identical bytecode, so CREATE2 addresses are predictable everywhere.

Typical pattern: a protocol computes CREATE2(salt = user) for each user and tells them to send funds there. Later the protocol deploys the puppet and makes it delegate to a function that moves the funds. Upgrading the protocol's own logic changes what all its puppets can do, with no beacon needed. According to the spec, deployment costs about 45K gas, roughly 4K more than an ERC-1167 clone.

Sample code

Deploying a puppet per user and sweeping an ERC-20 out of it (based on the spec's helper library):

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

library Puppet {
    bytes internal constant CREATION_CODE =
        hex"604260126D60203D3D3683113D3560A01C17733D3360147F33181760405782"
        hex"3603803D943D373D3D355AF43D82803E903D91604057FD5BF36034525252F3";

    function deployDeterministic(bytes32 salt) internal returns (address instance) {
        bytes memory code = CREATION_CODE;
        assembly { instance := create2(0, add(code, 32), mload(code), salt) }
        require(instance != address(0), "deploy failed");
    }

    function delegationCalldata(address to, bytes memory data) internal pure returns (bytes memory) {
        return abi.encodePacked(bytes32(uint256(uint160(to))), data);
    }
}

contract Sweeper {
    function sweep(address token, address to) external {
        (bool ok, ) = token.call(abi.encodeWithSignature("transfer(address,uint256)", to,
            IERC20Like(token).balanceOf(address(this))));
        require(ok);
    }
}

interface IERC20Like { function balanceOf(address) external view returns (uint256); }

contract Vault {
    Sweeper immutable sweeper = new Sweeper();

    function collect(address user, address token) external {
        address p = Puppet.deployDeterministic(bytes32(uint256(uint160(user))));
        (bool ok, ) = p.call(Puppet.delegationCalldata(
            address(sweeper), abi.encodeCall(Sweeper.sweep, (token, address(this)))));
        require(ok, "sweep failed");
    }
}

Things to know

  • Status is Draft.
  • Puppets cannot answer callbacks, so mechanisms that expect the recipient to expose functions, such as ERC-721 safeTransferFrom's onERC721Received, will not work with them. Plain ERC-20 transfers work fine.
  • Whatever the deployer delegates to runs with full control over the puppet's assets. The deployer's own access control is the only protection.
  • The address is ABI-encoded in the first word, so a third party can only trick the deployer into an arbitrary delegation if the deployer calls the puppet with selector 0x00000000.
  • The sample deploys each puppet only once; a second collect for the same user would need to reuse the existing address instead of redeploying.

#proxy #create2 #bytecode #accounts

Details

Authors
Igor Żuk (@CodeSandwich)
Status
Draft
Type
Standards Track / ERC
Created
2024-02-04

Machine-readable: Markdown · JSON