{"eip":8167,"title":"Modular Dispatch Proxies","description":"Proxy-level function dispatch via delegatecall","authors":["William Morriss (@wjmelements)","Radek Svarz (@radeksvarz)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2026-02-16","discussionsTo":"https://ethereum-magicians.org/t/erc-8167-modular-dispatch-proxies/27781","repo":"ERCs","label":"ERC-8167","officialUrl":"https://eips.ethereum.org/EIPS/eip-8167","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8167.md","url":"https://eips.huatuo.xyz/eip-8167/","tldr":{"en":"A minimal standard for proxies that route each function selector to its own logic module via delegatecall, with two view functions so tools can discover the proxy's ABI and upgrade history.","ja":"関数セレクターごとに専用のロジックモジュールへ delegatecall でルーティングするプロキシのための最小限の標準。ツールがプロキシの ABI とアップグレード履歴を調べられるよう、2 つの view 関数を備える。","ko":"함수 셀렉터마다 전용 로직 모듈로 delegatecall 해 라우팅하는 프록시를 위한 최소한의 표준. 도구가 프록시의 ABI와 업그레이드 이력을 알아낼 수 있도록 view 함수 두 개를 둔다.","zh":"一个最小化的代理标准：通过 delegatecall 把每个函数选择器路由到各自的逻辑模块，并提供两个 view 函数，让工具能够发现代理的 ABI 和升级历史。"},"tags":["proxy","upgradeability","delegatecall","modular","standard"],"explainers":{"en":{"lang":"en","tldr":"A minimal standard for proxies that route each function selector to its own logic module via delegatecall, with two view functions so tools can discover the proxy's ABI and upgrade history.","tags":["proxy","upgradeability","delegatecall","modular","standard"],"related":[2535,7201,8042,7702,8349],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-8167/","markdown":"## What problem does it solve?\n\nMost proxy contracts forward every call to a single implementation contract. That works, but has limits:\n\n- A big monolithic implementation can hit the contract code size limit.\n- Upgrading means swapping the whole implementation at once, which is risky and hard to verify.\n- Contracts that share most of their logic (say, two tokens with the same balance code but different metadata) still need fully separate implementations.\n\nThe alternative, routing different functions to different logic contracts, already exists in [ERC-2535](/eip-2535/) \"Diamonds\". ERC-8167 standardizes the same idea with a much smaller surface and without the diamond terminology, so explorers, wallets and indexers can reliably work out what such a proxy does.\n\n## How it works\n\n- A **dispatch proxy** reads the first four bytes of calldata (the function selector), looks up the **delegate** (logic module) registered for it, and `delegatecall`s that delegate with the full calldata.\n- Two view functions are **required**:\n  - `implementation(bytes4 selector)` returns the delegate for a selector, or `address(0)` if none.\n  - `selectors()` returns all selectors that have an implementation.\n- **Recommended:** emit `SelectorDelegated(selector, delegate)` whenever a mapping changes (`address(0)` means removed), and revert with `FunctionNotFound(selector)` for unknown selectors.\n- The introspection functions should themselves be implemented by delegates, not hard-coded in the proxy, and the constructor should install at least one delegate.\n\nThe standard deliberately does **not** define an upgrade function or a storage layout; those are left to implementations or later standards. Removing the upgrade selectors turns an upgradeable proxy into an immutable one.\n\nTo rebuild a proxy's ABI, a tool calls `selectors()`, maps each to `implementation(selector)`, and pulls the verified ABI of each unique delegate.\n\n## Sample code\n\nThe interface and a bare-bones dispatch fallback (no admin logic, illustration only):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC8167 {\n    event SelectorDelegated(bytes4 indexed selector, address indexed delegate);\n    error FunctionNotFound(bytes4 selector);\n    function implementation(bytes4 selector) external view returns (address);\n    function selectors() external view returns (bytes4[] memory);\n}\n\ncontract DispatchProxy {\n    mapping(bytes4 =\u003e address) internal delegates; // use a namespaced slot in practice\n\n    fallback() external payable {\n        address target = delegates[msg.sig];\n        if (target == address(0)) revert IERC8167.FunctionNotFound(msg.sig);\n        assembly {\n            calldatacopy(0, 0, calldatasize())\n            let ok := delegatecall(gas(), target, 0, calldatasize(), 0, 0)\n            returndatacopy(0, 0, returndatasize())\n            if iszero(ok) { revert(0, returndatasize()) }\n            return(0, returndatasize())\n        }\n    }\n}\n```\n\n## Things to know\n\n- **Status: Final.**\n- Upgrade functions need access control; the standard leaves the design to you.\n- Delegates should never be able to self-destruct, or they can break every proxy using them.\n- All delegates share the proxy's storage. Use one common base storage layout, or namespaced storage such as [ERC-7201](/eip-7201/) or [ERC-8042](/eip-8042/), to avoid collisions.\n- Existing single-implementation proxies can migrate by populating a selector-to-delegate map and then switching to a dispatch implementation. Modular designs also suit [EIP-7702](/eip-7702/) delegated EOAs.\n- A related draft, [ERC-8349](/eip-8349/), explores an index-based variant of the multi-facet proxy.\n"},"ja":{"lang":"ja","tldr":"関数セレクターごとに専用のロジックモジュールへ delegatecall でルーティングするプロキシのための最小限の標準。ツールがプロキシの ABI とアップグレード履歴を調べられるよう、2 つの view 関数を備える。","tags":["proxy","upgradeability","delegatecall","modular","standard"],"related":[2535,7201,8042,7702,8349],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-8167/","markdown":"## 何を解決するのか\n\nほとんどのプロキシコントラクトは、すべての呼び出しを 1 つの実装コントラクトに転送します。それでも動作はしますが、限界があります。\n\n- 大きな単一の実装は、コントラクトコードサイズの上限に達することがあります。\n- アップグレードは実装全体を一度に差し替えることを意味し、リスクが高く検証も困難です。\n- ロジックの大半を共有するコントラクト（たとえば、残高のコードは同じでメタデータだけが異なる 2 つのトークン）でも、完全に別々の実装が必要です。\n\n関数ごとに異なるロジックコントラクトへルーティングするという代替策は、[ERC-2535](/eip-2535/)「Diamonds」としてすでに存在します。ERC-8167 は同じ考え方を、はるかに小さな表面積で、diamond 用語を使わずに標準化します。これにより、エクスプローラー、ウォレット、インデクサーが、そうしたプロキシが何をするのかを確実に把握できます。\n\n## 仕組み\n\n- **ディスパッチプロキシ** は、calldata の先頭 4 バイト（関数セレクター）を読み、それに登録された **delegate**（ロジックモジュール）を調べ、完全な calldata でその delegate に `delegatecall` します。\n- 2 つの view 関数が**必須**です。\n  - `implementation(bytes4 selector)` は、セレクターに対応する delegate を返し、なければ `address(0)` を返します。\n  - `selectors()` は、実装を持つすべてのセレクターを返します。\n- **推奨:** マッピングが変わるたびに `SelectorDelegated(selector, delegate)` を emit し（`address(0)` は削除を意味します）、未知のセレクターには `FunctionNotFound(selector)` で revert します。\n- イントロスペクション関数は、プロキシにハードコードせず、delegate 自身が実装すべきであり、コンストラクターは少なくとも 1 つの delegate をインストールすべきです。\n\nこの標準は、アップグレード関数もストレージレイアウトも意図的に定義**しません**。それらは実装や後続の標準に委ねられます。アップグレード用のセレクターを取り除くと、アップグレード可能なプロキシが不変（immutable）なプロキシになります。\n\nプロキシの ABI を再構築するには、ツールが `selectors()` を呼び、それぞれを `implementation(selector)` に対応付け、ユニークな delegate ごとに検証済みの ABI を取得します。\n\n## サンプルコード\n\nインターフェースと、最小限のディスパッチ fallback（管理ロジックなし、説明用）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC8167 {\n    event SelectorDelegated(bytes4 indexed selector, address indexed delegate);\n    error FunctionNotFound(bytes4 selector);\n    function implementation(bytes4 selector) external view returns (address);\n    function selectors() external view returns (bytes4[] memory);\n}\n\ncontract DispatchProxy {\n    mapping(bytes4 =\u003e address) internal delegates; // use a namespaced slot in practice\n\n    fallback() external payable {\n        address target = delegates[msg.sig];\n        if (target == address(0)) revert IERC8167.FunctionNotFound(msg.sig);\n        assembly {\n            calldatacopy(0, 0, calldatasize())\n            let ok := delegatecall(gas(), target, 0, calldatasize(), 0, 0)\n            returndatacopy(0, 0, returndatasize())\n            if iszero(ok) { revert(0, returndatasize()) }\n            return(0, returndatasize())\n        }\n    }\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Final。**\n- アップグレード関数にはアクセス制御が必要です。この標準は設計をあなたに任せています。\n- delegate は自己破壊できてはなりません。できてしまうと、それを使うすべてのプロキシを壊す可能性があります。\n- すべての delegate はプロキシのストレージを共有します。衝突を避けるため、共通のベースストレージレイアウトを 1 つ使うか、[ERC-7201](/eip-7201/) や [ERC-8042](/eip-8042/) のような名前空間付きストレージを使ってください。\n- 既存の単一実装のプロキシは、セレクターから delegate へのマップを作成してから、ディスパッチ実装に切り替えることで移行できます。モジュラーな設計は、[EIP-7702](/eip-7702/) で委任された EOA にも適しています。\n- 関連するドラフトの [ERC-8349](/eip-8349/) は、マルチファセットプロキシのインデックスベースのバリアントを探っています。\n"},"ko":{"lang":"ko","tldr":"함수 셀렉터마다 전용 로직 모듈로 delegatecall 해 라우팅하는 프록시를 위한 최소한의 표준. 도구가 프록시의 ABI와 업그레이드 이력을 알아낼 수 있도록 view 함수 두 개를 둔다.","tags":["proxy","upgradeability","delegatecall","modular","standard"],"related":[2535,7201,8042,7702,8349],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-8167/","markdown":"## 어떤 문제를 해결하나요?\n\n대부분의 프록시 컨트랙트는 모든 호출을 하나의 구현 컨트랙트로 전달합니다. 동작은 하지만 한계가 있습니다.\n\n- 큰 단일 구현은 컨트랙트 코드 크기 제한에 걸릴 수 있습니다.\n- 업그레이드는 구현 전체를 한 번에 교체하는 것이라 위험하고 검증하기도 어렵습니다.\n- 로직 대부분을 공유하는 컨트랙트(예: 잔액 코드는 같고 메타데이터만 다른 두 토큰)도 완전히 별개의 구현이 필요합니다.\n\n함수마다 다른 로직 컨트랙트로 라우팅하는 대안은 이미 [ERC-2535](/eip-2535/) \"Diamonds\"에 있습니다. ERC-8167은 같은 아이디어를 훨씬 작은 표면적으로, diamond 용어 없이 표준화해서 익스플로러, 지갑, 인덱서가 이런 프록시가 무엇을 하는지 안정적으로 파악할 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n- **디스패치 프록시**는 calldata의 첫 4바이트(함수 셀렉터)를 읽고, 그에 등록된 **delegate**(로직 모듈)를 찾아, 전체 calldata로 그 delegate에 `delegatecall`합니다.\n- 두 개의 view 함수가 **필수**입니다.\n  - `implementation(bytes4 selector)`는 셀렉터에 대한 delegate를 반환하며, 없으면 `address(0)`을 반환합니다.\n  - `selectors()`는 구현이 있는 모든 셀렉터를 반환합니다.\n- **권장:** 매핑이 바뀔 때마다 `SelectorDelegated(selector, delegate)`를 emit하고(`address(0)`은 제거를 의미), 알 수 없는 셀렉터에는 `FunctionNotFound(selector)`로 revert합니다.\n- 인트로스펙션 함수는 프록시에 하드코딩하지 말고 delegate가 구현해야 하며, 생성자는 최소 하나의 delegate를 설치해야 합니다.\n\n이 표준은 업그레이드 함수나 스토리지 레이아웃을 의도적으로 정의하지 **않습니다**. 이는 구현이나 이후의 표준에 맡깁니다. 업그레이드 셀렉터를 제거하면 업그레이드 가능한 프록시가 불변(immutable) 프록시가 됩니다.\n\n프록시의 ABI를 재구성하려면 도구가 `selectors()`를 호출하고, 각 셀렉터를 `implementation(selector)`에 매핑한 뒤, 고유한 delegate마다 검증된 ABI를 가져옵니다.\n\n## 샘플 코드\n\n인터페이스와 최소한의 디스패치 fallback(관리 로직 없음, 설명용):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC8167 {\n    event SelectorDelegated(bytes4 indexed selector, address indexed delegate);\n    error FunctionNotFound(bytes4 selector);\n    function implementation(bytes4 selector) external view returns (address);\n    function selectors() external view returns (bytes4[] memory);\n}\n\ncontract DispatchProxy {\n    mapping(bytes4 =\u003e address) internal delegates; // use a namespaced slot in practice\n\n    fallback() external payable {\n        address target = delegates[msg.sig];\n        if (target == address(0)) revert IERC8167.FunctionNotFound(msg.sig);\n        assembly {\n            calldatacopy(0, 0, calldatasize())\n            let ok := delegatecall(gas(), target, 0, calldatasize(), 0, 0)\n            returndatacopy(0, 0, returndatasize())\n            if iszero(ok) { revert(0, returndatasize()) }\n            return(0, returndatasize())\n        }\n    }\n}\n```\n\n## 알아둘 점\n\n- **상태: Final.**\n- 업그레이드 함수에는 접근 제어가 필요합니다. 이 표준은 설계를 여러분에게 맡깁니다.\n- delegate는 절대 자기 파괴할 수 없어야 합니다. 그렇지 않으면 그것을 쓰는 모든 프록시가 망가질 수 있습니다.\n- 모든 delegate는 프록시의 스토리지를 공유합니다. 충돌을 피하려면 공통 기본 스토리지 레이아웃 하나를 쓰거나 [ERC-7201](/eip-7201/), [ERC-8042](/eip-8042/) 같은 네임스페이스 스토리지를 사용하세요.\n- 기존의 단일 구현 프록시는 셀렉터-delegate 맵을 채운 뒤 디스패치 구현으로 전환하는 방식으로 이전할 수 있습니다. 모듈식 설계는 [EIP-7702](/eip-7702/)로 위임된 EOA에도 어울립니다.\n- 관련 초안인 [ERC-8349](/eip-8349/)는 멀티 facet 프록시의 인덱스 기반 변형을 탐구합니다.\n"},"zh":{"lang":"zh","tldr":"一个最小化的代理标准：通过 delegatecall 把每个函数选择器路由到各自的逻辑模块，并提供两个 view 函数，让工具能够发现代理的 ABI 和升级历史。","tags":["proxy","upgradeability","delegatecall","modular","standard"],"related":[2535,7201,8042,7702,8349],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-8167/","markdown":"## 它解决什么问题？\n\n大多数代理合约会把每次调用都转发给单个实现合约。这样可行，但有局限：\n\n- 庞大的单体实现可能触及合约代码大小限制。\n- 升级意味着一次性替换整个实现，既有风险又难以验证。\n- 大部分逻辑相同的合约（例如，余额代码相同、元数据不同的两种代币）仍然需要完全独立的实现。\n\n把不同函数路由到不同逻辑合约的替代方案，已经存在于 [ERC-2535](/eip-2535/)\"Diamonds\"中。ERC-8167 以小得多的接口面、且不使用 diamond 术语，把同样的思路标准化，使浏览器、钱包和索引器能够可靠地弄清这类代理在做什么。\n\n## 它如何运作\n\n- **分发代理**读取 calldata 的前四个字节（函数选择器），查找为其注册的 **delegate**（逻辑模块），并以完整的 calldata 对该 delegate 执行 `delegatecall`。\n- **必须**提供两个 view 函数：\n  - `implementation(bytes4 selector)` 返回某个选择器对应的 delegate，若没有则返回 `address(0)`。\n  - `selectors()` 返回所有有实现的选择器。\n- **建议：** 每当映射发生变化时 emit `SelectorDelegated(selector, delegate)`（`address(0)` 表示已移除），并对未知选择器以 `FunctionNotFound(selector)` revert。\n- 自省函数本身应由 delegate 实现，而不是硬编码在代理中，并且构造函数应至少安装一个 delegate。\n\n该标准有意**不**定义升级函数或存储布局；这些留给具体实现或后续标准。移除升级选择器，就能把可升级代理变成不可变代理。\n\n要重建代理的 ABI，工具会调用 `selectors()`，把每个选择器映射到 `implementation(selector)`，再获取每个唯一 delegate 经过验证的 ABI。\n\n## 示例代码\n\n接口以及一个最简的分发 fallback（无管理逻辑，仅作演示）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC8167 {\n    event SelectorDelegated(bytes4 indexed selector, address indexed delegate);\n    error FunctionNotFound(bytes4 selector);\n    function implementation(bytes4 selector) external view returns (address);\n    function selectors() external view returns (bytes4[] memory);\n}\n\ncontract DispatchProxy {\n    mapping(bytes4 =\u003e address) internal delegates; // use a namespaced slot in practice\n\n    fallback() external payable {\n        address target = delegates[msg.sig];\n        if (target == address(0)) revert IERC8167.FunctionNotFound(msg.sig);\n        assembly {\n            calldatacopy(0, 0, calldatasize())\n            let ok := delegatecall(gas(), target, 0, calldatasize(), 0, 0)\n            returndatacopy(0, 0, returndatasize())\n            if iszero(ok) { revert(0, returndatasize()) }\n            return(0, returndatasize())\n        }\n    }\n}\n```\n\n## 需要注意\n\n- **状态：Final。**\n- 升级函数需要访问控制；该标准把这部分设计留给你。\n- delegate 绝不能能够自毁，否则可能破坏所有使用它的代理。\n- 所有 delegate 共享代理的存储。请使用统一的基础存储布局，或使用 [ERC-7201](/eip-7201/)、[ERC-8042](/eip-8042/) 这样的命名空间存储，以避免冲突。\n- 现有的单实现代理可以通过填充\"选择器到 delegate\"的映射，再切换到分发实现来迁移。模块化设计也适合 [EIP-7702](/eip-7702/) 委托的 EOA。\n- 相关草案 [ERC-8349](/eip-8349/) 探索了多 facet 代理的基于索引的变体。\n"}}}
