{"eip":8109,"title":"Diamonds, Simplified","description":"A simplified diamond architecture for modular smart contract systems.","authors":["Nick Mudge (@mudgen)"],"status":"Withdrawn","type":"Standards Track","category":"ERC","created":"2025-12-21","discussionsTo":"https://ethereum-magicians.org/t/erc-8109-diamonds-simplified/27119","repo":"ERCs","label":"ERC-8109","officialUrl":"https://eips.ethereum.org/EIPS/eip-8109","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8109.md","url":"https://eips.huatuo.xyz/eip-8109/","tldr":{"en":"A withdrawn attempt to simplify ERC-2535 Diamonds with per-function events and just two introspection functions; it was superseded by ERC-8153.","ja":"関数ごとのイベントと 2 つのイントロスペクション関数だけで ERC-2535 Diamonds を簡素化しようとした試み。撤回され、ERC-8153 に置き換えられた。","ko":"함수별 이벤트와 단 두 개의 인트로스펙션 함수로 ERC-2535 Diamonds를 단순화하려던 시도. 철회되었으며 ERC-8153으로 대체되었다.","zh":"一次已撤回的尝试：用逐函数事件和仅两个自省函数来简化 ERC-2535 Diamonds；它已被 ERC-8153 取代。"},"tags":["diamond","proxy","upgradeability","facets","withdrawn"],"explainers":{"en":{"lang":"en","tldr":"A withdrawn attempt to simplify ERC-2535 Diamonds with per-function events and just two introspection functions; it was superseded by ERC-8153.","tags":["diamond","proxy","upgradeability","facets","withdrawn"],"related":[8153,2535,8042,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-8109/","markdown":"## What problem does it solve?\n\nA **diamond** is a proxy contract that `delegatecall`s to many implementation contracts, called **facets**, behind one address. Because the diamond's functions are decided at runtime by a selector-to-facet table rather than by its own bytecode, block explorers and tools need standard functions and events to discover what a diamond can do.\n\n[ERC-2535](/eip-2535/) standardized that, but with several introspection functions and a single large `DiamondCut` event that is awkward to emit and to index. ERC-8109 tried to keep everything diamonds can do while making them easier to implement and to read.\n\n## How it works\n\n- **Fallback routing.** Any call hits the diamond's `fallback()`, which looks up the facet for `msg.sig` and `delegatecall`s it. Storage, `msg.sender` and `msg.value` stay the diamond's. If no facet (or default handler) exists, it must revert with `FunctionNotFound(bytes4)`.\n- **Per-function events (required).** Every change emits one event per selector: `DiamondFunctionAdded`, `DiamondFunctionReplaced` or `DiamondFunctionRemoved`. Indexers can rebuild the full upgrade history from these.\n- **Two introspection functions (required).** `facetAddress(bytes4)` and `functionFacetPairs()`, which returns the whole selector-to-facet mapping as `(selector, facet)` pairs. It is meant to be called off-chain.\n- **Optional events.** `DiamondDelegateCall` records non-routing `delegatecall`s (for example, init or migration code), and `DiamondMetadata` records arbitrary tags such as a release version.\n- **No upgrade function is specified.** A diamond can be built entirely in its constructor and be immutable, or define its own upgrade function as long as it emits the events above.\n- **Immutable functions** defined directly in the diamond must still be reported by introspection, with the diamond's own address as the facet, and must not be replaceable.\n\nExisting ERC-2535 diamonds could migrate by swapping in a new upgrade function, adding `functionFacetPairs()`, and emitting `DiamondFunctionAdded` for every current function as a \"snapshot\".\n\n## Sample code\n\nThe required interface:\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IDiamond8109 {\n    error FunctionNotFound(bytes4 _selector);\n\n    event DiamondFunctionAdded(bytes4 indexed _selector, address indexed _facet);\n    event DiamondFunctionReplaced(bytes4 indexed _selector, address indexed _oldFacet, address indexed _newFacet);\n    event DiamondFunctionRemoved(bytes4 indexed _selector, address indexed _oldFacet);\n\n    struct FunctionFacetPair {\n        bytes4 selector;\n        address facet;\n    }\n\n    function facetAddress(bytes4 _functionSelector) external view returns (address);\n    function functionFacetPairs() external view returns (FunctionFacetPair[] memory pairs);\n}\n```\n\nListing a diamond's functions off-chain (ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst diamond = new Contract(diamondAddress, [\n  \"function functionFacetPairs() view returns (tuple(bytes4 selector, address facet)[])\",\n], provider);\n\nfor (const { selector, facet } of await diamond.functionFacetPairs()) {\n  console.log(selector, \"-\u003e\", facet);\n}\n```\n\n## Things to know\n\n- **Status: Withdrawn.** The author withdrew it as superseded by [ERC-8153](/eip-8153/) (Facet-Based Diamonds), which is the version to use for new work. ERC-8153 keeps ERC-2535's introspection functions and switches to facet-level events.\n- The storage layout pattern is out of scope; [ERC-8042](/eip-8042/) Diamond Storage or [ERC-7201](/eip-7201/) namespaced storage are the examples the spec points to.\n- Ownership and access control for upgrades are not part of the standard and must be designed carefully.\n- Two functions with the same signature cannot live in one diamond at the same time.\n"},"ja":{"lang":"ja","tldr":"関数ごとのイベントと 2 つのイントロスペクション関数だけで ERC-2535 Diamonds を簡素化しようとした試み。撤回され、ERC-8153 に置き換えられた。","tags":["diamond","proxy","upgradeability","facets","withdrawn"],"related":[8153,2535,8042,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-8109/","markdown":"## 何を解決するのか\n\n**ダイヤモンド**は、1 つのアドレスの背後で、**ファセット**と呼ばれる多数の実装コントラクトに `delegatecall` するプロキシコントラクトです。ダイヤモンドの関数は、自身のバイトコードではなく、実行時のセレクター対ファセットのテーブルで決まるため、ブロックエクスプローラーやツールがダイヤモンドの機能を調べられるよう、標準的な関数とイベントが必要です。\n\n[ERC-2535](/eip-2535/) はそれを標準化しましたが、複数のイントロスペクション関数と、emit にもインデックス化にも扱いにくい 1 つの大きな `DiamondCut` イベントを使います。ERC-8109 は、ダイヤモンドができることをすべて維持しつつ、実装しやすく読みやすくしようとしました。\n\n## 仕組み\n\n- **フォールバックによるルーティング。** すべての呼び出しはダイヤモンドの `fallback()` に届き、`msg.sig` に対応するファセットを調べて `delegatecall` します。ストレージ、`msg.sender`、`msg.value` はダイヤモンドのものがそのまま維持されます。ファセット（またはデフォルトのハンドラー）がない場合は、`FunctionNotFound(bytes4)` で revert しなければなりません。\n- **関数ごとのイベント（必須）。** 変更のたびに、セレクターごとに 1 つのイベント（`DiamondFunctionAdded`、`DiamondFunctionReplaced`、`DiamondFunctionRemoved` のいずれか）を emit します。インデクサーはこれらからアップグレード履歴の全体を再構築できます。\n- **2 つのイントロスペクション関数（必須）。** `facetAddress(bytes4)` と `functionFacetPairs()` です。後者はセレクター対ファセットの対応全体を `(selector, facet)` のペアとして返します。オフチェーンで呼び出すことを想定しています。\n- **任意のイベント。** `DiamondDelegateCall` はルーティング以外の `delegatecall`（たとえば初期化やマイグレーションのコード）を記録し、`DiamondMetadata` はリリースバージョンなどの任意のタグを記録します。\n- **アップグレード用の関数は規定されていません。** ダイヤモンドはコンストラクタ内で完全に構築してイミュータブルにすることも、上記のイベントを emit する限り独自のアップグレード関数を定義することもできます。\n- ダイヤモンド内に直接定義される**イミュータブルな関数**も、ダイヤモンド自身のアドレスをファセットとしてイントロスペクションで報告しなければならず、置き換え可能であってはなりません。\n\n既存の ERC-2535 ダイヤモンドは、新しいアップグレード関数への入れ替え、`functionFacetPairs()` の追加、現在のすべての関数に対する「スナップショット」としての `DiamondFunctionAdded` の emit によって移行できます。\n\n## サンプルコード\n\n必須のインターフェース:\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IDiamond8109 {\n    error FunctionNotFound(bytes4 _selector);\n\n    event DiamondFunctionAdded(bytes4 indexed _selector, address indexed _facet);\n    event DiamondFunctionReplaced(bytes4 indexed _selector, address indexed _oldFacet, address indexed _newFacet);\n    event DiamondFunctionRemoved(bytes4 indexed _selector, address indexed _oldFacet);\n\n    struct FunctionFacetPair {\n        bytes4 selector;\n        address facet;\n    }\n\n    function facetAddress(bytes4 _functionSelector) external view returns (address);\n    function functionFacetPairs() external view returns (FunctionFacetPair[] memory pairs);\n}\n```\n\nオフチェーンでダイヤモンドの関数を一覧表示する（ethers v6）:\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst diamond = new Contract(diamondAddress, [\n  \"function functionFacetPairs() view returns (tuple(bytes4 selector, address facet)[])\",\n], provider);\n\nfor (const { selector, facet } of await diamond.functionFacetPairs()) {\n  console.log(selector, \"-\u003e\", facet);\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Withdrawn。** [ERC-8153](/eip-8153/)（Facet-Based Diamonds）に置き換えられたとして作者が撤回しました。新規の作業では ERC-8153 を使ってください。ERC-8153 は ERC-2535 のイントロスペクション関数を維持し、ファセット単位のイベントに切り替えています。\n- ストレージレイアウトのパターンはスコープ外です。仕様が例として挙げるのは [ERC-8042](/eip-8042/) の Diamond Storage や [ERC-7201](/eip-7201/) の名前空間付きストレージです。\n- アップグレードのオーナーシップとアクセス制御は標準に含まれておらず、慎重に設計する必要があります。\n- 同じシグネチャを持つ 2 つの関数が、同時に 1 つのダイヤモンドに存在することはできません。\n"},"ko":{"lang":"ko","tldr":"함수별 이벤트와 단 두 개의 인트로스펙션 함수로 ERC-2535 Diamonds를 단순화하려던 시도. 철회되었으며 ERC-8153으로 대체되었다.","tags":["diamond","proxy","upgradeability","facets","withdrawn"],"related":[8153,2535,8042,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-8109/","markdown":"## 어떤 문제를 해결하나요?\n\n**다이아몬드**는 하나의 주소 뒤에서 **파셋(facet)**이라 불리는 여러 구현 컨트랙트로 `delegatecall`하는 프록시 컨트랙트입니다. 다이아몬드의 함수는 자체 바이트코드가 아니라 런타임의 셀렉터-파셋 테이블로 결정되므로, 블록 탐색기와 도구가 다이아몬드가 무엇을 할 수 있는지 알아내려면 표준 함수와 이벤트가 필요합니다.\n\n[ERC-2535](/eip-2535/)가 이를 표준화했지만, 여러 개의 인트로스펙션 함수와 emit하기도 인덱싱하기도 번거로운 하나의 큰 `DiamondCut` 이벤트를 사용합니다. ERC-8109는 다이아몬드가 할 수 있는 모든 것을 유지하면서 구현하고 읽기 더 쉽게 만들려 했습니다.\n\n## 어떻게 동작하나요?\n\n- **폴백 라우팅.** 모든 호출은 다이아몬드의 `fallback()`에 도달하고, 이는 `msg.sig`에 해당하는 파셋을 찾아 `delegatecall`합니다. 스토리지, `msg.sender`, `msg.value`는 다이아몬드의 것으로 유지됩니다. 파셋(또는 기본 핸들러)이 없으면 `FunctionNotFound(bytes4)`로 revert해야 합니다.\n- **함수별 이벤트(필수).** 모든 변경은 셀렉터마다 이벤트 하나(`DiamondFunctionAdded`, `DiamondFunctionReplaced`, `DiamondFunctionRemoved` 중 하나)를 emit합니다. 인덱서는 이를 바탕으로 전체 업그레이드 이력을 재구성할 수 있습니다.\n- **두 개의 인트로스펙션 함수(필수).** `facetAddress(bytes4)`와 `functionFacetPairs()`입니다. 후자는 전체 셀렉터-파셋 매핑을 `(selector, facet)` 쌍으로 반환하며, 오프체인에서 호출하도록 만들어졌습니다.\n- **선택적 이벤트.** `DiamondDelegateCall`은 라우팅이 아닌 `delegatecall`(예: 초기화나 마이그레이션 코드)을 기록하고, `DiamondMetadata`는 릴리스 버전 같은 임의의 태그를 기록합니다.\n- **업그레이드 함수는 규정하지 않습니다.** 다이아몬드는 생성자에서 전부 구성하고 불변으로 만들 수도 있고, 위 이벤트를 emit하기만 하면 자체 업그레이드 함수를 정의할 수도 있습니다.\n- 다이아몬드에 직접 정의된 **불변 함수**도 다이아몬드 자신의 주소를 파셋으로 하여 인트로스펙션으로 보고해야 하며, 교체할 수 있어서는 안 됩니다.\n\n기존 ERC-2535 다이아몬드는 새 업그레이드 함수로 교체하고, `functionFacetPairs()`를 추가하고, 현재의 모든 함수에 대해 \"스냅숏\"으로 `DiamondFunctionAdded`를 emit하는 방식으로 마이그레이션할 수 있습니다.\n\n## 샘플 코드\n\n필수 인터페이스:\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IDiamond8109 {\n    error FunctionNotFound(bytes4 _selector);\n\n    event DiamondFunctionAdded(bytes4 indexed _selector, address indexed _facet);\n    event DiamondFunctionReplaced(bytes4 indexed _selector, address indexed _oldFacet, address indexed _newFacet);\n    event DiamondFunctionRemoved(bytes4 indexed _selector, address indexed _oldFacet);\n\n    struct FunctionFacetPair {\n        bytes4 selector;\n        address facet;\n    }\n\n    function facetAddress(bytes4 _functionSelector) external view returns (address);\n    function functionFacetPairs() external view returns (FunctionFacetPair[] memory pairs);\n}\n```\n\n오프체인에서 다이아몬드의 함수 나열하기(ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst diamond = new Contract(diamondAddress, [\n  \"function functionFacetPairs() view returns (tuple(bytes4 selector, address facet)[])\",\n], provider);\n\nfor (const { selector, facet } of await diamond.functionFacetPairs()) {\n  console.log(selector, \"-\u003e\", facet);\n}\n```\n\n## 알아둘 점\n\n- **상태: Withdrawn.** [ERC-8153](/eip-8153/)(Facet-Based Diamonds)으로 대체되었다며 작성자가 철회했습니다. 새 작업에는 ERC-8153을 사용하세요. ERC-8153은 ERC-2535의 인트로스펙션 함수를 유지하고 파셋 단위 이벤트로 바꿉니다.\n- 스토리지 레이아웃 패턴은 범위 밖입니다. 스펙이 예로 드는 것은 [ERC-8042](/eip-8042/) Diamond Storage와 [ERC-7201](/eip-7201/) 네임스페이스 스토리지입니다.\n- 업그레이드의 소유권과 접근 제어는 표준에 포함되지 않으므로 신중하게 설계해야 합니다.\n- 같은 시그니처를 가진 두 함수는 하나의 다이아몬드에 동시에 존재할 수 없습니다.\n"},"zh":{"lang":"zh","tldr":"一次已撤回的尝试：用逐函数事件和仅两个自省函数来简化 ERC-2535 Diamonds；它已被 ERC-8153 取代。","tags":["diamond","proxy","upgradeability","facets","withdrawn"],"related":[8153,2535,8042,7201],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-8109/","markdown":"## 它解决什么问题？\n\n**diamond** 是一种代理合约，在一个地址背后对许多被称为 **facet** 的实现合约执行 `delegatecall`。由于 diamond 的函数由运行时的 selector 到 facet 的映射表决定，而不是由它自身的字节码决定，区块浏览器和工具需要标准的函数和事件来发现 diamond 能做什么。\n\n[ERC-2535](/eip-2535/) 对此做了标准化，但它使用了多个自省函数，以及一个难以触发、也难以索引的大型 `DiamondCut` 事件。ERC-8109 试图在保留 diamond 全部功能的同时，让它们更易于实现和阅读。\n\n## 它如何运作\n\n- **Fallback 路由。** 任何调用都会进入 diamond 的 `fallback()`，它查找 `msg.sig` 对应的 facet 并对其 `delegatecall`。存储、`msg.sender` 和 `msg.value` 仍属于 diamond。如果没有 facet（或默认处理程序），必须以 `FunctionNotFound(bytes4)` revert。\n- **逐函数事件（必需）。** 每次变更都为每个 selector 触发一个事件：`DiamondFunctionAdded`、`DiamondFunctionReplaced` 或 `DiamondFunctionRemoved`。索引器可以据此重建完整的升级历史。\n- **两个自省函数（必需）。** `facetAddress(bytes4)` 和 `functionFacetPairs()`，后者以 `(selector, facet)` 对的形式返回完整的 selector 到 facet 的映射。它预期在链下调用。\n- **可选事件。** `DiamondDelegateCall` 记录非路由的 `delegatecall`（例如初始化或迁移代码），`DiamondMetadata` 记录发布版本等任意标签。\n- **不规定升级函数。** diamond 可以完全在构造函数中构建并保持不可变，也可以定义自己的升级函数，只要它触发上述事件。\n- 直接定义在 diamond 中的**不可变函数**仍须通过自省报告，facet 为 diamond 自身的地址，并且不得可被替换。\n\n现有的 ERC-2535 diamond 可以这样迁移：换上新的升级函数，添加 `functionFacetPairs()`，并为每个当前函数触发 `DiamondFunctionAdded` 作为“快照”。\n\n## 示例代码\n\n必需的接口：\n\n```solidity\n// SPDX-License-Identifier: CC0-1.0\npragma solidity ^0.8.20;\n\ninterface IDiamond8109 {\n    error FunctionNotFound(bytes4 _selector);\n\n    event DiamondFunctionAdded(bytes4 indexed _selector, address indexed _facet);\n    event DiamondFunctionReplaced(bytes4 indexed _selector, address indexed _oldFacet, address indexed _newFacet);\n    event DiamondFunctionRemoved(bytes4 indexed _selector, address indexed _oldFacet);\n\n    struct FunctionFacetPair {\n        bytes4 selector;\n        address facet;\n    }\n\n    function facetAddress(bytes4 _functionSelector) external view returns (address);\n    function functionFacetPairs() external view returns (FunctionFacetPair[] memory pairs);\n}\n```\n\n在链下列出 diamond 的函数（ethers v6）：\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst diamond = new Contract(diamondAddress, [\n  \"function functionFacetPairs() view returns (tuple(bytes4 selector, address facet)[])\",\n], provider);\n\nfor (const { selector, facet } of await diamond.functionFacetPairs()) {\n  console.log(selector, \"-\u003e\", facet);\n}\n```\n\n## 需要注意\n\n- **状态：Withdrawn。** 作者因其已被 [ERC-8153](/eip-8153/)（Facet-Based Diamonds）取代而撤回；新项目应使用 ERC-8153。ERC-8153 保留了 ERC-2535 的自省函数，并改用 facet 级事件。\n- 存储布局模式不在范围之内；规范指向的例子是 [ERC-8042](/eip-8042/) Diamond Storage 和 [ERC-7201](/eip-7201/) 命名空间存储。\n- 升级的所有权和访问控制不属于该标准，必须谨慎设计。\n- 具有相同签名的两个函数不能同时存在于同一个 diamond 中。\n"}}}
