{"eip":3448,"title":"MetaProxy Standard","description":"A minimal bytecode implementation for creating proxy contracts with immutable metadata attached to the bytecode","authors":["pinkiebell (@pinkiebell)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2021-03-29","discussionsTo":"https://ethereum-magicians.org/t/erc-3448-metaproxy-factory/5834","repo":"ERCs","label":"ERC-3448","officialUrl":"https://eips.ethereum.org/EIPS/eip-3448","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-3448.md","url":"https://eips.huatuo.xyz/eip-3448/","tldr":{"en":"A minimal DELEGATECALL proxy whose bytecode ends with immutable metadata that gets appended to every call's calldata, giving cheap clones with per-instance parameters and no storage reads.","ja":"バイトコードの末尾に不変のメタデータを持ち、それがすべての呼び出しの calldata に追加される最小限の DELEGATECALL プロキシ。ストレージ読み取りなしで、インスタンスごとのパラメータを持つ安価なクローンを実現する。","ko":"바이트코드 끝에 불변 메타데이터를 두고 이를 모든 호출의 calldata에 덧붙이는 최소 DELEGATECALL 프록시. 스토리지 읽기 없이 인스턴스별 파라미터를 가진 저렴한 클론을 만든다.","zh":"一种最小化的 DELEGATECALL 代理，其字节码末尾带有不可变元数据，每次调用时都会附加到 calldata 上，从而以廉价的克隆实现每个实例各自的参数，且无需读取存储。"},"tags":["proxy","clones","bytecode","gas","factory"],"explainers":{"en":{"lang":"en","tldr":"A minimal DELEGATECALL proxy whose bytecode ends with immutable metadata that gets appended to every call's calldata, giving cheap clones with per-instance parameters and no storage reads.","tags":["proxy","clones","bytecode","gas","factory"],"related":[1167],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3448/","markdown":"## What problem does it solve?\n\nFactories often deploy many copies of the same logic with different parameters: one vault per token, one pool per pair. [ERC-1167](/eip-1167/) minimal proxies make the copies cheap, but every instance then has to store its parameters in storage via an `init` call and read them back with `SLOAD` on every use.\n\nERC-3448 (MetaProxy) puts those parameters in the proxy's **bytecode** instead. They are fixed at deploy time, cost nothing to read from storage, and tools like block explorers can recognise the proxy and show its target and metadata.\n\n## How it works\n\nThe proxy is a fixed 54-byte runtime code with the target address patched in:\n\n```\n363d3d373d3d3d3d60368038038091363936013d73\u003c20-byte target\u003e5af43d3d93803e603457fd5bf3\n```\n\nAfter those 54 bytes comes arbitrary metadata, and the **last 32 bytes** of the code hold the metadata length:\n\n```\n\u003c54 bytes MetaProxy\u003e \u003cmetadata\u003e \u003cuint256 metadata length\u003e\n```\n\nOn every call the proxy:\n\n1. Copies the incoming calldata to memory.\n2. Copies everything after the 54-byte header (metadata plus its length word) right after it.\n3. `DELEGATECALL`s the target with that combined buffer.\n4. Returns or reverts with the target's return data.\n\nSo inside the implementation, the last 32 bytes of `calldata` are the metadata length, and the metadata sits just before them. Revert reasons bubble up unchanged.\n\n## Sample code\n\nReading the metadata inside the implementation contract (adapted from the spec's examples):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// Decodes metadata appended by the MetaProxy to the calldata.\n    function _metadata() internal pure returns (address token, uint256 fee) {\n        bytes memory data;\n        assembly {\n            let posOfSize := sub(calldatasize(), 32)\n            let size := calldataload(posOfSize)\n            let start := sub(posOfSize, size)\n            data := mload(0x40)\n            mstore(0x40, add(data, add(size, 32)))\n            mstore(data, size)\n            calldatacopy(add(data, 32), start, size)\n        }\n        return abi.decode(data, (address, uint256));\n    }\n\n    function feeBps() external pure returns (uint256 fee) {\n        (, fee) = _metadata();\n    }\n}\n```\n\nA factory would deploy a proxy for each instance with metadata `abi.encode(token, fee)`. The spec's reference `MetaProxyFactory` provides helpers like `_metaProxyFromBytes(target, bytes)`.\n\n## Things to know\n\n- Status is **Final**.\n- Because metadata is appended to calldata, functions in the implementation see extra trailing bytes. Normal ABI decoding ignores them, but code that checks `msg.data.length` or uses raw calldata must account for it.\n- Calling the implementation contract directly (not through a proxy) means there is no metadata, so `_metadata()` would read garbage. Guard against direct use where it matters.\n- Metadata is immutable. Anything that must change later still belongs in storage.\n- The spec says its reference implementation is only an example; research the side effects for your design and get it audited.\n"},"ja":{"lang":"ja","tldr":"バイトコードの末尾に不変のメタデータを持ち、それがすべての呼び出しの calldata に追加される最小限の DELEGATECALL プロキシ。ストレージ読み取りなしで、インスタンスごとのパラメータを持つ安価なクローンを実現する。","tags":["proxy","clones","bytecode","gas","factory"],"related":[1167],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3448/","markdown":"## 何を解決するのか\n\nファクトリーは、同じロジックのコピーを異なるパラメータで多数デプロイすることがよくあります。トークンごとに 1 つの vault、ペアごとに 1 つのプール、といった具合です。[ERC-1167](/eip-1167/) の最小プロキシはコピーを安価にしますが、その場合、各インスタンスは `init` 呼び出しでパラメータをストレージに保存し、使うたびに `SLOAD` で読み戻す必要があります。\n\nERC-3448（MetaProxy）は、それらのパラメータをプロキシの**バイトコード**に置きます。デプロイ時に固定され、ストレージからの読み取りにコストがかからず、ブロックエクスプローラーなどのツールはプロキシを認識して、そのターゲットとメタデータを表示できます。\n\n## 仕組み\n\nプロキシは、ターゲットアドレスを埋め込む固定の 54 バイトのランタイムコードです。\n\n```\n363d3d373d3d3d3d60368038038091363936013d73\u003c20-byte target\u003e5af43d3d93803e603457fd5bf3\n```\n\nこの 54 バイトの後に任意のメタデータが続き、コードの**最後の 32 バイト**にメタデータの長さが入ります。\n\n```\n\u003c54 bytes MetaProxy\u003e \u003cmetadata\u003e \u003cuint256 metadata length\u003e\n```\n\nプロキシは呼び出しのたびに次を行います。\n\n1. 受け取った calldata をメモリにコピーする。\n2. 54 バイトのヘッダーより後ろのすべて（メタデータとその長さのワード）を、その直後にコピーする。\n3. その結合したバッファを使ってターゲットを `DELEGATECALL` する。\n4. ターゲットの戻りデータで return または revert する。\n\nつまり実装コントラクトの内部では、`calldata` の最後の 32 バイトがメタデータの長さで、メタデータはその直前に置かれます。revert の理由はそのまま伝わります。\n\n## サンプルコード\n\n実装コントラクト内でメタデータを読む（仕様の例を改変）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// Decodes metadata appended by the MetaProxy to the calldata.\n    function _metadata() internal pure returns (address token, uint256 fee) {\n        bytes memory data;\n        assembly {\n            let posOfSize := sub(calldatasize(), 32)\n            let size := calldataload(posOfSize)\n            let start := sub(posOfSize, size)\n            data := mload(0x40)\n            mstore(0x40, add(data, add(size, 32)))\n            mstore(data, size)\n            calldatacopy(add(data, 32), start, size)\n        }\n        return abi.decode(data, (address, uint256));\n    }\n\n    function feeBps() external pure returns (uint256 fee) {\n        (, fee) = _metadata();\n    }\n}\n```\n\nファクトリーは、メタデータ `abi.encode(token, fee)` を持つプロキシをインスタンスごとにデプロイします。仕様のリファレンス実装 `MetaProxyFactory` には、`_metaProxyFromBytes(target, bytes)` のようなヘルパーがあります。\n\n## 知っておくべきこと\n\n- ステータスは **Final** です。\n- メタデータは calldata に追加されるため、実装側の関数は末尾に余分なバイトを見ます。通常の ABI デコードはそれを無視しますが、`msg.data.length` を確認したり生の calldata を使ったりするコードは、それを考慮する必要があります。\n- 実装コントラクトを（プロキシを経由せず）直接呼び出すとメタデータがないため、`_metadata()` は無意味な値を読みます。重要な場面では直接の使用を防いでください。\n- メタデータは不変です。後で変更が必要なものは、やはりストレージに置くべきです。\n- 仕様は、そのリファレンス実装はあくまで例であり、自分の設計での副作用を調べ、監査を受けるよう述べています。\n"},"ko":{"lang":"ko","tldr":"바이트코드 끝에 불변 메타데이터를 두고 이를 모든 호출의 calldata에 덧붙이는 최소 DELEGATECALL 프록시. 스토리지 읽기 없이 인스턴스별 파라미터를 가진 저렴한 클론을 만든다.","tags":["proxy","clones","bytecode","gas","factory"],"related":[1167],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3448/","markdown":"## 어떤 문제를 해결하나요?\n\n팩토리는 같은 로직의 복사본을 서로 다른 파라미터로 많이 배포하는 경우가 흔합니다. 토큰마다 vault 하나, 페어마다 풀 하나 같은 식입니다. [ERC-1167](/eip-1167/) 최소 프록시는 복사본을 저렴하게 만들지만, 그러면 각 인스턴스가 `init` 호출로 파라미터를 스토리지에 저장하고 쓸 때마다 `SLOAD`로 다시 읽어야 합니다.\n\nERC-3448(MetaProxy)은 그 파라미터를 프록시의 **바이트코드**에 넣습니다. 배포 시점에 고정되고, 스토리지에서 읽는 비용이 들지 않으며, 블록 탐색기 같은 도구가 프록시를 알아보고 대상과 메타데이터를 보여 줄 수 있습니다.\n\n## 어떻게 동작하나요?\n\n프록시는 대상 주소가 채워지는 고정된 54바이트 런타임 코드입니다.\n\n```\n363d3d373d3d3d3d60368038038091363936013d73\u003c20-byte target\u003e5af43d3d93803e603457fd5bf3\n```\n\n이 54바이트 뒤에는 임의의 메타데이터가 오고, 코드의 **마지막 32바이트**에는 메타데이터 길이가 들어 있습니다.\n\n```\n\u003c54 bytes MetaProxy\u003e \u003cmetadata\u003e \u003cuint256 metadata length\u003e\n```\n\n프록시는 호출할 때마다 다음을 수행합니다.\n\n1. 들어온 calldata를 메모리에 복사합니다.\n2. 54바이트 헤더 뒤의 모든 내용(메타데이터와 그 길이 워드)을 그 바로 뒤에 복사합니다.\n3. 합쳐진 버퍼로 대상을 `DELEGATECALL`합니다.\n4. 대상의 반환 데이터로 return하거나 revert합니다.\n\n따라서 구현 컨트랙트 안에서 `calldata`의 마지막 32바이트는 메타데이터 길이이고, 메타데이터는 그 바로 앞에 놓입니다. revert 사유는 그대로 전달됩니다.\n\n## 샘플 코드\n\n구현 컨트랙트 안에서 메타데이터 읽기(스펙의 예제를 변형):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// Decodes metadata appended by the MetaProxy to the calldata.\n    function _metadata() internal pure returns (address token, uint256 fee) {\n        bytes memory data;\n        assembly {\n            let posOfSize := sub(calldatasize(), 32)\n            let size := calldataload(posOfSize)\n            let start := sub(posOfSize, size)\n            data := mload(0x40)\n            mstore(0x40, add(data, add(size, 32)))\n            mstore(data, size)\n            calldatacopy(add(data, 32), start, size)\n        }\n        return abi.decode(data, (address, uint256));\n    }\n\n    function feeBps() external pure returns (uint256 fee) {\n        (, fee) = _metadata();\n    }\n}\n```\n\n팩토리는 인스턴스마다 메타데이터 `abi.encode(token, fee)`를 가진 프록시를 배포합니다. 스펙의 레퍼런스 `MetaProxyFactory`는 `_metaProxyFromBytes(target, bytes)` 같은 헬퍼를 제공합니다.\n\n## 알아둘 점\n\n- 상태는 **Final**입니다.\n- 메타데이터가 calldata에 덧붙기 때문에 구현 안의 함수는 끝에 추가 바이트가 붙은 것을 보게 됩니다. 일반적인 ABI 디코딩은 이를 무시하지만, `msg.data.length`를 확인하거나 원시 calldata를 사용하는 코드는 이를 고려해야 합니다.\n- 구현 컨트랙트를 (프록시를 거치지 않고) 직접 호출하면 메타데이터가 없으므로 `_metadata()`는 쓰레기 값을 읽게 됩니다. 중요한 곳에서는 직접 사용을 막으세요.\n- 메타데이터는 불변입니다. 나중에 바뀌어야 하는 것은 여전히 스토리지에 두어야 합니다.\n- 스펙은 레퍼런스 구현이 예시일 뿐이라고 밝힙니다. 자신의 설계에 미치는 부작용을 조사하고 감사를 받으세요.\n"},"zh":{"lang":"zh","tldr":"一种最小化的 DELEGATECALL 代理，其字节码末尾带有不可变元数据，每次调用时都会附加到 calldata 上，从而以廉价的克隆实现每个实例各自的参数，且无需读取存储。","tags":["proxy","clones","bytecode","gas","factory"],"related":[1167],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3448/","markdown":"## 它解决什么问题？\n\n工厂合约经常用不同参数部署同一套逻辑的许多副本：每种代币一个金库，每个交易对一个池子。[ERC-1167](/eip-1167/) 最小代理让这些副本很便宜，但每个实例随后都要通过 `init` 调用把参数存进存储，并在每次使用时用 `SLOAD` 读回来。\n\nERC-3448（MetaProxy）把这些参数放进代理的**字节码**中。它们在部署时固定，读取时无需访问存储，区块浏览器等工具也能识别该代理并显示它的目标和元数据。\n\n## 它如何运作\n\n代理是固定的 54 字节运行时代码，目标地址会被填入其中：\n\n```\n363d3d373d3d3d3d60368038038091363936013d73\u003c20-byte target\u003e5af43d3d93803e603457fd5bf3\n```\n\n这 54 字节之后是任意元数据，代码的**最后 32 字节**保存元数据长度：\n\n```\n\u003c54 bytes MetaProxy\u003e \u003cmetadata\u003e \u003cuint256 metadata length\u003e\n```\n\n每次调用时，代理会：\n\n1. 把传入的 calldata 复制到内存。\n2. 把 54 字节头部之后的所有内容（元数据及其长度字）紧接着复制到后面。\n3. 用合并后的缓冲区对目标执行 `DELEGATECALL`。\n4. 以目标的返回数据返回或回滚。\n\n因此在实现合约内部，`calldata` 的最后 32 字节是元数据长度，元数据就位于它们之前。revert 原因会原样向上传递。\n\n## 示例代码\n\n在实现合约内部读取元数据（改编自规范中的示例）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// Decodes metadata appended by the MetaProxy to the calldata.\n    function _metadata() internal pure returns (address token, uint256 fee) {\n        bytes memory data;\n        assembly {\n            let posOfSize := sub(calldatasize(), 32)\n            let size := calldataload(posOfSize)\n            let start := sub(posOfSize, size)\n            data := mload(0x40)\n            mstore(0x40, add(data, add(size, 32)))\n            mstore(data, size)\n            calldatacopy(add(data, 32), start, size)\n        }\n        return abi.decode(data, (address, uint256));\n    }\n\n    function feeBps() external pure returns (uint256 fee) {\n        (, fee) = _metadata();\n    }\n}\n```\n\n工厂会为每个实例部署一个代理，元数据为 `abi.encode(token, fee)`。规范中的参考 `MetaProxyFactory` 提供了 `_metaProxyFromBytes(target, bytes)` 之类的辅助函数。\n\n## 需要注意\n\n- 状态为 **Final**。\n- 由于元数据被附加到 calldata，实现中的函数会看到末尾多出的字节。常规的 ABI 解码会忽略它们，但检查 `msg.data.length` 或使用原始 calldata 的代码必须将其考虑在内。\n- 直接调用实现合约（而非通过代理）意味着没有元数据，因此 `_metadata()` 会读到垃圾数据。在重要的地方要防范直接使用。\n- 元数据是不可变的。之后需要更改的内容仍应放在存储中。\n- 规范称其参考实现只是一个示例；请针对你的设计研究其副作用，并进行审计。\n"}}}
