{"eip":6224,"title":"Contracts Dependencies Registry","description":"A registry for managing smart contracts with their dependencies.","authors":["Artem Chystiakov (@arvolear)"],"status":"Last Call","type":"Standards Track","category":"ERC","created":"2022-12-27","requires":[1967,5750],"discussionsTo":"https://ethereum-magicians.org/t/eip-6224-contracts-dependencies-registry/12316","repo":"ERCs","label":"ERC-6224","officialUrl":"https://eips.ethereum.org/EIPS/eip-6224","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6224.md","url":"https://eips.huatuo.xyz/eip-6224/","tldr":{"en":"A standard ContractsRegistry plus a Dependant mix-in that give a protocol one on-chain place to register, upgrade and wire together its contracts through dependency injection.","ja":"標準的な ContractsRegistry と Dependant ミックスインにより、プロトコルが依存性注入を通じて、自分のコントラクトの登録、アップグレード、相互接続をオンチェーンの 1 か所で行えるようにする。","ko":"표준 ContractsRegistry와 Dependant 믹스인을 통해, 프로토콜이 의존성 주입으로 자신의 컨트랙트를 등록, 업그레이드, 연결할 수 있는 온체인의 단일 장소를 제공한다.","zh":"一个标准的 ContractsRegistry 加上 Dependant 混入合约，为协议提供一个链上的统一位置，通过依赖注入来注册、升级并连接它的各个合约。"},"tags":["registry","upgradeability","proxy","dependency-injection","architecture"],"explainers":{"en":{"lang":"en","tldr":"A standard ContractsRegistry plus a Dependant mix-in that give a protocol one on-chain place to register, upgrade and wire together its contracts through dependency injection.","tags":["registry","upgradeability","proxy","dependency-injection","architecture"],"related":[1967,5750,2535,1822],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-6224/","markdown":"## What problem does it solve?\n\nA real protocol is many contracts that point at each other: a vault needs the oracle, the oracle needs the price feed, and so on. Teams usually hard-code those addresses in constructors or initializers, then struggle when one contract is replaced or upgraded: every contract that depends on it must be updated by hand.\n\nERC-6224 proposes a standard architecture: one **ContractsRegistry** that knows every contract of the protocol (optionally deploying upgradeable proxies for them), and a **Dependant** base contract that lets the registry push dependencies into each contract on demand.\n\n## How it works\n\n**ContractsRegistry** (`IContractsRegistry`):\n\n- Contracts are identified by a human-readable `string` name.\n- `addContract(name, addr)` registers a plain, non-upgradeable contract.\n- `addProxyContract(name, impl)` / `addProxyContractAndCall(name, impl, data)` deploy a proxy over an implementation, so the registry can later `upgradeContract` / `upgradeContractAndCall` it.\n- `justAddProxyContract(name, proxy)` adopts an existing proxy (e.g. when migrating to a new registry, which must then hold upgrade rights).\n- `getContract(name)` reverts if nothing is registered; `hasContract(name)` checks presence; `removeContract(name)` deletes.\n- Registering `address(0)` must revert.\n- `injectDependencies(name)` / `injectDependenciesWithData(name, data)` call `setDependencies(address(this), data)` on the named contract.\n\n**Dependant** (`IDependant`):\n\n- Every standalone protocol contract inherits it and reads its dependencies **in `setDependencies`**, not in a constructor or initializer.\n- Only the current **injector** may call `setDependencies` and `setInjector`. The injector starts as zero, so the first call is allowed; the reference implementation then records the caller as injector.\n- The injector address may live in the slot `bytes32(uint256(keccak256(\"eip6224.dependant.slot\")) - 1)`, an [ERC-1967](/eip-1967/)-style storage slot.\n\nThe extra `bytes data` argument follows the [ERC-5750](/eip-5750/) pattern for extensible method behaviour.\n\n## Sample code\n\nA dependant contract pulling two dependencies from the registry:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IContractsRegistry {\n    function getContract(string memory name) external view returns (address);\n}\n\n/// `Dependant` as in the ERC's reference implementation (stores the injector,\n/// exposes the `dependant` modifier that checks and then records msg.sender).\nimport {Dependant} from \"./Dependant.sol\";\n\ncontract Vault is Dependant {\n    address public oracle;\n    address public treasury;\n\n    function setDependencies(address registry, bytes memory) public override dependant {\n        IContractsRegistry r = IContractsRegistry(registry);\n        oracle = r.getContract(\"ORACLE\");\n        treasury = r.getContract(\"TREASURY\");\n    }\n}\n```\n\nDeployment flow (pseudocode):\n\n```text\nregistry.addContract(\"ORACLE\", oracleAddr)\nregistry.addProxyContract(\"TREASURY\", treasuryImpl)\nregistry.addProxyContract(\"VAULT\", vaultImpl)\nregistry.injectDependencies(\"VAULT\")       // Vault reads ORACLE and TREASURY\n// later: swap the oracle and re-inject\nregistry.addContract(\"ORACLE\", newOracle)\nregistry.injectDependencies(\"VAULT\")\n```\n\n## Things to know\n\n- Status is **Last Call**: close to final, but details could still change.\n- The registry owner controls every upgrade. Losing or leaking that key compromises the whole protocol; use a multisig or governance.\n- The registry does no compatibility checks between implementations; storage-layout safety on upgrade is your responsibility.\n- Because the injector starts as zero, the first `setDependencies` call can be front-run. Inject dependencies right after deployment, ideally in the same transaction.\n- Events use non-indexed `string` names on purpose, trading filterability for readability.\n"},"ja":{"lang":"ja","tldr":"標準的な ContractsRegistry と Dependant ミックスインにより、プロトコルが依存性注入を通じて、自分のコントラクトの登録、アップグレード、相互接続をオンチェーンの 1 か所で行えるようにする。","tags":["registry","upgradeability","proxy","dependency-injection","architecture"],"related":[1967,5750,2535,1822],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-6224/","markdown":"## 何を解決するのか\n\n実際のプロトコルは、互いを指し示す多数のコントラクトで構成されます。ボールトにはオラクルが必要で、オラクルには価格フィードが必要、という具合です。チームは通常、これらのアドレスをコンストラクタや初期化関数にハードコードし、コントラクトの 1 つが置き換えられたりアップグレードされたりしたときに苦労します。それに依存するすべてのコントラクトを手作業で更新しなければならないからです。\n\nERC-6224 は標準的なアーキテクチャを提案します。プロトコルのすべてのコントラクトを把握する 1 つの **ContractsRegistry**（任意で、それらのためのアップグレード可能なプロキシをデプロイする）と、レジストリが必要に応じて各コントラクトに依存先を注入できるようにする **Dependant** 基底コントラクトです。\n\n## 仕組み\n\n**ContractsRegistry**（`IContractsRegistry`）:\n\n- コントラクトは、人間が読める `string` の名前で識別されます。\n- `addContract(name, addr)` は、アップグレード不可の通常のコントラクトを登録します。\n- `addProxyContract(name, impl)` / `addProxyContractAndCall(name, impl, data)` は、実装の上にプロキシをデプロイするため、レジストリは後から `upgradeContract` / `upgradeContractAndCall` でアップグレードできます。\n- `justAddProxyContract(name, proxy)` は、既存のプロキシを取り込みます（たとえば新しいレジストリへの移行時。その場合、新しいレジストリがアップグレード権限を持つ必要があります）。\n- `getContract(name)` は、何も登録されていなければ revert します。`hasContract(name)` は存在を確認し、`removeContract(name)` は削除します。\n- `address(0)` の登録は revert しなければなりません。\n- `injectDependencies(name)` / `injectDependenciesWithData(name, data)` は、指定された名前のコントラクトの `setDependencies(address(this), data)` を呼びます。\n\n**Dependant**（`IDependant`）:\n\n- プロトコルの独立したコントラクトはすべてこれを継承し、依存先をコンストラクタや初期化関数ではなく、**`setDependencies` の中で**読み取ります。\n- `setDependencies` と `setInjector` を呼べるのは、現在の **injector** だけです。injector は最初はゼロなので、最初の呼び出しは許可されます。その後、リファレンス実装は呼び出し元を injector として記録します。\n- injector のアドレスは、[ERC-1967](/eip-1967/) 形式のストレージスロットである `bytes32(uint256(keccak256(\"eip6224.dependant.slot\")) - 1)` のスロットに置いてもかまいません。\n\n追加の `bytes data` 引数は、拡張可能なメソッド動作のための [ERC-5750](/eip-5750/) のパターンに従っています。\n\n## サンプルコード\n\nレジストリから 2 つの依存先を取得する Dependant コントラクト:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IContractsRegistry {\n    function getContract(string memory name) external view returns (address);\n}\n\n/// `Dependant` as in the ERC's reference implementation (stores the injector,\n/// exposes the `dependant` modifier that checks and then records msg.sender).\nimport {Dependant} from \"./Dependant.sol\";\n\ncontract Vault is Dependant {\n    address public oracle;\n    address public treasury;\n\n    function setDependencies(address registry, bytes memory) public override dependant {\n        IContractsRegistry r = IContractsRegistry(registry);\n        oracle = r.getContract(\"ORACLE\");\n        treasury = r.getContract(\"TREASURY\");\n    }\n}\n```\n\nデプロイの流れ（疑似コード）:\n\n```text\nregistry.addContract(\"ORACLE\", oracleAddr)\nregistry.addProxyContract(\"TREASURY\", treasuryImpl)\nregistry.addProxyContract(\"VAULT\", vaultImpl)\nregistry.injectDependencies(\"VAULT\")       // Vault reads ORACLE and TREASURY\n// later: swap the oracle and re-inject\nregistry.addContract(\"ORACLE\", newOracle)\nregistry.injectDependencies(\"VAULT\")\n```\n\n## 知っておくべきこと\n\n- ステータスは **Last Call** です。final に近いものの、詳細はまだ変更される可能性があります。\n- レジストリの所有者がすべてのアップグレードを管理します。その鍵を失ったり漏えいしたりするとプロトコル全体が危険にさらされるため、マルチシグやガバナンスを使ってください。\n- レジストリは実装間の互換性チェックを行いません。アップグレード時のストレージレイアウトの安全性は、あなたの責任です。\n- injector は最初はゼロなので、最初の `setDependencies` 呼び出しはフロントランされうる点に注意が必要です。デプロイ直後、できれば同じトランザクション内で依存先を注入してください。\n- イベントは、フィルタリングのしやすさよりも読みやすさを優先して、あえてインデックスなしの `string` 名を使っています。\n"},"ko":{"lang":"ko","tldr":"표준 ContractsRegistry와 Dependant 믹스인을 통해, 프로토콜이 의존성 주입으로 자신의 컨트랙트를 등록, 업그레이드, 연결할 수 있는 온체인의 단일 장소를 제공한다.","tags":["registry","upgradeability","proxy","dependency-injection","architecture"],"related":[1967,5750,2535,1822],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-6224/","markdown":"## 어떤 문제를 해결하나요?\n\n실제 프로토콜은 서로를 가리키는 많은 컨트랙트로 이루어집니다. 볼트는 오라클이 필요하고, 오라클은 가격 피드가 필요하고, 이런 식입니다. 팀은 보통 이 주소들을 생성자나 초기화 함수에 하드코딩하고, 컨트랙트 하나가 교체되거나 업그레이드될 때 고생합니다. 그것에 의존하는 모든 컨트랙트를 손으로 업데이트해야 하기 때문입니다.\n\nERC-6224는 표준 아키텍처를 제안합니다. 프로토콜의 모든 컨트랙트를 아는 하나의 **ContractsRegistry**(선택적으로 이들을 위한 업그레이드 가능 프록시를 배포)와, 레지스트리가 필요할 때 각 컨트랙트에 의존성을 밀어 넣을 수 있게 하는 **Dependant** 기반 컨트랙트입니다.\n\n## 어떻게 동작하나요?\n\n**ContractsRegistry**(`IContractsRegistry`):\n\n- 컨트랙트는 사람이 읽을 수 있는 `string` 이름으로 식별됩니다.\n- `addContract(name, addr)`는 업그레이드할 수 없는 일반 컨트랙트를 등록합니다.\n- `addProxyContract(name, impl)` / `addProxyContractAndCall(name, impl, data)`는 구현 위에 프록시를 배포하므로, 레지스트리가 나중에 `upgradeContract` / `upgradeContractAndCall`로 업그레이드할 수 있습니다.\n- `justAddProxyContract(name, proxy)`는 기존 프록시를 넘겨받습니다(예: 새 레지스트리로 마이그레이션할 때. 이 경우 새 레지스트리가 업그레이드 권한을 가져야 합니다).\n- `getContract(name)`는 등록된 것이 없으면 revert하고, `hasContract(name)`는 존재 여부를 확인하며, `removeContract(name)`는 삭제합니다.\n- `address(0)`을 등록하면 revert해야 합니다.\n- `injectDependencies(name)` / `injectDependenciesWithData(name, data)`는 해당 이름의 컨트랙트에 `setDependencies(address(this), data)`를 호출합니다.\n\n**Dependant**(`IDependant`):\n\n- 프로토콜의 모든 독립 컨트랙트가 이를 상속하며, 의존성을 생성자나 초기화 함수가 아니라 **`setDependencies` 안에서** 읽습니다.\n- 현재 **injector**만 `setDependencies`와 `setInjector`를 호출할 수 있습니다. injector는 처음에는 0이므로 첫 호출은 허용되며, 레퍼런스 구현은 그 호출자를 injector로 기록합니다.\n- injector 주소는 [ERC-1967](/eip-1967/) 방식의 스토리지 슬롯인 `bytes32(uint256(keccak256(\"eip6224.dependant.slot\")) - 1)` 슬롯에 둘 수 있습니다.\n\n추가 `bytes data` 인자는 확장 가능한 메서드 동작을 위한 [ERC-5750](/eip-5750/) 패턴을 따릅니다.\n\n## 샘플 코드\n\n레지스트리에서 두 개의 의존성을 가져오는 dependant 컨트랙트:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IContractsRegistry {\n    function getContract(string memory name) external view returns (address);\n}\n\n/// `Dependant` as in the ERC's reference implementation (stores the injector,\n/// exposes the `dependant` modifier that checks and then records msg.sender).\nimport {Dependant} from \"./Dependant.sol\";\n\ncontract Vault is Dependant {\n    address public oracle;\n    address public treasury;\n\n    function setDependencies(address registry, bytes memory) public override dependant {\n        IContractsRegistry r = IContractsRegistry(registry);\n        oracle = r.getContract(\"ORACLE\");\n        treasury = r.getContract(\"TREASURY\");\n    }\n}\n```\n\n배포 흐름(의사 코드):\n\n```text\nregistry.addContract(\"ORACLE\", oracleAddr)\nregistry.addProxyContract(\"TREASURY\", treasuryImpl)\nregistry.addProxyContract(\"VAULT\", vaultImpl)\nregistry.injectDependencies(\"VAULT\")       // Vault reads ORACLE and TREASURY\n// later: swap the oracle and re-inject\nregistry.addContract(\"ORACLE\", newOracle)\nregistry.injectDependencies(\"VAULT\")\n```\n\n## 알아둘 점\n\n- 상태는 **Last Call**입니다. final에 가깝지만 세부 사항은 아직 바뀔 수 있습니다.\n- 레지스트리 소유자가 모든 업그레이드를 제어합니다. 그 키를 잃거나 유출하면 프로토콜 전체가 위험해지므로 멀티시그나 거버넌스를 사용하세요.\n- 레지스트리는 구현 간 호환성 검사를 하지 않습니다. 업그레이드 시 스토리지 레이아웃의 안전성은 여러분의 책임입니다.\n- injector가 처음에는 0이므로 첫 `setDependencies` 호출은 프론트러닝될 수 있습니다. 배포 직후, 가능하면 같은 트랜잭션에서 의존성을 주입하세요.\n- 이벤트는 필터링 편의성 대신 가독성을 택해 일부러 인덱싱되지 않은 `string` 이름을 사용합니다.\n"},"zh":{"lang":"zh","tldr":"一个标准的 ContractsRegistry 加上 Dependant 混入合约，为协议提供一个链上的统一位置，通过依赖注入来注册、升级并连接它的各个合约。","tags":["registry","upgradeability","proxy","dependency-injection","architecture"],"related":[1967,5750,2535,1822],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-6224/","markdown":"## 它解决什么问题？\n\n一个真实的协议由许多相互指向的合约组成：金库需要预言机，预言机需要价格源，依此类推。团队通常把这些地址硬编码在构造函数或初始化函数中，一旦某个合约被替换或升级就很头疼：所有依赖它的合约都得手动更新。\n\nERC-6224 提出了一种标准架构：一个了解协议所有合约的 **ContractsRegistry**（可选地为它们部署可升级代理），以及一个 **Dependant** 基础合约，让注册表按需把依赖推送到每个合约中。\n\n## 它如何运作\n\n**ContractsRegistry**（`IContractsRegistry`）：\n\n- 合约由人类可读的 `string` 名称标识。\n- `addContract(name, addr)` 注册一个普通的、不可升级的合约。\n- `addProxyContract(name, impl)` / `addProxyContractAndCall(name, impl, data)` 在某个实现之上部署代理，这样注册表之后可以对其执行 `upgradeContract` / `upgradeContractAndCall`。\n- `justAddProxyContract(name, proxy)` 接管一个已有的代理（例如迁移到新注册表时，新注册表必须持有升级权限）。\n- 如果没有注册任何内容，`getContract(name)` 会 revert；`hasContract(name)` 检查是否存在；`removeContract(name)` 负责删除。\n- 注册 `address(0)` 必须 revert。\n- `injectDependencies(name)` / `injectDependenciesWithData(name, data)` 会调用指定名称合约的 `setDependencies(address(this), data)`。\n\n**Dependant**（`IDependant`）：\n\n- 协议中每个独立的合约都继承它，并**在 `setDependencies` 中**读取其依赖，而不是在构造函数或初始化函数中。\n- 只有当前的 **injector** 才能调用 `setDependencies` 和 `setInjector`。injector 初始为零，因此首次调用是被允许的；参考实现随后把调用者记录为 injector。\n- injector 地址可以存放在槽位 `bytes32(uint256(keccak256(\"eip6224.dependant.slot\")) - 1)` 中，这是一个 [ERC-1967](/eip-1967/) 风格的存储槽。\n\n额外的 `bytes data` 参数遵循 [ERC-5750](/eip-5750/) 中用于可扩展方法行为的模式。\n\n## 示例代码\n\n一个从注册表获取两个依赖的 dependant 合约：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IContractsRegistry {\n    function getContract(string memory name) external view returns (address);\n}\n\n/// `Dependant` as in the ERC's reference implementation (stores the injector,\n/// exposes the `dependant` modifier that checks and then records msg.sender).\nimport {Dependant} from \"./Dependant.sol\";\n\ncontract Vault is Dependant {\n    address public oracle;\n    address public treasury;\n\n    function setDependencies(address registry, bytes memory) public override dependant {\n        IContractsRegistry r = IContractsRegistry(registry);\n        oracle = r.getContract(\"ORACLE\");\n        treasury = r.getContract(\"TREASURY\");\n    }\n}\n```\n\n部署流程（伪代码）：\n\n```text\nregistry.addContract(\"ORACLE\", oracleAddr)\nregistry.addProxyContract(\"TREASURY\", treasuryImpl)\nregistry.addProxyContract(\"VAULT\", vaultImpl)\nregistry.injectDependencies(\"VAULT\")       // Vault reads ORACLE and TREASURY\n// later: swap the oracle and re-inject\nregistry.addContract(\"ORACLE\", newOracle)\nregistry.injectDependencies(\"VAULT\")\n```\n\n## 需要注意\n\n- 状态为 **Last Call**：接近定稿，但细节仍可能变化。\n- 注册表所有者控制每一次升级。丢失或泄露该密钥会危及整个协议；请使用多签或治理。\n- 注册表不会对各实现之间做兼容性检查；升级时存储布局的安全性由你自己负责。\n- 由于 injector 初始为零，首次 `setDependencies` 调用可能被抢跑（front-run）。请在部署后立即注入依赖，最好在同一笔交易中完成。\n- 事件有意使用非 indexed 的 `string` 名称，以可过滤性换取可读性。\n"}}}
