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 ERC7744, a proposal for indexing contract bytecode to support contract discovery and verification.

This article translates, summarizes, and expands on the proposal below.

I have also covered a range of other EIPs.

Overview

ERC7744 proposes a standard interface for indexing Ethereum contracts by the hash of their bytecode. Traditional address-based identification can obscure malicious implementation code when proxies are involved. Using bytecode hashes instead provides a more reliable basis for discovering and verifying specific code. Potential use cases include signing bytecode, maintaining allowlists, and decentralized distribution mechanisms.

Motivation

Contract discovery on Ethereum currently relies on addresses. Deployments of identical bytecode can occupy different addresses. Proxy contracts can also separate the address used to interact with a contract from its actual implementation logic, making code identification more difficult.

To address these problems, the proposal introduces a way to identify contract code by its bytecode hash, improving transparency and confidence in code identity.

Improving Security Audits and Code Verification

Consider a security auditor who wants to assess and attest to a contract's safety. Under the current approach, the auditor must identify the deployed contract address and examine deployment parameters and storage state. An address alone, however, cannot establish that the bytecode under audit is actually the code being executed.

With hash-based identification, the auditor can examine the code itself. Rather than relying on an address, the auditor can verify the identity and integrity of the bytecode by comparing its hash against the audited version. This makes the code under review explicit and improves the reliability of the audit process. It does not remove the need to inspect relevant storage, configuration, or delegated execution paths.

Allowlisting Before Deployment

Identifying contracts by their bytecode hashes makes it possible to allowlist code before deployment. This is useful in scenarios such as the following.

  • Obtaining prior approval for code

    Some protocols must restrict interactions to contracts that meet specific requirements. Registering bytecode hashes makes it possible to build a system that permits only preapproved code to be deployed or used within that system.

  • Automatic infrastructure adaptation

    A contract or off-chain service could detect when specific bytecode is deployed on-chain and adjust its behavior accordingly. An allowlist lets infrastructure take predefined actions when the expected code appears.

Preventing Proxy-Based Attacks and Unauthorized Changes

On Ethereum, proxy patterns can replace implementation logic without changing the address through which users interact. If this mechanism is abused, an implementation previously approved as legitimate could later be replaced with malicious code.

Hash-based identification makes it possible to check whether the expected code is being executed, provided that the implementation or other relevant execution targets are checked as well as the proxy itself. This is important for maintaining long-term trust and providing transparency to end users.

Reducing Gas Costs and Optimizing Resources

Many contracts in DApps share common logic. Traditionally, deploying separate contracts containing identical code incurs deployment gas costs each time.

With a bytecode-hash index, developers can discover and reference an existing instance instead of deploying another copy when reuse is appropriate. This approach can reduce contract development and operating costs. The index itself does not automatically eliminate deployment costs or make stateful contract instances interchangeable.

Why an ERC Standard Is Needed

There are several reasons to standardize this code indexing mechanism as an Ethereum ERC.

  • Ecosystem-wide consistency

    If every project implements its own bytecode identification scheme, incompatible approaches can fragment the ecosystem. An ERC gives projects a common way to identify and look up bytecode.

  • Simpler integration and adoption

    Contract developers can use a common interface, making it easier to incorporate the functionality into new projects.

  • Flexibility across use cases

    Bytecode identification supports a range of uses, including audits, allowlist management, code references, and potential gas savings. Standardizing the mechanism makes these benefits available to more Ethereum developers.

Specification

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;

interface IERC7744 {
    event Indexed(address indexed container, bytes32 indexed codeHash);
    error alreadyExists(bytes32 id, address source);

    function register(address container) external;

    function get(bytes32 id) external view returns (address);
}

/**
 * @title Byte Code Indexer Contract
 * @notice You can use this contract to index contracts by their bytecode.
 * @dev This allows to query contracts by their bytecode instead of addresses.
 * @author Tim Pechersky (@Peersky)
 */
contract ERC7744 is IERC7744 {
    mapping(bytes32 => address) private index;

    function isValidContainer(address container) private view returns (bool) {
        bytes memory code = container.code;
        bytes32 codeHash = container.codehash;
        bytes32 eip7702Hash = bytes32(0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329);
        // Contract should have non-empty code and valid codehash
        return (code.length > 0 && codeHash != bytes32(0) && codeHash != eip7702Hash);
    }

    /**
     * @notice Registers a contract in the index by its bytecode hash
     * @param container The contract to register
     * @dev `msg.codeHash` will be used
     * @dev It will revert if the contract is already indexed or if returns EIP7702 hash
     */
    function register(address container) external {
        address etalon = index[container.codehash];
        require(isValidContainer(container), "Invalid container");
        if (etalon != address(0)) {
            if (isValidContainer(etalon)) revert alreadyExists(container.codehash, container);
        }
        index[container.codehash] = container;
        emit Indexed(container, container.codehash);
    }

    /**
     * @notice Returns the contract address by its bytecode hash
     * @dev returns zero if the contract is not indexed
     * @param id The bytecode hash
     * @return The contract address
     */
    function get(bytes32 id) external view returns (address) {
        return index[id];
    }
}

IERC7744

javascript
interface IERC7744 {
    event Indexed(address indexed container, bytes32 indexed codeHash);
    error alreadyExists(bytes32 id, address source);

    function register(address container) external;

    function get(bytes32 id) external view returns (address);
}

Overview
A standard interface for indexing Ethereum contracts by their bytecode hashes.

Details
The interface provides functions for registering and retrieving contracts based on their bytecode hashes. Using codeHash, an identifier derived from the bytecode itself, rather than a specific address makes code identity easier to establish and verify.

  • Indexed
    • An event indicating that a contract has been registered along with its bytecode hash.
  • alreadyExists
    • An error raised when the bytecode hash being registered already has a valid entry.
  • register
    • A function that registers a contract's bytecode in the index.
  • get
    • A function that retrieves the contract address associated with a registered bytecode hash.

Indexed

javascript
event Indexed(address indexed container, bytes32 indexed codeHash);

Overview
An event indicating that a contract has been registered along with its bytecode hash.

Details
This event is emitted on successful execution of register and records the registered contract's address (container) and bytecode hash (codeHash). It allows observers to track which code has been registered on-chain.

Parameters

  • container
    • The address of the registered contract.
  • codeHash
    • The bytecode hash of the registered contract.

alreadyExists

javascript
error alreadyExists(bytes32 id, address source);

Overview
An error raised when the bytecode hash being registered already exists as a valid entry.

Details
When adding a contract to the index, the implementation raises this error if a contract with the same bytecode hash is already validly registered. This prevents duplicate registrations of the same bytecode.

Parameters

  • id
    • The already registered bytecode hash.
  • source
    • The address of the contract the caller attempted to register.

index

javascript
mapping(bytes32 => address) private index;

Overview
A mapping from bytecode hashes to contract addresses.

Details
The mapping uses a bytes32 bytecode hash as its key and stores the associated contract address as its value. This allows callers to retrieve an address based on the contract's bytecode.

Parameters

  • bytes32
    • The bytecode hash.
  • address
    • The corresponding contract address.

isValidContainer

javascript
function isValidContainer(address container) private view returns (bool) {
    bytes memory code = container.code;
    bytes32 codeHash = container.codehash;
    bytes32 eip7702Hash = bytes32(0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329);
    return (code.length > 0 && codeHash != bytes32(0) && codeHash != eip7702Hash);
}

Overview
A function that checks whether a contract address is a valid container.

Details
The function checks whether the specified container contains bytecode and whether its hash satisfies the validity conditions. In particular, the example rejects a specific code hash associated with EIP7702. See the security discussion below for the limitation of that check.

For more on EIP7702, see the following article.

[EIP7702] Turning EOAs into Delegated Accounts

Parameters

  • container
    • The contract address to validate.

Return value

  • bool
    • true if the container is valid, and false otherwise.

register

javascript
function register(address container) external {
    address etalon = index[container.codehash];
    require(isValidContainer(container), "Invalid container");
    if (etalon != address(0)) {
        if (isValidContainer(etalon)) revert alreadyExists(container.codehash, container);
    }
    index[container.codehash] = container;
    emit Indexed(container, container.codehash);
}

Overview
A function that registers a new contract in the index using its bytecode hash as the key.

Details
The function obtains the bytecode hash of the specified container and uses it as the key in index. If the same bytecode already has a valid entry, it raises the alreadyExists error. It calls isValidContainer to check that the code is nonempty and does not have a disallowed hash. On successful registration, it emits an Indexed event.

Parameters

  • container
    • The address of the contract to register.

get

javascript
function get(bytes32 id) external view returns (address) {
    return index[id];
}

Overview
A function that retrieves the contract address associated with the specified bytecode hash.

Details
The function returns the address associated with the bytecode hash (id) in index. If there is no entry, it returns 0x0 (the zero address). External callers can therefore look up a corresponding address using the contract's bytecode hash.

Parameters

  • id
    • The bytecode hash of the contract to look up.

Return value

  • address
    • The contract address associated with the bytecode hash, or 0x0 if no entry exists.

Deployment

The CodeIndex contract is described as deployed at 0xC0dE1D2F7662c63796E544B2647b2A94EE658E07. This address is derived deterministically using CREATE2.

The deployment specifies the salt (arbitrary data used when deriving a contract address with CREATE2) 0x70b27c94ed692bfb60748cee464ef910d4bf768ac1f3a63eeb4c05258f629256. The salt was selected to obtain a vanity address containing the recognizable pattern "Code ID" (0xC0dE1D...).

Additional Considerations

Why Use Bytecode as the Basis for Identification?

The reason for indexing contracts by bytecode rather than by address is that a given bytecode has a deterministic hash that can be verified on-chain. An address, by contrast, identifies a particular deployment rather than the code itself, and deployments of the same bytecode can use different addresses. Even deterministic deployment methods such as CREATE2 do not make addresses universal identifiers for runtime bytecode.

Errors on Re-registration

In theory, a bytecode hash collision, in which different code produces the same hash, is possible. The probability is extremely low, however. Disallowing replacement of a valid registered entry prevents a registered hash from being redirected to a different address through routine updates, reducing potential attack risks.

Keeping the Interface Simple

The specification adopts a minimal interface that exposes only the required functionality. The aim is to simplify integration with other contracts and reduce implementation overhead. Keeping the design simple makes it easier for developers to incorporate the mechanism.

An ERC Standard Rather Than a Library

Providing this mechanism only as a library would make it harder to establish a shared index and reuse code across independent implementations. Defining it as an ERC instead provides the ecosystem with a common code reference mechanism. Projects on Ethereum can follow the standard to manage code consistently.

Reference Implementation

A sample implementation is available here. https://eips.ethereum.org/EIPS/eip-7744#reference-implementation

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
import {IERC7744} from "./IERC7744.sol";

/**
 * @title Byte Code Indexer Contract
 * @notice You can use this contract to index contracts by their bytecode.
 * @dev This allows to query contracts by their bytecode instead of addresses.
 * @author Tim Pechersky (@Peersky)
 */
contract ERC7744 is IERC7744 {
    mapping(bytes32 => address) private index;

    function isValidContainer(address container) private view returns (bool) {
        bytes memory code = container.code;
        bytes32 codeHash = container.codehash;
        bytes32 eip7702Hash = bytes32(0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329);
        // Contract should have non-empty code and valid codehash
        return (code.length > 0 && codeHash != bytes32(0) && codeHash != eip7702Hash);
    }

    /**
     * @notice Registers a contract in the index by its bytecode hash
     * @param container The contract to register
     * @dev `msg.codeHash` will be used
     * @dev It will revert if the contract is already indexed or if returns EIP7702 hash
     */
    function register(address container) external {
        address etalon = index[container.codehash];
        require(isValidContainer(container), "Invalid container");
        if (etalon != address(0)) {
            if (isValidContainer(etalon)) revert alreadyExists(container.codehash, container);
        }
        index[container.codehash] = container;
        emit Indexed(container, container.codehash);
    }

    /**
     * @notice Returns the contract address by its bytecode hash
     * @dev returns zero if the contract is not indexed
     * @param id The bytecode hash
     * @return The contract address
     */
    function get(bytes32 id) external view returns (address) {
        return index[id];
    }
}

Security

Malicious Code

The Code Index does not guarantee the safety or legitimacy of registered contracts. Users must therefore independently check whether the registered code is malicious. Obtaining a contract address through get does not, by itself, make that contract's code trustworthy.

Storage State of Registered Contracts

The index registers bytecode, not contract storage data. Consequently, even if a contract with identical bytecode has been registered, the index does not establish what data that contract holds. Changes to storage may result in unexpected behavior, so callers must account for the contract's state.

EIP7702

EIP7702 (delegated accounts) introduces account behavior that differs from ordinary deployed contracts. The Code Index is intended to reject EIP7702 delegated accounts because their delegation can change under certain conditions, unlike the fixed code identity the index aims to represent. The example checks EXTCODEHASH (the opcode that retrieves an account's code hash) at registration time and causes register to revert if the hash equals 0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329, or keccak256(0xef01).

This is the historical check shown in the original reference implementation. The finalized EIP7702 delegation designator is 0xef0100 followed by a 20-byte address; checking only the hash of 0xef01 is not sufficient to reject all such delegation designators. The sample is retained as written, not presented as a comprehensive current implementation.

Handling Self-Destructed Contracts

Where Ethereum's SELFDESTRUCT semantics permit deletion of contract code, the address of a deleted contract no longer contains that code. If a contract registered in the Code Index is deleted through SELFDESTRUCT, the corresponding index entry can become invalid. Under EIP6780, however, SELFDESTRUCT generally no longer deletes a contract's code or storage unless it is called in the same transaction in which the contract was created.

The implementation addresses invalid entries as follows.

  • On execution of register, check whether the previously registered address is still valid.
  • Allow a new registration only if the existing entry has become invalid.

This permits bytecode from a deleted contract to be registered again at a different address, preserving the consistency of the index.

Citation

Tim Pechersky (@peersky) t@peersky.xyz, "ERC-7744: Code Index [DRAFT]," Ethereum Improvement Proposals, no. 7744, July 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7744.

Conclusion

This article covered ERC7744, a proposal for recording contract bytecode to support contract discovery and verification.

If you have questions, feel free to contact me by direct message on Twitter.

Twitter @cardene777

I also publish material on the following platforms.

https://chaldene.net/