Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers ERC6224, a proposal for managing the smart contracts used by a decentralized protocol in one place and safely replacing or upgrading them as needed.
This article translates, summarizes, and adds explanations to the specification linked below.
I also cover various EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs:
Overview
ERC6224 proposes an on-chain registry system that allows decentralized protocols to manage their smart contracts efficiently.
The system consists of two main components.
| Component | Role |
|---|---|
| ContractsRegistry | Stores references to all smart contracts used by the protocol. It can deploy self-managed proxies as needed to support upgrades. |
| Dependant | Retrieves and uses dependencies registered in the ContractsRegistry. |
ContractsRegistry acts as a hub for managing the protocol's contracts in one place and flexibly upgrading or replacing them. Dependant, in turn, provides a mechanism for retrieving the required dependencies from the registry.
In other words, ERC6224 proposes a framework for organizing the contract architecture of an entire protocol and managing upgrades and dependencies safely and flexibly.
Motivation
As the Ethereum ecosystem develops, projects are growing rapidly in size and complexity. Many modern decentralized applications (DApps) and protocols face the following challenges.
- Continuous delivery and improvement of features Protocols need to add new features and refine existing ones frequently to meet users' needs.
- Constraints imposed by blockchain immutability Smart contract code generally cannot be modified once deployed. This makes subsequent fixes and upgrades difficult.
- Managing complex dependencies As dependencies between contracts multiply, it becomes harder to tell which contracts use which functionality, reducing the maintainability of the entire system.
- Increasing risk of bugs Continuous development and growing architectural complexity increase the risk of introducing bugs and make debugging and fixes more difficult.
Against this background, ERC6224 has the following goals.
- Maintain a clear architecture Keep the roles and dependencies of individual components explicit and easy to understand.
- Design for future extensions Allow features and contracts to be added or changed without breaking the existing system.
- Make dependencies transparent and manageable Make it clear which dependencies each contract uses and allow them to be replaced dynamically when necessary.
Benefits
Adopting the proposed ContractsRegistry and Dependant system offers protocol architects and developers the following benefits.
| Benefit | Description |
|---|---|
| Structured smart contract management | Manage all dependency contracts centrally through a dedicated management contract (ContractsRegistry). |
| Flexible upgrades | Support ad hoc, partial upgrades at the protocol level. |
| Runtime contract management | Safely add, remove, or replace smart contracts at runtime. |
| Dependency injection | Use Dependant to retrieve the required dependencies from the registry securely. |
| Flexible access control | Define custom access control rules for protocol maintenance. |
These benefits can substantially improve the flexibility and maintainability of a system. The ability to change dependencies and fix bugs on-chain also provides a foundation for ongoing improvements to a project.
Specification
Overview
ERC6224 consists of the following two smart contract components.
| Contract | Description |
|---|---|
| ContractsRegistry | A single (singleton) registry for registering, managing, and upgrading smart contracts used by a protocol. |
| Dependant | A contract that refers to information held in the registry. |
The relationship between these contracts can be described as follows.
- ContractsRegistry serves as the central hub of the protocol and holds references to all its contracts.
- Dependant relies on the registry and retrieves the information it needs to operate.
ContractsRegistry
ContractsRegistry is the core contract in ERC6224 and holds references to all standalone contracts used by the protocol. It can also be configured to deploy optional proxy contracts for registered implementations.
Specification
ContractsRegistrymust reject registration of the zero address (address(0)).- Registered contracts are referenced by name and can be upgraded or removed.
- The registry can provide references and add or upgrade proxies, among other operations.
pragma solidity ^0.8.0;
interface IContractsRegistry {
event ContractAdded(string name, address contractAddress);
event ProxyContractAdded(string name, address contractAddress, address implementation);
event ProxyContractUpgraded(string name, address newImplementation);
event ContractRemoved(string name);
function getContract(string memory name) external view returns (address);
function hasContract(string memory name) external view returns (bool);
function injectDependencies(string memory name) external;
function injectDependenciesWithData(string memory name, bytes memory data) external;
function upgradeContract(string memory name, address newImplementation) external;
function upgradeContractAndCall(string memory name, address newImplementation, bytes memory data) external;
function addContract(string memory name, address contractAddress) external;
function addProxyContract(string memory name, address contractAddress) external;
function addProxyContractAndCall(string memory name, address contractAddress, bytes memory data) external;
function justAddProxyContract(string memory name, address contractAddress) external;
function removeContract(string memory name) external;
}ContractAdded
event ContractAdded(string name, address contractAddress);An event emitted when a new contract is added to the registry.
This event is emitted when the addContract function is called.
It indicates that a contract has been registered successfully.
Parameters
nameName of the registered contract.contractAddressAddress of the registered contract.
ProxyContractAdded
event ProxyContractAdded(string name, address contractAddress, address implementation);An event emitted when a new proxy contract is added to the registry.
It is emitted on calls to addProxyContract or addProxyContractAndCall.
It records both the proxy address and the address of the implementation it references.
Parameters
nameRegistered name.contractAddressAddress of the deployed proxy.implementationAddress of the implementation referenced by the proxy.
ProxyContractUpgraded
event ProxyContractUpgraded(string name, address newImplementation);An event emitted when an existing proxy is upgraded to a new implementation.
It is emitted on calls to upgradeContract or upgradeContractAndCall.
The event records the address of the new implementation.
Parameters
nameName of the upgraded contract.newImplementationAddress of the new implementation.
ContractRemoved
event ContractRemoved(string name);An event emitted when a contract is removed from the registry.
It is emitted when removeContract is called.
Parameters
nameName of the removed contract.
getContract
function getContract(string memory name) external view returns (address);Retrieves the contract registered under a specified name. It returns the address registered for the contract. It reverts if the address is zero.
Arguments
nameRegistered contract name.
Return value
addressAddress of the registered contract.
hasContract
function hasContract(string memory name) external view returns (bool);Checks whether a contract with the specified name exists.
It returns true if the contract is registered.
Arguments
nameContract name.
Return value
boolWhether the contract exists.
injectDependencies
function injectDependencies(string memory name) external;Injects information about the other contracts required by a specified contract.
When this function is executed, it calls
setDependencies(address(this), bytes("")) on the target contract,
allowing the target to learn the addresses of other contracts it uses from the registry.
No additional data is passed; only the basic configuration is performed.
Arguments
nameName of the contract to configure.
injectDependenciesWithData
function injectDependenciesWithData(string memory name, bytes memory data) external;Injects information about other contracts into a specified contract while passing additional data.
When this function is executed, it calls setDependencies(address(this), data) on the target contract.
The data parameter can contain extra information for context-specific configuration or initialization. The registry passes it to the target contract along with the information needed to resolve dependencies.
Arguments
nameName of the contract to configure.dataAdditional information to pass (optional).
upgradeContract
function upgradeContract(string memory name, address newImplementation) external;Upgrades an existing proxy contract to a new implementation.
The owner is responsible for checking compatibility.
A ProxyContractUpgraded event is emitted after the upgrade.
Arguments
nameProxy contract name.newImplementationAddress of the new implementation.
upgradeContractAndCall
function upgradeContractAndCall(string memory name, address newImplementation, bytes memory data) external;Upgrades a proxy to a new implementation and makes a call using specified data, for example to initialize it.
In addition to the behavior of upgradeContract, this function allows a call with data after the upgrade.
Arguments
nameContract name.newImplementationAddress of the new implementation.dataCall data, such as an ABI-encoded function call.
addContract
function addContract(string memory name, address contractAddress) external;Adds a non-proxy contract to the registry. It is used to register contracts that do not need upgrades or external dependencies.
Arguments
nameContract name.contractAddressAddress of the contract to register.
addProxyContract
function addProxyContract(string memory name, address contractAddress) external;Adds a proxy contract to the registry given an implementation address. It is used to register an upgradeable contract.
Arguments
nameContract name.contractAddressAddress of the implementation.
addProxyContractAndCall
function addProxyContractAndCall(string memory name, address contractAddress, bytes memory data) external;Adds a proxy contract with accompanying call data. This allows flexible registration, such as calling an initializer when the proxy is added.
Arguments
nameContract name.contractAddressAddress of the implementation.dataFor example, an ABI-encoded initialization call.
justAddProxyContract
function justAddProxyContract(string memory name, address contractAddress) external;Adds an already deployed proxy contract to the registry. It can be used during system migrations. The new registry needs to have the authority to upgrade the proxy.
Arguments
nameContract name.contractAddressAddress of the existing proxy.
removeContract
function removeContract(string memory name) external;Removes a registered contract.
It removes the target contract from the registry.
A ContractRemoved event is emitted upon removal.
Arguments
nameName of the contract to remove.
Dependant
Dependant is a contract component that works with ContractsRegistry.
All standalone protocol contracts participating in this dependency injection model must inherit Dependant.
Dependencies are configured through setDependencies, rather than a constructor or initialization function.
Access control is also necessary when configuring information about other contracts.
Interface
pragma solidity ^0.8.0;
interface IDependant {
function setDependencies(address contractsRegistry, bytes memory data) external;
function setInjector(address injector) external;
function getInjector() external view returns (address);
}setDependencies
function setDependencies(address contractsRegistry, bytes memory data) external;Called by ContractsRegistry to configure the dependencies that the specified contract uses.
In this usage, the function checks that msg.sender is the authorized injector, which is typically ContractsRegistry.
It retrieves information such as addresses of dependency contracts from the registry and configures them internally.
In this way, an external registry supplies the information that the contract needs.
Arguments
contractsRegistryAddress of the registry from which information is retrieved.dataAdditional context-specific information (for example, for initialization).
setInjector
function setInjector(address injector) external;Sets a new injector. The function specifies who is allowed to supply dependency information to the contract. Call permissions are controlled so that only authorized addresses can change the setting.
Arguments
injectorAddress of the new injector.
getInjector
function getInjector() external view returns (address);Retrieves the address of the currently configured injector. Calling it returns the address currently authorized to supply dependency information to the contract.
Return value
addressAddress of the current injector.
Storage slot specification
A Dependant contract can store the address of its injector (typically ContractsRegistry)
in a particular storage slot.
The slot is defined by the following expression.
0x3d1f25f1ac447e55e7fec744471c4dab1c6a2b6ffb897825f9ea3d2e8c9be583This value is derived as follows.
bytes32(uint256(keccak256("eip6224.dependant.slot")) - 1)Reserving a specific slot in this way helps avoid collisions with other storage variables and allows the injector address to be stored in a secure, standardized manner.
Additional considerations
ContractsRegistry design
Contract identifiers
ContractsRegistry uses string identifiers to identify contracts.
Alternatives such as uint256 and bytes32 were considered, but strings were chosen for the following reasons.
| Consideration | Description |
|---|---|
| Readability | String names make contract identifiers easier for humans to understand. Referring to contracts by name is particularly intuitive when interacting directly through a block explorer or DAO. |
| Prevention of operator error | Using string names rather than numbers or hashes can help reduce human errors, such as selecting the wrong identifier. |
| User-oriented design | ContractsRegistry is central to the protocol and is likely to be accessed directly by users and developers, so ease of use takes priority. |
The trade-off is that this design is less gas-efficient. However, the design deliberately prioritizes clarity over gas efficiency.
Because strings are used, the relevant event parameters (for example, in ContractAdded) are not marked indexed.
An indexed string is represented by a keccak256 hash rather than its original text, making the name difficult to read directly from an event log. This applies to dynamic strings regardless of length, although the Japanese source specifically mentions strings longer than 32 bytes.
The parameters therefore remain non-indexed, deliberately prioritizing human readability over searchability.
Reverts
The getContract function reverts if the address of the requested contract is address(0) (unregistered).
This is required to prevent incorrect protocol initialization or use of an unregistered dependency.
The order of contract registration is also important for maintaining registry consistency.
All necessary contracts must be correctly registered in ContractsRegistry before their dependencies are configured.
Similarly, the following functions revert if address(0) is provided.
| Function | Reason |
|---|---|
addContract |
Report an error when an attempt is made to register an invalid address. |
addProxyContract |
Prevent registration with a zero implementation address. |
addProxyContractAndCall |
Apply the same protection to registration with initialization. |
justAddProxyContract |
Reject a zero address when registering an existing proxy. |
Explicitly rejecting the zero address in all registration functions helps prevent incorrect registrations and protocol inconsistencies.
Dependant design
Data parameter
The setDependencies function of Dependant has a data parameter.
This parameter is intended for passing application-specific contextual information.
It allows each contract to perform different initialization or configuration operations.
For example, it can support the following behavior.
- One contract receives particular role settings or token information at initialization.
- Another module receives configuration data for an external service along with its dependencies.
The data parameter is therefore designed as a flexible hook for extending the standard dependency injection mechanism.
Injector
The setInjector function sets the injector authorized to supply dependency information to a contract.
It is declared external and can be called from outside the contract.
This design also supports contracts created by a factory contract.
Contracts created through a factory may not automatically receive the address of ContractsRegistry at deployment time.
They therefore need a way to configure the registry afterward using setInjector.
However, because the function is externally callable, strict access control is recommended.
An unauthorized caller could substitute a different registry. Implementations should therefore use suitable authorization, such as an onlyOwner or onlyInjector modifier.
Reference implementation
ContractsRegistry
pragma solidity ^0.8.0;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {Dependant} from "./Dependant.sol";
interface IContractsRegistry {
event ContractAdded(string name, address contractAddress);
event ProxyContractAdded(
string name,
address contractAddress,
address implementation
);
event ProxyContractUpgraded(string name, address newImplementation);
event ContractRemoved(string name);
function getContract(string memory name) external view returns (address);
function hasContract(string memory name) external view returns (bool);
function injectDependencies(string memory name) external;
function injectDependenciesWithData(string memory name, bytes memory data)
external;
function upgradeContract(string memory name, address newImplementation)
external;
function upgradeContractAndCall(
string memory name,
address newImplementation,
bytes memory data
) external;
function addContract(string memory name, address contractAddress) external;
function addProxyContract(string memory name, address contractAddress)
external;
function addProxyContractAndCall(
string memory name,
address contractAddress,
bytes memory data
) external;
function justAddProxyContract(string memory name, address contractAddress)
external;
function removeContract(string memory name) external;
}
contract ProxyUpgrader {
using Address for address;
address private immutable _OWNER;
modifier onlyOwner() {
_onlyOwner();
_;
}
constructor() {
_OWNER = msg.sender;
}
function upgrade(address what_, address to_, bytes calldata data_) external onlyOwner {
if (data_.length > 0) {
TransparentUpgradeableProxy(payable(what_)).upgradeToAndCall(to_, data_);
} else {
TransparentUpgradeableProxy(payable(what_)).upgradeTo(to_);
}
}
function getImplementation(address what_) external view onlyOwner returns (address) {
// bytes4(keccak256("implementation()")) == 0x5c60da1b
(bool success_, bytes memory returndata_) = address(what_).staticcall(hex"5c60da1b");
require(success_, "ProxyUpgrader: not a proxy");
return abi.decode(returndata_, (address));
}
function _onlyOwner() internal view {
require(_OWNER == msg.sender, "ProxyUpgrader: not an owner");
}
}
contract ContractsRegistry is IContractsRegistry, OwnableUpgradeable {
ProxyUpgrader private _proxyUpgrader;
mapping(string => address) private _contracts;
mapping(address => bool) private _isProxy;
function __ContractsRegistry_init() public initializer {
_proxyUpgrader = new ProxyUpgrader();
__Ownable_init();
}
function getContract(string memory name_) public view returns (address) {
address contractAddress_ = _contracts[name_];
require(
contractAddress_ != address(0),
"ContractsRegistry: this mapping doesn't exist"
);
return contractAddress_;
}
function hasContract(string memory name_) public view returns (bool) {
return _contracts[name_] != address(0);
}
function getProxyUpgrader() external view returns (address) {
return address(_proxyUpgrader);
}
function injectDependencies(string memory name_) public virtual onlyOwner {
injectDependenciesWithData(name_, bytes(""));
}
function injectDependenciesWithData(string memory name_, bytes memory data_)
public
virtual
onlyOwner
{
address contractAddress_ = _contracts[name_];
require(
contractAddress_ != address(0),
"ContractsRegistry: this mapping doesn't exist"
);
Dependant dependant_ = Dependant(contractAddress_);
dependant_.setDependencies(address(this), data_);
}
function upgradeContract(string memory name_, address newImplementation_)
public
virtual
onlyOwner
{
upgradeContractAndCall(name_, newImplementation_, bytes(""));
}
function upgradeContractAndCall(
string memory name_,
address newImplementation_,
bytes memory data_
) public virtual onlyOwner {
address contractToUpgrade_ = _contracts[name_];
require(
contractToUpgrade_ != address(0),
"ContractsRegistry: this mapping doesn't exist"
);
require(
_isProxy[contractToUpgrade_],
"ContractsRegistry: not a proxy contract"
);
_proxyUpgrader.upgrade(contractToUpgrade_, newImplementation_, data_);
emit ProxyContractUpgraded(name_, newImplementation_);
}
function addContract(string memory name_, address contractAddress_)
public
virtual
onlyOwner
{
require(
contractAddress_ != address(0),
"ContractsRegistry: zero address is forbidden"
);
_contracts[name_] = contractAddress_;
emit ContractAdded(name_, contractAddress_);
}
function addProxyContract(string memory name_, address contractAddress_)
public
virtual
onlyOwner
{
addProxyContractAndCall(name_, contractAddress_, bytes(""));
}
function addProxyContractAndCall(
string memory name_,
address contractAddress_,
bytes memory data_
) public virtual onlyOwner {
require(
contractAddress_ != address(0),
"ContractsRegistry: zero address is forbidden"
);
address proxyAddr_ = _deployProxy(
contractAddress_,
address(_proxyUpgrader),
data_
);
_contracts[name_] = proxyAddr_;
_isProxy[proxyAddr_] = true;
emit ProxyContractAdded(name_, proxyAddr_, contractAddress_);
}
function justAddProxyContract(string memory name_, address contractAddress_)
public
virtual
onlyOwner
{
require(
contractAddress_ != address(0),
"ContractsRegistry: zero address is forbidden"
);
_contracts[name_] = contractAddress_;
_isProxy[contractAddress_] = true;
emit ProxyContractAdded(
name_,
contractAddress_,
_proxyUpgrader.getImplementation(contractAddress_)
);
}
function removeContract(string memory name_) public virtual onlyOwner {
address contractAddress_ = _contracts[name_];
require(
contractAddress_ != address(0),
"ContractsRegistry: this mapping doesn't exist"
);
delete _isProxy[contractAddress_];
delete _contracts[name_];
emit ContractRemoved(name_);
}
function _deployProxy(
address contractAddress_,
address admin_,
bytes memory data_
) internal virtual returns (address) {
return
address(
new TransparentUpgradeableProxy(contractAddress_, admin_, data_)
);
}
}Dependant
pragma solidity ^0.8.0;
interface IDependant {
function setDependencies(address contractsRegistry, bytes memory data) external;
function setInjector(address injector) external;
function getInjector() external view returns (address);
}
abstract contract Dependant is IDependant {
/**
* @dev bytes32(uint256(keccak256("eip6224.dependant.slot")) - 1)
*/
bytes32 private constant _INJECTOR_SLOT =
0x3d1f25f1ac447e55e7fec744471c4dab1c6a2b6ffb897825f9ea3d2e8c9be583;
modifier dependant() {
_checkInjector();
_;
_setInjector(msg.sender);
}
function setDependencies(address contractsRegistry_, bytes memory data_) public virtual;
function setInjector(address injector_) external {
_checkInjector();
_setInjector(injector_);
}
function getInjector() public view returns (address injector_) {
bytes32 slot_ = _INJECTOR_SLOT;
assembly {
injector_ := sload(slot_)
}
}
function _setInjector(address injector_) internal {
bytes32 slot_ = _INJECTOR_SLOT;
assembly {
sstore(slot_, injector_)
}
}
function _checkInjector() internal view {
address injector_ = getInjector();
require(injector_ == address(0) || injector_ == msg.sender, "Dependant: not an injector");
}
}Security
General considerations
The owner (administrator) of ContractsRegistry must keep their private keys secure.
If the owner's keys are compromised or lost, protocol administration can become effectively impossible, potentially creating a point of no return.
ContractsRegistry is the hub of the protocol and provides a mechanism for administering all its contracts.
Access should therefore be restricted to fully trusted parties, and robust administrative controls such as multisignature wallets or hardware wallets are strongly recommended.
ContractsRegistry security
ContractsRegistry supports upgrades, but it does not automatically verify compatibility between the new and existing implementations.
When upgrading a proxy using upgradeContract or upgradeContractAndCall, developers or owners are responsible for verifying compatibility.
Selecting the wrong implementation can break the entire protocol or render it inoperable.
| Risk | Description | Mitigation |
|---|---|---|
| Incompatible implementation upgrade | A new implementation that is incompatible with the previous version may break the protocol. | Check storage layouts and function signatures before upgrading. |
| Unauthorized registry operations | An attacker who obtains administrator privileges may be able to replace all contracts. | Enforce strict access control and strengthen signing controls. |
The security of ContractsRegistry is therefore not just a matter of code; it is closely connected to off-chain authority management, including private key management and multisignature configuration.
Dependant security
Dependant contracts also face particular risks during dependency configuration.
The timing of the first call to setDependencies is especially important.
Under the described security model, before the first setDependencies call, a Dependant
needs to have its injector configured.
If configuration is delayed, a third party may be able to submit the first call ahead of the intended caller.
This is a front-running risk.
| Consideration | Description |
|---|---|
| Front-running risk | If anyone can make the first setDependencies call, a malicious address may be able to set an unauthorized injector. |
| Impact | Once an unauthorized injector is configured, the contract may be unable to connect to the legitimate registry, and dependency information could be falsified. |
| Mitigation | Configure the legitimate injector immediately after deployment, preferably atomically, and enforce access control before the first call. |
Safe use of Dependant therefore requires configuring the injector promptly after deployment and preventing unauthorized parties from intervening.
Citation
Artem Chystiakov (@arvolear), "ERC-6224: Contracts Dependencies Registry [DRAFT]," Ethereum Improvement Proposals, no. 6224, December 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6224.
Conclusion
This article covered ERC6224, a proposal for managing a decentralized protocol's smart contracts centrally and safely replacing or upgrading them as needed. I hope this explanation was helpful.
If you have questions, feel free to contact me via Twitter DM:
You can also find my other articles on the following platforms:



