{"eip":7613,"title":"Puppet Proxy Contract","description":"A proxy that, if called by its deployer, delegates to an implementation specified in calldata.","authors":["Igor Żuk (@CodeSandwich)"],"status":"Draft","type":"Standards Track","category":"ERC","created":"2024-02-04","discussionsTo":"https://ethereum-magicians.org/t/eip-7613-puppet-proxy-contract/18482","repo":"ERCs","label":"ERC-7613","officialUrl":"https://eips.ethereum.org/EIPS/eip-7613","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7613.md","url":"https://eips.huatuo.xyz/eip-7613/","tldr":{"en":"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.","ja":"デプロイした本人以外には何もしない、ドラフトの 66 バイトのプロキシ。デプロイした本人は任意のロジックに delegatecall させられるため、プロトコルはユーザーごとの入金アドレスやサブアカウントを安価に用意できる。","ko":"배포자 외에는 누구에게도 아무것도 하지 않는 초안 66바이트 프록시. 배포자는 이것이 임의의 로직으로 delegatecall하게 만들 수 있어, 프로토콜이 사용자별 입금 주소와 하위 계정을 저렴하게 만들 수 있다.","zh":"一个草案的 66 字节代理：除了部署者之外对任何人都毫无作为，部署者可以让它 delegatecall 任意逻辑，为协议提供廉价的按用户存款地址和子账户。"},"tags":["proxy","create2","bytecode","accounts"],"explainers":{"en":{"lang":"en","tldr":"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.","tags":["proxy","create2","bytecode","accounts"],"related":[1167,20,721],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7613/","markdown":"## What problem does it solve?\n\nProtocols 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.\n\nERC-7613 defines a tiny, fixed piece of bytecode, the **puppet**, that a deployer can drive like a remote-controlled account.\n\n## How it works\n\n- 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.\n- When the **deployer** calls it, the first 32 bytes of calldata must be an ABI-encoded (zero-padded) address. The puppet `DELEGATECALL`s that address with the remaining calldata, bubbling up return data and reverts.\n- 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.\n- 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.\n\nTypical 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](/eip-1167/) clone.\n\n## Sample code\n\nDeploying a puppet per user and sweeping an ERC-20 out of it (based on the spec's helper library):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Puppet {\n    bytes internal constant CREATION_CODE =\n        hex\"604260126D60203D3D3683113D3560A01C17733D3360147F33181760405782\"\n        hex\"3603803D943D373D3D355AF43D82803E903D91604057FD5BF36034525252F3\";\n\n    function deployDeterministic(bytes32 salt) internal returns (address instance) {\n        bytes memory code = CREATION_CODE;\n        assembly { instance := create2(0, add(code, 32), mload(code), salt) }\n        require(instance != address(0), \"deploy failed\");\n    }\n\n    function delegationCalldata(address to, bytes memory data) internal pure returns (bytes memory) {\n        return abi.encodePacked(bytes32(uint256(uint160(to))), data);\n    }\n}\n\ncontract Sweeper {\n    function sweep(address token, address to) external {\n        (bool ok, ) = token.call(abi.encodeWithSignature(\"transfer(address,uint256)\", to,\n            IERC20Like(token).balanceOf(address(this))));\n        require(ok);\n    }\n}\n\ninterface IERC20Like { function balanceOf(address) external view returns (uint256); }\n\ncontract Vault {\n    Sweeper immutable sweeper = new Sweeper();\n\n    function collect(address user, address token) external {\n        address p = Puppet.deployDeterministic(bytes32(uint256(uint160(user))));\n        (bool ok, ) = p.call(Puppet.delegationCalldata(\n            address(sweeper), abi.encodeCall(Sweeper.sweep, (token, address(this)))));\n        require(ok, \"sweep failed\");\n    }\n}\n```\n\n## Things to know\n\n- Status is **Draft**.\n- Puppets cannot answer callbacks, so mechanisms that expect the recipient to expose functions, such as [ERC-721](/eip-721/) `safeTransferFrom`'s `onERC721Received`, will not work with them. Plain [ERC-20](/eip-20/) transfers work fine.\n- Whatever the deployer delegates to runs with full control over the puppet's assets. The deployer's own access control is the only protection.\n- 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`.\n- The sample deploys each puppet only once; a second `collect` for the same user would need to reuse the existing address instead of redeploying.\n"},"ja":{"lang":"ja","tldr":"デプロイした本人以外には何もしない、ドラフトの 66 バイトのプロキシ。デプロイした本人は任意のロジックに delegatecall させられるため、プロトコルはユーザーごとの入金アドレスやサブアカウントを安価に用意できる。","tags":["proxy","create2","bytecode","accounts"],"related":[1167,20,721],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7613/","markdown":"## 何を解決するのか\n\nプロトコルは、ユーザーごとに別々のアドレスを欲しがることがよくあります。誰でも approve なしでトークンを送れる入金アドレス、1 人のユーザーの残高を分けて管理するサブアカウント、まだ何もデプロイされていない段階で資金を受け取れる予測可能なアドレスなどです。そのために独自のコントラクトを書くとデプロイのコストが高く、Solidity からコンパイルすると、そのバイトコード（つまり CREATE2 アドレス）はコンパイラのバージョンによって変わってしまいます。\n\nERC-7613 は、小さく固定されたバイトコード、**puppet** を定義します。デプロイした本人は、これをリモコン操作のアカウントのように動かせます。\n\n## 仕組み\n\n- デプロイした本人以外の誰にとっても、puppet は空のアカウントのように振る舞います。ETH とトークンは受け取りますが、それ以外は何もしません。API は公開していません。\n- **デプロイした本人**が呼び出す場合、calldata の最初の 32 バイトは ABI エンコードされた（ゼロ埋めされた）アドレスでなければなりません。puppet は、そのアドレスに対して、残りの calldata で `DELEGATECALL` を行い、戻りデータと revert をそのまま伝えます。\n- 呼び出し元がデプロイした本人でない場合、calldata が 32 バイト未満の場合、または最初のワードがパディングされたアドレスでない場合、puppet は何もしません。そのため、デプロイした本人からの単なる ETH 送金も成功するだけです。\n- この動作は生のバイトコードとして定義されています。作成コードは 62 バイト、デプロイされるコードは 66 バイトで、`PUSH0` を持たないチェーン向けに `PUSH0` を避けています。どの実装も同一のバイトコードを生成するため、CREATE2 アドレスはどこでも予測可能です。\n\n典型的なパターン: プロトコルがユーザーごとに `CREATE2(salt = user)` を計算し、そこへ資金を送るよう伝えます。後でプロトコルが puppet をデプロイし、資金を移す関数に delegate させます。プロトコル自身のロジックをアップグレードすれば、すべての puppet にできることが変わり、Beacon は不要です。仕様によると、デプロイコストは約 45K gas で、[ERC-1167](/eip-1167/) のクローンより約 4K 多いだけです。\n\n## サンプルコード\n\nユーザーごとに puppet をデプロイし、そこから ERC-20 を回収する例（仕様のヘルパーライブラリに基づく）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Puppet {\n    bytes internal constant CREATION_CODE =\n        hex\"604260126D60203D3D3683113D3560A01C17733D3360147F33181760405782\"\n        hex\"3603803D943D373D3D355AF43D82803E903D91604057FD5BF36034525252F3\";\n\n    function deployDeterministic(bytes32 salt) internal returns (address instance) {\n        bytes memory code = CREATION_CODE;\n        assembly { instance := create2(0, add(code, 32), mload(code), salt) }\n        require(instance != address(0), \"deploy failed\");\n    }\n\n    function delegationCalldata(address to, bytes memory data) internal pure returns (bytes memory) {\n        return abi.encodePacked(bytes32(uint256(uint160(to))), data);\n    }\n}\n\ncontract Sweeper {\n    function sweep(address token, address to) external {\n        (bool ok, ) = token.call(abi.encodeWithSignature(\"transfer(address,uint256)\", to,\n            IERC20Like(token).balanceOf(address(this))));\n        require(ok);\n    }\n}\n\ninterface IERC20Like { function balanceOf(address) external view returns (uint256); }\n\ncontract Vault {\n    Sweeper immutable sweeper = new Sweeper();\n\n    function collect(address user, address token) external {\n        address p = Puppet.deployDeterministic(bytes32(uint256(uint160(user))));\n        (bool ok, ) = p.call(Puppet.delegationCalldata(\n            address(sweeper), abi.encodeCall(Sweeper.sweep, (token, address(this)))));\n        require(ok, \"sweep failed\");\n    }\n}\n```\n\n## 知っておくべきこと\n\n- ステータスは **Draft** です。\n- puppet はコールバックに応答できないため、受信側が関数を公開していることを期待する仕組み、たとえば [ERC-721](/eip-721/) の `safeTransferFrom` の `onERC721Received` は動作しません。通常の [ERC-20](/eip-20/) の転送は問題なく動作します。\n- デプロイした本人が delegate した先は、puppet の資産を完全に制御して実行されます。デプロイした本人側のアクセス制御だけが唯一の防御です。\n- アドレスは最初のワードに ABI エンコードされるため、第三者が任意の delegation を行わせることができるのは、デプロイした本人がセレクター `0x00000000` で puppet を呼び出した場合に限られます。\n- サンプルは各 puppet を一度だけデプロイします。同じユーザーに対して `collect` を再度呼ぶ場合は、再デプロイするのではなく既存のアドレスを再利用する必要があります。\n"},"ko":{"lang":"ko","tldr":"배포자 외에는 누구에게도 아무것도 하지 않는 초안 66바이트 프록시. 배포자는 이것이 임의의 로직으로 delegatecall하게 만들 수 있어, 프로토콜이 사용자별 입금 주소와 하위 계정을 저렴하게 만들 수 있다.","tags":["proxy","create2","bytecode","accounts"],"related":[1167,20,721],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7613/","markdown":"## 어떤 문제를 해결하나요?\n\n프로토콜은 사용자마다 별도의 주소를 원하는 경우가 많습니다. 누구나 approve 없이 토큰을 보낼 수 있는 입금 주소, 한 사용자의 잔액을 따로 보관하는 하위 계정, 아직 아무것도 배포되기 전에도 자금을 받을 수 있는 예측 가능한 주소 같은 것들입니다. 이를 위해 맞춤 컨트랙트를 작성하면 배포 비용이 크고, Solidity로 컴파일하면 바이트코드(따라서 CREATE2 주소)가 컴파일러 버전에 따라 달라집니다.\n\nERC-7613은 작고 고정된 바이트코드인 **puppet**을 정의합니다. 배포자는 이것을 원격 조종 계정처럼 움직일 수 있습니다.\n\n## 어떻게 동작하나요?\n\n- 배포자를 제외한 모두에게 puppet은 빈 계정처럼 동작합니다. ETH와 토큰을 받기만 하고 다른 일은 하지 않습니다. 어떤 API도 노출하지 않습니다.\n- **배포자**가 호출하면 calldata의 첫 32바이트는 ABI 인코딩된(0으로 패딩된) 주소여야 합니다. puppet은 나머지 calldata로 그 주소에 `DELEGATECALL`하고, 반환 데이터와 revert를 그대로 위로 전달합니다.\n- 호출자가 배포자가 아니거나, calldata가 32바이트보다 짧거나, 첫 워드가 패딩된 주소가 아니면 puppet은 아무것도 하지 않습니다. 따라서 배포자가 보내는 단순 ETH 전송도 그냥 성공합니다.\n- 이 동작은 원시 바이트코드로 정의됩니다. 생성 코드는 62바이트, 배포된 코드는 66바이트이며, `PUSH0`이 없는 체인을 위해 `PUSH0`을 쓰지 않습니다. 모든 구현이 동일한 바이트코드를 생성하므로 CREATE2 주소는 어디서나 예측 가능합니다.\n\n일반적인 패턴: 프로토콜이 사용자마다 `CREATE2(salt = user)`를 계산하고 그곳으로 자금을 보내라고 안내합니다. 나중에 프로토콜이 puppet을 배포하고 자금을 옮기는 함수로 delegate하게 합니다. 프로토콜 자체의 로직을 업그레이드하면 모든 puppet이 할 수 있는 일이 바뀌며 비콘이 필요 없습니다. 명세에 따르면 배포 비용은 약 45K gas로, [ERC-1167](/eip-1167/) 클론보다 약 4K 더 듭니다.\n\n## 샘플 코드\n\n사용자마다 puppet을 배포하고 그곳에서 ERC-20을 회수하는 예(명세의 헬퍼 라이브러리 기반):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Puppet {\n    bytes internal constant CREATION_CODE =\n        hex\"604260126D60203D3D3683113D3560A01C17733D3360147F33181760405782\"\n        hex\"3603803D943D373D3D355AF43D82803E903D91604057FD5BF36034525252F3\";\n\n    function deployDeterministic(bytes32 salt) internal returns (address instance) {\n        bytes memory code = CREATION_CODE;\n        assembly { instance := create2(0, add(code, 32), mload(code), salt) }\n        require(instance != address(0), \"deploy failed\");\n    }\n\n    function delegationCalldata(address to, bytes memory data) internal pure returns (bytes memory) {\n        return abi.encodePacked(bytes32(uint256(uint160(to))), data);\n    }\n}\n\ncontract Sweeper {\n    function sweep(address token, address to) external {\n        (bool ok, ) = token.call(abi.encodeWithSignature(\"transfer(address,uint256)\", to,\n            IERC20Like(token).balanceOf(address(this))));\n        require(ok);\n    }\n}\n\ninterface IERC20Like { function balanceOf(address) external view returns (uint256); }\n\ncontract Vault {\n    Sweeper immutable sweeper = new Sweeper();\n\n    function collect(address user, address token) external {\n        address p = Puppet.deployDeterministic(bytes32(uint256(uint160(user))));\n        (bool ok, ) = p.call(Puppet.delegationCalldata(\n            address(sweeper), abi.encodeCall(Sweeper.sweep, (token, address(this)))));\n        require(ok, \"sweep failed\");\n    }\n}\n```\n\n## 알아둘 점\n\n- 상태는 **Draft**입니다.\n- puppet은 콜백에 응답할 수 없으므로, 수신자가 함수를 노출하길 기대하는 메커니즘, 예를 들어 [ERC-721](/eip-721/) `safeTransferFrom`의 `onERC721Received`는 동작하지 않습니다. 일반 [ERC-20](/eip-20/) 전송은 문제없이 동작합니다.\n- 배포자가 delegate한 대상은 puppet의 자산에 대한 완전한 통제권을 가지고 실행됩니다. 배포자 자신의 접근 제어가 유일한 보호 장치입니다.\n- 주소는 첫 워드에 ABI 인코딩되므로, 제3자가 배포자를 속여 임의의 delegation을 하게 만들 수 있는 것은 배포자가 셀렉터 `0x00000000`으로 puppet을 호출할 때뿐입니다.\n- 샘플은 각 puppet을 한 번만 배포합니다. 같은 사용자에 대해 `collect`를 다시 호출하려면 재배포하지 말고 기존 주소를 재사용해야 합니다.\n"},"zh":{"lang":"zh","tldr":"一个草案的 66 字节代理：除了部署者之外对任何人都毫无作为，部署者可以让它 delegatecall 任意逻辑，为协议提供廉价的按用户存款地址和子账户。","tags":["proxy","create2","bytecode","accounts"],"related":[1167,20,721],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7613/","markdown":"## 它解决什么问题？\n\n协议常常希望每个用户拥有一个独立的地址：一个任何人无需授权就能向其转入代币的存款地址、一个把某个用户的余额隔离开的子账户，或是一个在那里部署任何东西之前就能接收资金的可预测地址。为此编写自定义合约，部署成本很高，而且如果用 Solidity 编译，其字节码（进而 CREATE2 地址）会随编译器版本而变化。\n\nERC-7613 定义了一小段固定的字节码，即 **puppet**，部署者可以像遥控账户一样驱动它。\n\n## 它如何运作\n\n- 对除部署者之外的所有人，puppet 表现得像一个空账户：它接受 ETH 和代币，别无其他作为。它不暴露任何 API。\n- 当**部署者**调用它时，calldata 的前 32 字节必须是经 ABI 编码（补零）的地址。puppet 会用剩余的 calldata 对该地址执行 `DELEGATECALL`，并把返回数据和 revert 原样向上传递。\n- 如果调用者不是部署者，或者 calldata 不足 32 字节，或者第一个字不是补零后的地址，puppet 什么也不做。因此部署者发来的普通 ETH 转账也只是直接成功。\n- 其行为以原始字节码的形式定义。创建代码为 62 字节，部署后的代码为 66 字节；为了兼容没有 `PUSH0` 的链，它避免使用 `PUSH0`。每种实现都会生成完全相同的字节码，因此 CREATE2 地址在任何地方都是可预测的。\n\n典型模式：协议为每个用户计算 `CREATE2(salt = user)`，并告诉他们把资金发到那里。之后协议部署 puppet，并让它 delegate 到一个转移资金的函数。升级协议自己的逻辑，就会改变它所有 puppet 能做的事，无需信标。根据规范，部署成本约为 45K gas，比 [ERC-1167](/eip-1167/) 克隆多约 4K。\n\n## 示例代码\n\n为每个用户部署一个 puppet，并从中清扫出 ERC-20（基于规范中的辅助库）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Puppet {\n    bytes internal constant CREATION_CODE =\n        hex\"604260126D60203D3D3683113D3560A01C17733D3360147F33181760405782\"\n        hex\"3603803D943D373D3D355AF43D82803E903D91604057FD5BF36034525252F3\";\n\n    function deployDeterministic(bytes32 salt) internal returns (address instance) {\n        bytes memory code = CREATION_CODE;\n        assembly { instance := create2(0, add(code, 32), mload(code), salt) }\n        require(instance != address(0), \"deploy failed\");\n    }\n\n    function delegationCalldata(address to, bytes memory data) internal pure returns (bytes memory) {\n        return abi.encodePacked(bytes32(uint256(uint160(to))), data);\n    }\n}\n\ncontract Sweeper {\n    function sweep(address token, address to) external {\n        (bool ok, ) = token.call(abi.encodeWithSignature(\"transfer(address,uint256)\", to,\n            IERC20Like(token).balanceOf(address(this))));\n        require(ok);\n    }\n}\n\ninterface IERC20Like { function balanceOf(address) external view returns (uint256); }\n\ncontract Vault {\n    Sweeper immutable sweeper = new Sweeper();\n\n    function collect(address user, address token) external {\n        address p = Puppet.deployDeterministic(bytes32(uint256(uint160(user))));\n        (bool ok, ) = p.call(Puppet.delegationCalldata(\n            address(sweeper), abi.encodeCall(Sweeper.sweep, (token, address(this)))));\n        require(ok, \"sweep failed\");\n    }\n}\n```\n\n## 需要注意\n\n- 状态为 **Draft**。\n- puppet 无法响应回调，因此那些期望接收方暴露函数的机制，例如 [ERC-721](/eip-721/) `safeTransferFrom` 的 `onERC721Received`，对它们不起作用。普通的 [ERC-20](/eip-20/) 转账则没有问题。\n- 部署者 delegate 到的任何代码，都会以对 puppet 资产的完全控制权运行。部署者自己的访问控制是唯一的保护。\n- 地址是以 ABI 编码放在第一个字中的，因此只有当部署者以选择器 `0x00000000` 调用 puppet 时，第三方才有可能诱使部署者进行任意 delegation。\n- 示例中每个 puppet 只部署一次；对同一用户再次 `collect` 时，需要复用现有地址，而不是重新部署。\n"}}}
