{"eip":8349,"title":"Index-Based Multi-Facet Proxy","description":"A modular proxy architecture that uses compact facet indices for protocol routing while preserving function selectors for compatibility.","authors":["Artem Buchikhin (@Arhemius)"],"status":"Draft","type":"Standards Track","category":"ERC","created":"2026-07-25","requires":[165],"discussionsTo":"https://ethereum-magicians.org/t/erc-8349-index-based-multi-facet-proxy/29054","repo":"ERCs","label":"ERC-8349","officialUrl":"https://eips.ethereum.org/EIPS/eip-8349","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8349.md","url":"https://eips.huatuo.xyz/eip-8349/","tldr":{"en":"A multi-facet proxy design ('Cento') that routes calls by a one-byte facet index appended to calldata instead of by function selector, so routing data scales with modules rather than functions.","ja":"関数セレクターではなく calldata に付加した 1 バイトの facet インデックスで呼び出しをルーティングするマルチファセットプロキシの設計（「Cento」）。ルーティングデータが関数数ではなくモジュール数に応じて増える。","ko":"함수 셀렉터 대신 calldata에 덧붙인 1바이트 facet 인덱스로 호출을 라우팅하는 멀티 facet 프록시 설계('Cento'). 라우팅 데이터가 함수 수가 아니라 모듈 수에 비례해 늘어난다.","zh":"一种多 facet 代理设计（\"Cento\"）：通过附加在 calldata 末尾的一个字节的 facet 索引而不是函数选择器来路由调用，使路由数据随模块数量而不是函数数量扩展。"},"tags":["proxy","upgradeability","modular","delegatecall","standard"],"explainers":{"en":{"lang":"en","tldr":"A multi-facet proxy design ('Cento') that routes calls by a one-byte facet index appended to calldata instead of by function selector, so routing data scales with modules rather than functions.","tags":["proxy","upgradeability","modular","delegatecall","standard"],"related":[2535,8167,165,173,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-8349/","markdown":"## What problem does it solve?\n\nMulti-facet proxies such as [ERC-2535](/eip-2535/) Diamonds (and the simpler [ERC-8167](/eip-8167/)) keep one contract address but split logic across many \"facets\". They decide which facet runs by looking up the 4-byte **function selector**. That means:\n\n- the routing table grows with every exported function, not with the number of modules;\n- every upgrade has to update entries selector by selector, even when a whole facet is swapped;\n- independently written facets must never expose the same selector.\n\nERC-8349 argues that \"which module runs\" and \"which function is called\" are separate concerns, and gives facets an explicit identity of their own.\n\n## How it works\n\nThe proposal calls its routing model **Cento**. The proxy (\"router\") supports two paths:\n\n- **Protocol Routing.** The caller appends **one byte**, a routing index from 0 to 255, to the end of the calldata. The router reads it, looks up the facet in its routing table, strips the byte and `delegatecall`s the facet with the original calldata. The facet sees a normal call, so existing Solidity code works unchanged, and selectors only need to be unique *within* a facet.\n- **Compatibility Routing.** Standard interfaces that wallets and tools call without an index (for example [ERC-165](/eip-165/) `supportsInterface` or [ERC-173](/eip-173/) `owner`) are recognised by selector and mapped to the right index. How the router tells the two paths apart is implementation-specific; the spec's example uses odd vs. even calldata length.\n\nManagement and introspection:\n\n- `atomicUpdate(setF, addI, remI, migrator, data)` installs, replaces or removes facets, registers or unregisters ERC-165 interface IDs and optionally runs a storage migration via `delegatecall`, all or nothing, and emits `AtomicUpdate`.\n- `IObservability` exposes `getFacets`, `getFacetEntries`, `getFacetAt`, `getFacetCount` and `getFirstFreeSlot`.\n- Routers start with three core facets: index 0 facet manager, index 1 ownership, index 2 ERC-165 plus observability.\n\n## Sample code\n\nCalling a protocol function through the router by appending the facet index (ethers v6):\n\n```ts\nimport { Interface, concat, toBeHex, Contract } from \"ethers\";\n\nconst vaultFacet = new Interface([\"function deposit(uint256 amount)\"]);\nconst VAULT_INDEX = 3; // routing index assigned to this facet\n\nconst data = concat([\n  vaultFacet.encodeFunctionData(\"deposit\", [1_000n]),\n  toBeHex(VAULT_INDEX, 1),               // one trailing routing byte\n]);\nawait signer.sendTransaction({ to: ROUTER, data });\n\n// Compatibility path: no index byte, plain selector call\nconst router = new Contract(ROUTER, [\"function getFacetAt(uint8) view returns (address)\"], provider);\nconsole.log(await router.getFacetAt(VAULT_INDEX));\n```\n\n## Things to know\n\n- **Status: Draft.**\n- Calls through Protocol Routing need the extra byte, so generic tooling that only knows the facet ABI will not reach those functions unless it appends the index.\n- Routers should reject EOAs, code-less addresses and [EIP-7702](/eip-7702/) delegated EOAs as facets (the reference implementation checks for the `0xef0100` prefix), and must never delegate to `address(0)` or themselves.\n- Empty calldata must not reach the fallback; stripping an index from zero bytes can underflow and burn all gas. Provide a `receive()` or an explicit length check.\n- Gate `atomicUpdate` with strong access control, consider time-locks, and use namespaced storage such as [ERC-7201](/eip-7201/) to avoid facet storage collisions.\n- It is not compatible with selector-based Diamonds; both models are intended to coexist.\n"},"ja":{"lang":"ja","tldr":"関数セレクターではなく calldata に付加した 1 バイトの facet インデックスで呼び出しをルーティングするマルチファセットプロキシの設計（「Cento」）。ルーティングデータが関数数ではなくモジュール数に応じて増える。","tags":["proxy","upgradeability","modular","delegatecall","standard"],"related":[2535,8167,165,173,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-8349/","markdown":"## 何を解決するのか\n\n[ERC-2535](/eip-2535/) の Diamonds（およびより単純な [ERC-8167](/eip-8167/)）のようなマルチファセットプロキシは、コントラクトアドレスを 1 つに保ちつつ、ロジックを多数の「ファセット」に分割します。どのファセットを実行するかは、4 バイトの**関数セレクター**を調べて決めます。その結果、次のようになります。\n\n- ルーティングテーブルは、モジュールの数ではなく、公開される関数ごとに大きくなる\n- ファセット全体を入れ替える場合でも、すべてのアップグレードでセレクターごとにエントリーを更新しなければならない\n- 独立して書かれたファセット同士は、同じセレクターを公開してはならない\n\nERC-8349 は、「どのモジュールが実行されるか」と「どの関数が呼ばれるか」は別々の関心事だと主張し、ファセットに独自の明示的な識別子を与えます。\n\n## 仕組み\n\nこの提案は、そのルーティングモデルを **Cento** と呼びます。プロキシ（「ルーター」）は 2 つの経路をサポートします。\n\n- **Protocol Routing。** 呼び出し側は、calldata の末尾に **1 バイト**（0 から 255 のルーティングインデックス）を付加します。ルーターはそれを読み、ルーティングテーブルからファセットを調べ、そのバイトを取り除いて、元の calldata でファセットに `delegatecall` します。ファセットからは通常の呼び出しに見えるため、既存の Solidity コードがそのまま動作し、セレクターはファセット*内*でのみ一意であればよくなります。\n- **Compatibility Routing。** ウォレットやツールがインデックスなしで呼び出す標準インターフェース（たとえば [ERC-165](/eip-165/) の `supportsInterface` や [ERC-173](/eip-173/) の `owner`）は、セレクターで認識され、適切なインデックスに対応付けられます。ルーターが 2 つの経路をどう区別するかは実装依存で、仕様の例では calldata の長さが奇数か偶数かを使っています。\n\n管理とイントロスペクション:\n\n- `atomicUpdate(setF, addI, remI, migrator, data)` は、ファセットのインストール、置き換え、削除、ERC-165 のインターフェース ID の登録・登録解除を行い、必要に応じて `delegatecall` でストレージのマイグレーションを実行します。すべて成功するか、何も反映されないかで、`AtomicUpdate` を emit します。\n- `IObservability` は、`getFacets`、`getFacetEntries`、`getFacetAt`、`getFacetCount`、`getFirstFreeSlot` を公開します。\n- ルーターは 3 つのコアファセットで始まります。インデックス 0 がファセットマネージャー、インデックス 1 がオーナーシップ、インデックス 2 が ERC-165 とオブザーバビリティです。\n\n## サンプルコード\n\nファセットのインデックスを付加して、ルーター経由でプロトコルの関数を呼び出す（ethers v6）:\n\n```ts\nimport { Interface, concat, toBeHex, Contract } from \"ethers\";\n\nconst vaultFacet = new Interface([\"function deposit(uint256 amount)\"]);\nconst VAULT_INDEX = 3; // routing index assigned to this facet\n\nconst data = concat([\n  vaultFacet.encodeFunctionData(\"deposit\", [1_000n]),\n  toBeHex(VAULT_INDEX, 1),               // one trailing routing byte\n]);\nawait signer.sendTransaction({ to: ROUTER, data });\n\n// Compatibility path: no index byte, plain selector call\nconst router = new Contract(ROUTER, [\"function getFacetAt(uint8) view returns (address)\"], provider);\nconsole.log(await router.getFacetAt(VAULT_INDEX));\n```\n\n## 知っておくべきこと\n\n- **ステータス: Draft。**\n- Protocol Routing による呼び出しには追加のバイトが必要なため、ファセットの ABI しか知らない汎用ツールは、インデックスを付加しない限り、それらの関数に到達できません。\n- ルーターは、EOA、コードのないアドレス、[EIP-7702](/eip-7702/) で委任された EOA をファセットとして拒否すべきです（リファレンス実装は `0xef0100` のプレフィックスを確認します）。また、`address(0)` や自分自身には決して delegate してはなりません。\n- 空の calldata が fallback に到達してはなりません。0 バイトからインデックスを取り除くとアンダーフローし、すべての gas を使い果たす可能性があります。`receive()` を用意するか、明示的な長さのチェックを入れてください。\n- `atomicUpdate` には強力なアクセス制御をかけ、タイムロックを検討し、ファセットのストレージ衝突を避けるために [ERC-7201](/eip-7201/) のような名前空間付きストレージを使ってください。\n- セレクターベースの Diamonds とは互換性がありません。両方のモデルは共存することを想定しています。\n"},"ko":{"lang":"ko","tldr":"함수 셀렉터 대신 calldata에 덧붙인 1바이트 facet 인덱스로 호출을 라우팅하는 멀티 facet 프록시 설계('Cento'). 라우팅 데이터가 함수 수가 아니라 모듈 수에 비례해 늘어난다.","tags":["proxy","upgradeability","modular","delegatecall","standard"],"related":[2535,8167,165,173,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-8349/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-2535](/eip-2535/) Diamonds(그리고 더 단순한 [ERC-8167](/eip-8167/)) 같은 멀티 facet 프록시는 컨트랙트 주소 하나를 유지하면서 로직을 여러 \"facet\"으로 나눕니다. 어떤 facet을 실행할지는 4바이트 **함수 셀렉터**를 조회해 결정합니다. 그래서 다음과 같은 문제가 생깁니다.\n\n- 라우팅 테이블이 모듈 수가 아니라 노출되는 함수마다 커집니다.\n- facet 전체를 교체하더라도 모든 업그레이드에서 항목을 셀렉터 단위로 갱신해야 합니다.\n- 독립적으로 작성된 facet은 같은 셀렉터를 노출해서는 안 됩니다.\n\nERC-8349는 \"어떤 모듈이 실행되는가\"와 \"어떤 함수가 호출되는가\"가 별개의 관심사라고 주장하며, facet에 고유하고 명시적인 식별자를 부여합니다.\n\n## 어떻게 동작하나요?\n\n이 제안은 라우팅 모델을 **Cento**라고 부릅니다. 프록시(\"라우터\")는 두 가지 경로를 지원합니다.\n\n- **Protocol Routing.** 호출자는 calldata 끝에 **1바이트**, 즉 0에서 255 사이의 라우팅 인덱스를 덧붙입니다. 라우터는 이를 읽고, 라우팅 테이블에서 facet을 찾고, 그 바이트를 제거한 뒤, 원래의 calldata로 facet에 `delegatecall`합니다. facet은 일반 호출로 보게 되므로 기존 Solidity 코드가 수정 없이 동작하며, 셀렉터는 facet *안에서만* 고유하면 됩니다.\n- **Compatibility Routing.** 지갑과 도구가 인덱스 없이 호출하는 표준 인터페이스(예: [ERC-165](/eip-165/) `supportsInterface`나 [ERC-173](/eip-173/) `owner`)는 셀렉터로 인식되어 올바른 인덱스에 매핑됩니다. 라우터가 두 경로를 어떻게 구분하는지는 구현에 따라 다르며, 사양의 예시는 calldata 길이의 홀수/짝수를 사용합니다.\n\n관리와 인트로스펙션:\n\n- `atomicUpdate(setF, addI, remI, migrator, data)`는 facet을 설치, 교체, 제거하고, ERC-165 인터페이스 ID를 등록하거나 해제하며, 선택적으로 `delegatecall`로 스토리지 마이그레이션을 실행합니다. 전부 성공하거나 전부 반영되지 않으며 `AtomicUpdate`를 emit합니다.\n- `IObservability`는 `getFacets`, `getFacetEntries`, `getFacetAt`, `getFacetCount`, `getFirstFreeSlot`을 노출합니다.\n- 라우터는 세 개의 핵심 facet으로 시작합니다. 인덱스 0은 facet 매니저, 인덱스 1은 소유권, 인덱스 2는 ERC-165와 관측 가능성입니다.\n\n## 샘플 코드\n\nfacet 인덱스를 덧붙여 라우터를 통해 프로토콜 함수 호출하기(ethers v6):\n\n```ts\nimport { Interface, concat, toBeHex, Contract } from \"ethers\";\n\nconst vaultFacet = new Interface([\"function deposit(uint256 amount)\"]);\nconst VAULT_INDEX = 3; // routing index assigned to this facet\n\nconst data = concat([\n  vaultFacet.encodeFunctionData(\"deposit\", [1_000n]),\n  toBeHex(VAULT_INDEX, 1),               // one trailing routing byte\n]);\nawait signer.sendTransaction({ to: ROUTER, data });\n\n// Compatibility path: no index byte, plain selector call\nconst router = new Contract(ROUTER, [\"function getFacetAt(uint8) view returns (address)\"], provider);\nconsole.log(await router.getFacetAt(VAULT_INDEX));\n```\n\n## 알아둘 점\n\n- **상태: Draft.**\n- Protocol Routing을 통한 호출에는 추가 바이트가 필요하므로, facet ABI만 아는 범용 도구는 인덱스를 덧붙이지 않으면 그 함수들에 닿지 못합니다.\n- 라우터는 EOA, 코드 없는 주소, [EIP-7702](/eip-7702/)로 위임된 EOA를 facet으로 거부해야 하며(참조 구현은 `0xef0100` 접두사를 확인), `address(0)`이나 자기 자신에게 절대 delegate해서는 안 됩니다.\n- 빈 calldata가 fallback에 도달해서는 안 됩니다. 0바이트에서 인덱스를 떼어 내면 언더플로가 발생해 gas를 모두 태울 수 있습니다. `receive()`를 제공하거나 명시적인 길이 검사를 두세요.\n- `atomicUpdate`에는 강력한 접근 제어를 걸고, 타임락을 고려하며, facet 스토리지 충돌을 피하려면 [ERC-7201](/eip-7201/) 같은 네임스페이스 스토리지를 사용하세요.\n- 셀렉터 기반 Diamonds와는 호환되지 않으며, 두 모델은 공존하도록 의도되었습니다.\n"},"zh":{"lang":"zh","tldr":"一种多 facet 代理设计（\"Cento\"）：通过附加在 calldata 末尾的一个字节的 facet 索引而不是函数选择器来路由调用，使路由数据随模块数量而不是函数数量扩展。","tags":["proxy","upgradeability","modular","delegatecall","standard"],"related":[2535,8167,165,173,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-8349/","markdown":"## 它解决什么问题？\n\n像 [ERC-2535](/eip-2535/) Diamonds（以及更简单的 [ERC-8167](/eip-8167/)）这样的多 facet 代理，保持一个合约地址，但把逻辑拆分到许多\"facet\"中。它们通过查找 4 字节的**函数选择器**来决定运行哪个 facet。这意味着：\n\n- 路由表随着每个导出的函数而增长，而不是随模块数量增长；\n- 每次升级都必须逐个选择器地更新条目，即使替换的是整个 facet；\n- 独立编写的 facet 绝不能暴露相同的选择器。\n\nERC-8349 认为\"运行哪个模块\"和\"调用哪个函数\"是两个独立的问题，并赋予 facet 其自身明确的标识。\n\n## 它如何运作\n\n该提案把它的路由模型称为 **Cento**。代理（\"路由器\"）支持两条路径：\n\n- **Protocol Routing。** 调用者在 calldata 末尾附加**一个字节**，即 0 到 255 的路由索引。路由器读取它，在路由表中查找 facet，去掉该字节，并以原始 calldata 对 facet 执行 `delegatecall`。facet 看到的是一次普通调用，因此现有的 Solidity 代码无需改动即可工作，选择器只需要在 facet *内部*唯一。\n- **Compatibility Routing。** 钱包和工具不带索引就调用的标准接口（例如 [ERC-165](/eip-165/) 的 `supportsInterface` 或 [ERC-173](/eip-173/) 的 `owner`），按选择器识别并映射到正确的索引。路由器如何区分这两条路径取决于具体实现；规范中的示例使用 calldata 长度的奇偶性。\n\n管理与自省：\n\n- `atomicUpdate(setF, addI, remI, migrator, data)` 安装、替换或移除 facet，注册或注销 ERC-165 接口 ID，并可选地通过 `delegatecall` 运行存储迁移，要么全部成功要么全部不生效，并 emit `AtomicUpdate`。\n- `IObservability` 公开 `getFacets`、`getFacetEntries`、`getFacetAt`、`getFacetCount` 和 `getFirstFreeSlot`。\n- 路由器初始带有三个核心 facet：索引 0 为 facet 管理器，索引 1 为所有权，索引 2 为 ERC-165 加可观测性。\n\n## 示例代码\n\n通过附加 facet 索引，经由路由器调用协议函数（ethers v6）：\n\n```ts\nimport { Interface, concat, toBeHex, Contract } from \"ethers\";\n\nconst vaultFacet = new Interface([\"function deposit(uint256 amount)\"]);\nconst VAULT_INDEX = 3; // routing index assigned to this facet\n\nconst data = concat([\n  vaultFacet.encodeFunctionData(\"deposit\", [1_000n]),\n  toBeHex(VAULT_INDEX, 1),               // one trailing routing byte\n]);\nawait signer.sendTransaction({ to: ROUTER, data });\n\n// Compatibility path: no index byte, plain selector call\nconst router = new Contract(ROUTER, [\"function getFacetAt(uint8) view returns (address)\"], provider);\nconsole.log(await router.getFacetAt(VAULT_INDEX));\n```\n\n## 需要注意\n\n- **状态：Draft。**\n- 通过 Protocol Routing 的调用需要额外的字节，因此只了解 facet ABI 的通用工具除非附加索引，否则无法到达这些函数。\n- 路由器应拒绝 EOA、无代码的地址以及 [EIP-7702](/eip-7702/) 委托的 EOA 作为 facet（参考实现会检查 `0xef0100` 前缀），并且绝不能 delegate 给 `address(0)` 或自身。\n- 空的 calldata 不得到达 fallback；从零字节中去掉索引可能发生下溢并耗尽所有 gas。请提供 `receive()` 或显式的长度检查。\n- 用强访问控制保护 `atomicUpdate`，考虑使用时间锁，并使用 [ERC-7201](/eip-7201/) 这样的命名空间存储来避免 facet 存储冲突。\n- 它与基于选择器的 Diamonds 不兼容；这两种模型旨在并存。\n"}}}
