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 examines ERC-8167.

ERC-8167 defines a Modular Dispatch Proxy that selects a delegatecall destination based on the first four bytes of the received calldata, namely the function selector. Rather than forwarding every call from a proxy to a single implementation contract, it allows logic to be split by functionality and defines a minimal interface through which tools can discover the ABI and track changes.

Overview

ERC-8167 standardizes proxies that maintain a selector -> delegate mapping. During execution, the proxy performs a delegatecall to the delegate corresponding to msg.sig. For introspection, selectors() and implementation(bytes4) expose which functions are routed to which logic contracts.

The following figure illustrates the overall execution model of ERC-8167.

ERC-8167 execution overview

At runtime, the proxy selects a delegate based on the selector and forwards the original calldata using delegatecall. For introspection, the key feature is that external tools can reconstruct the proxy's function set using implementation(bytes4) and selectors(). ERC-8167 is thus a minimal standard intended to facilitate modular functionality and incremental upgrades while allowing tools to discover the ABI and track changes.

Motivation

Limitations of a single-implementation proxy

A conventional upgradeable proxy forwards incoming calls to a single implementation. Although this structure is easy to understand, the implementation grows as more features are added, and changes often require replacing it in its entirety.

This creates several problems.

  • The implementation can approach the contract code size limit.
  • Even a small fix requires replacing the entire implementation.
  • Adding extensions can increase the impact on existing functionality.
  • Audits and code reviews must cover larger units of change.

ERC-8167 addresses these problems by allowing different functionality to be assigned to separate delegates.

Combining shared logic with extensions

Token balance management and transfers are examples of logic that can be shared across multiple contracts. Names and issuance policies, on the other hand, may vary between deployments and benefit from separate modules. With a single implementation, these differences can lead to separate implementations for each deployment. Selector-based dispatch allows only the common functionality to be assigned to a shared module.

When a new extension standard is introduced, the relevant group of functions can also be installed as a separate module. Potential use cases include smart accounts and extensible tokens.

For more on EIP-7702, see the following article.

[EIP-7702] Enabling Contract Account Behavior for EOAs

Incremental upgrades and hardening

Monolithic proxies tend to introduce large sets of changes with each upgrade. ERC-8167 supports adding, updating, or removing delegates at the selector level, allowing smaller changes.

Removing the methods responsible for upgrades can also support hardening the proxy toward an immutable configuration, provided no other modification paths remain. This makes it easier to operate a contract as upgradeable initially and close its upgrade paths once the implementation is sufficiently mature.

The following figure illustrates the transition from an upgradeable configuration to a hardened one.

Upgrades and hardening

Specification

Execution rules

A Modular Dispatch Proxy must use delegatecall to forward the original calldata to the delegate associated with its first four bytes. The proxy is not expected to rearrange arguments or convert the call to a custom ABI.

The selector is the existing four-byte selector defined by the Solidity ABI. ERC-8167 does not introduce a new dispatch identifier; it reuses the existing ABI selector as a routing key.

When no delegate is registered for the specified selector, reverting with FunctionNotFound(bytes4 selector) is recommended. This is RECOMMENDED rather than REQUIRED.

IERC8167

The interface is defined as follows.

js
interface IERC8167 {
    event SelectorDelegated(bytes4 indexed selector, address indexed delegate);
    function implementation(bytes4 selector) external view returns (address);
    function selectors() external view returns (bytes4[] memory);
    error FunctionNotFound(bytes4 selector);
}

Each element serves the following purpose.

Element Kind Requirement Purpose
SelectorDelegated Event Recommended Records changes to selector assignments.
implementation(bytes4) Function Required Returns the delegate associated with a selector.
selectors() Function Required Returns the registered selectors and facilitates ABI discovery.
FunctionNotFound Error Recommended Identifies a missing selector as the reason for failure.

Implementing the IERC8167 functions in a delegate rather than directly in the proxy is also recommended. This allows the proxy itself to focus on selector lookup and delegation, with administrative and introspection functionality implemented in delegates.

implementation(bytes4 selector)

js
function implementation(bytes4 selector) external view returns (address);

This function returns the delegate address associated with a selector. If the selector is not registered, it returns address(0).

External tools can use this common interface to determine where a selector is routed without knowing the proxy's storage layout.

Although eth_getStorageAt may also be used to inspect the mapping in some implementations, a standard interface avoids requiring tools to understand different storage layouts.

selectors()

js
function selectors() external view returns (bytes4[] memory);

This function returns the selectors that currently have an implementation. It is central to the value ERC-8167 provides to external tooling.

A selector alone does not reveal the function name or parameter types. However, the proxy ABI can be reconstructed using the following process.

  1. Retrieve the selector list with selectors(). Collect the function selectors exposed by the proxy.
  2. Call implementation(selector) for each selector. Identify the delegate responsible for each selector.
  3. Obtain the verified ABI of each delegate. If its source code is verified, the ABI can be retrieved. Otherwise, users may need to supply the missing information.
  4. Match selectors against the delegate ABIs to reconstruct the proxy's function set. Multiple selectors assigned to the same delegate can be grouped at this stage.

The following figure illustrates this discovery process.

ABI discovery process

Selectors could also be collected from SelectorDelegated event logs, but selectors() provides an entry point that does not depend on log searches. This simplifies tooling considerably, especially in environments without an indexer.

Constructor expectations

The dispatch proxy's constructor should configure at least one delegate. Deploying an empty proxy and registering all delegates afterward is not explicitly prohibited, but the proposal recommends providing a minimal bootstrapping capability.

Rationale

Why use bytes4 selector?

The four-byte selector is the established entry point of the Solidity ABI. Reusing it instead of introducing a new identifier makes integration with existing ABI tooling easier.

Why not standardize the upgrade process?

ERC-8167 focuses on a minimal standard for dispatch proxies. It does not prescribe the design of upgrade functions or version management.

This is intentional. Access control, batch upgrades, governance, and timelocks vary considerably across use cases. Standardizing all these features would expand the scope beyond a minimal interface. ERC-8167 standardizes selector-based dispatch and the corresponding introspection functions, leaving operational policies to other standards or individual implementations.

Why not prescribe a storage layout?

ERC-8167 does not prescribe a storage layout either. Implementations may use namespaced storage or inherit a common base storage layout, depending on their architecture.

Storage collisions must still be avoided. The standard leaves storage layout flexible while assigning responsibility for collision prevention to implementers.

For more on ERC-7201, see the following article.

[ERC-7201] Namespaced Storage for Smart Contracts

Compatibility

ERC-8167 is presented as an improvement on ERC-2535, an existing modular proxy standard. The proposal identifies three principal differences.

  • Replace diamond-specific terminology with more general terminology.
  • Reduce the number of introspection functions and simplify the interface.
  • Simplify upgrade events.

The following figure summarizes these differences.

Differences from ERC-2535

For more on ERC-2535, see the following article.

[ERC-2535] Understanding the Diamond Pattern

Like ERC-2535, ERC-8167 routes function selectors to logic modules, but it defines a smaller standardized surface. In particular, it retains the minimum functionality needed by tooling.

The proposed migration path from a monolithic proxy is as follows.

  1. Upgrade to an implementation capable of populating a selector-to-delegate mapping.
  2. Populate the mapping for the existing ABI functions and introspection functions.
  3. Switch to a dispatch proxy implementation that uses the mapping.

An existing modular proxy can move toward conformance by adding selectors() and implementation(bytes4), and, where appropriate, emitting SelectorDelegated for installed functions.

Reference implementation

The reference implementation consists of three files.

File Purpose
IERC8167.sol Defines the standard interface.
ProxyStorageBase.sol Defines namespaced storage for selector information.
Proxy.sol Implements Setup, FullAdmin, ProxyStorageView, and Proxy.

The following figure summarizes the responsibilities of the reference implementation.

Reference implementation responsibilities

ProxyStorageBase.sol

The reference implementation stores information for each selector in the following struct.

js
struct SelectorInfo {
    address delegate;
    uint96 index;
}

The delegate field contains the forwarding destination. The index field records the position in the selectors array, enabling O(1) removal using swap-and-pop.

Setup and FullAdmin

The Setup module provides the initial installation functionality. FullAdmin adds upgrade and uninstall to that functionality.

The functions have the following responsibilities.

Function Purpose Main checks
install(bytes4 selector, address delegate) Registers a new selector. Nonzero delegate address, existing code, selector not already registered.
upgrade(bytes4 selector, address delegate) Replaces the delegate of an existing selector. Nonzero delegate address, existing code, selector already registered.
uninstall(bytes4 selector) Removes a selector assignment. Selector already registered.

Each operation emits SelectorDelegated when successful. Removal is represented by a delegate value of address(0).

ProxyStorageView

The reference implementation groups selectors() and implementation(bytes4) in a delegate named ProxyStorageView. This follows the recommendation to implement the IERC8167 functions in a delegate rather than directly in the proxy.

The proxy itself can handle selector lookup and delegation, while the introspection interface resides in the ProxyStorageView delegate.

Bootstrapping the Proxy constructor

An interesting aspect of the reference implementation is its constructor. At deployment, it creates a new Setup delegate and registers its own install function as the initial selector.

js
constructor() {
    address installDelegate = address(new Setup(msg.sender));
    (bool success,) = installDelegate.delegatecall(
        abi.encodeWithSelector(
            Setup.install.selector,
            Setup.install.selector,
            installDelegate
        )
    );
    require(success);
}

The proxy therefore supports at least the install function immediately after deployment. This directly implements the recommendation that the constructor SHOULD configure at least one delegate.

The following figure illustrates the bootstrap sequence.

Constructor bootstrap sequence

Security considerations

Access control

Although ERC-8167 does not define upgrade functions, implementations that support upgrades require access control. Because the implementation can be replaced for individual selectors, compromising administrative controls can compromise the entire proxy's behavior.

At a minimum, the design should address the following questions.

  • Who can call install, upgrade, and uninstall?
  • Do changes take effect immediately, or is there a timelock?
  • What atomicity guarantees apply to batched changes?
  • Are administrative modification paths truly unavailable after hardening?

Avoid delegates that can self-destruct

Delegates must not be able to self-destruct. If a delegate's code disappears, proxies depending on that module can no longer execute the corresponding functionality as intended. Even if the proxy's state remains intact, the loss of the destination code can effectively break it. Whether SELFDESTRUCT removes code depends on the chain's execution rules.

Storage collisions

Storage collisions are one of the most common failure modes in modular architectures based on delegatecall. If different modules assign different meanings to the same storage slot, upgrading or extending the proxy can corrupt its state.

The following figure illustrates two safer approaches and a collision-prone design.

Preventing storage collisions

There are two principal approaches to preventing collisions.

  1. Have all delegates share the storage layout of a common superclass. Subclasses must not independently declare additional storage that conflicts with that shared layout.
  2. Use storage namespaces. This approach is particularly useful for shared-library-style modules that do not fit a common base storage layout.

ERC-7201 and ERC-8042 are cited as examples of the second approach. Although selector-level module replacement is convenient, mixing incompatible storage layouts can expand the impact of failures. This is an important consideration in the proposal.

Conclusion

This article covered ERC-8167.

ERC-8167 standardizes modular proxies that select a delegatecall destination for each function selector. Its minimal interface supports both runtime dispatch and ABI discovery by external tools. Rather than placing all logic in a single implementation, it facilitates feature-specific modules, incremental upgrades, and eventual hardening. Access control, storage collision prevention, and delegate lifecycle management remain responsibilities of individual implementations.

I also publish articles and other resources on the following platforms.