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-5005, a proposal for constructing contract accounts from interchangeable components.

This explanation translates, summarizes, and expands on the original proposal.

I have also written about other EIPs.

Abstract

ERC-5005 proposes standard interfaces that make tools for programmable Ethereum accounts more flexible and interoperable.

Programmable accounts, including those used by DAOs, have traditionally used monolithic designs in which authorization and execution logic are tightly coupled. ERC-5005 instead separates the account itself (the avatar) from authorization and execution components (such as a guard or module) to improve reusability and extensibility.

Separating the main components

ERC-5005 defines interfaces for the following account components:

  • Avatar

    The account itself, implementing the IAvatar interface. Transactions are executed through this contract.

  • Guard

    A component containing validation logic that checks whether an operation is permitted. It implements the IGuard interface.

  • Module

    An extension that can take different forms and implement additional functionality or operations.

This separation allows account operators to replace execution logic and combine multiple governance mechanisms.

Motivation

Many DAO tools and account frameworks combine authorization and execution logic, leading to several problems:

  • Limited extensibility

    Tightly coupled authorization and execution logic makes it difficult to add different mechanisms later.

  • Tool lock-in

    Switching from an adopted system to another framework can require substantial work.

  • Inflexible governance

    As a project grows, moving to a more complex decision-making process can be difficult.

ERC-5005 addresses these problems by separating responsibilities for account control. The design offers several potential benefits:

  • Flexible, modular account control.
  • Easier switching between tools and frameworks.
  • Combining multiple control mechanisms, such as multisignature and role-based authorization.
  • Support for cross-chain and cross-layer governance through appropriate modules.
  • Progressive decentralization, from simple initial control to more complex decentralized governance.

Specification

Components

ERC-5005 defines four components.

Avatar

An avatar is the actual Ethereum account. It holds assets, executes transactions, and interacts with other systems. It must implement the IAvatar interface. It enables and disables modules and accepts execution requests from enabled modules.

Module

A module is a unit of execution logic enabled by an avatar. Its contract can take various forms and define specific actions or rules.

Modifier

A modifier is a contract placed between a module and an avatar to restrict or alter the module's behavior. For example, it may introduce a delay before function calls or limit the transactions that can be executed. A modifier must implement the IAvatar interface.

Guard

A guard is an optional security mechanism for modules and modifiers. It performs checks before and after transaction execution. It implements the IGuard interface. A guardable contract must inherit Guardable and invoke checkTransaction() and checkAfterExecution() at the appropriate points.

Avatar interface

IAvatar.sol
/// @title Avatar - A contract that manages modules that can execute transactions via this contract.

pragma solidity >=0.7.0 <0.9.0;

import "./Enum.sol";


interface IAvatar {
    event EnabledModule(address module);
    event DisabledModule(address module);
    event ExecutionFromModuleSuccess(address indexed module);
    event ExecutionFromModuleFailure(address indexed module);

    /// @dev Enables a module on the avatar.
    /// @notice Can only be called by the avatar.
    /// @notice Modules should be stored as a linked list.
    /// @notice Must emit EnabledModule(address module) if successful.
    /// @param module Module to be enabled.
    function enableModule(address module) external;

    /// @dev Disables a module on the avatar.
    /// @notice Can only be called by the avatar.
    /// @notice Must emit DisabledModule(address module) if successful.
    /// @param prevModule Address that pointed to the module to be removed in the linked list
    /// @param module Module to be removed.
    function disableModule(address prevModule, address module) external;

    /// @dev Allows a Module to execute a transaction.
    /// @notice Can only be called by an enabled module.
    /// @notice Must emit ExecutionFromModuleSuccess(address module) if successful.
    /// @notice Must emit ExecutionFromModuleFailure(address module) if unsuccessful.
    /// @param to Destination address of module transaction.
    /// @param value Ether value of module transaction.
    /// @param data Data payload of module transaction.
    /// @param operation Operation type of module transaction: 0 == call, 1 == delegate call.
    function execTransactionFromModule(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation
    ) external returns (bool success);

    /// @dev Allows a Module to execute a transaction and return data
    /// @notice Can only be called by an enabled module.
    /// @notice Must emit ExecutionFromModuleSuccess(address module) if successful.
    /// @notice Must emit ExecutionFromModuleFailure(address module) if unsuccessful.
    /// @param to Destination address of module transaction.
    /// @param value Ether value of module transaction.
    /// @param data Data payload of module transaction.
    /// @param operation Operation type of module transaction: 0 == call, 1 == delegate call.
    function execTransactionFromModuleReturnData(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation
    ) external returns (bool success, bytes memory returnData);

    /// @dev Returns if an module is enabled
    /// @return True if the module is enabled
    function isModuleEnabled(address module) external view returns (bool);

    /// @dev Returns array of modules.
    /// @param start Start of the page.
    /// @param pageSize Maximum number of modules that should be returned.
    /// @return array Array of modules.
    /// @return next Start of the next page.
    function getModulesPaginated(address start, uint256 pageSize)
        external
        view
        returns (address[] memory array, address next);
}

Events

EnabledModule

Emitted when a module is enabled.

DisabledModule

Emitted when a module is disabled.

ExecutionFromModuleSuccess

Emitted when a transaction executed by a module succeeds.

ExecutionFromModuleFailure

Emitted when a transaction executed by a module fails.

Functions

enableModule

Registers and enables a module on the avatar. Modules are stored in a linked list. Only the avatar may call this function. A successful operation emits EnabledModule.

Arguments

  • module
    • The address of the module to enable.
disableModule

Disables a module. Because modules are managed in a linked list, the caller must supply the preceding module address. Only the avatar may call this function. A successful operation emits DisabledModule.

Arguments

  • prevModule
    • The address of the module immediately preceding the one to disable.
  • module
    • The address of the module to disable.
execTransactionFromModule

Allows a module to execute a transaction through the avatar. The function emits ExecutionFromModuleSuccess on success or ExecutionFromModuleFailure on failure. Only enabled modules may call it.

Arguments

  • to
    • The destination address.
  • value
    • The amount of ETH to send.
  • data
    • The byte sequence containing the function call and arguments.
  • operation
    • The execution type (Call or DelegateCall).

Return value

A bool indicating whether execution succeeded.

execTransactionFromModuleReturnData

Performs the same operation as execTransactionFromModule but also retrieves the data returned by the destination contract.

Return value

A bool indicating success or failure, together with the return data from the destination.

isModuleEnabled

Checks whether a module is currently enabled.

Arguments

  • module
    • The module being queried.

Return value

true if the module is enabled; otherwise false.

getModulesPaginated

Retrieves a paginated list of modules.

Arguments

  • start
    • The address at which to start retrieving modules.
  • pageSize
    • The maximum number of modules to return.

Return values

  • array
    • An array of module addresses.
  • next
    • The starting address for the next page.

Guard interface and Guardable contract

IGuard interface

IGuard.sol
pragma solidity >=0.7.0 <0.9.0;

import "./Enum.sol";

interface IGuard {
    function checkTransaction(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver,
        bytes memory signatures,
        address msgSender
    ) external;

    function checkAfterExecution(bytes32 txHash, bool success) external;
}
checkTransaction

Called before a transaction executes. It performs pre-execution checks using information such as the destination address, execution data, and amount of ETH.

The interface includes parameters that module transactions do not use, in order to maintain compatibility.

checkAfterExecution

Called after transaction execution. It can perform post-execution checks, additional processing, or logging.

Arguments

  • txHash
    • The hash of the transaction that was executed.
  • success
    • A flag indicating whether execution succeeded.

Guardable contract

Guardable.sol
pragma solidity >=0.7.0 <0.9.0;

import "./Enum.sol";
import "./BaseGuard.sol";

/// @title Guardable - A contract that manages fallback calls made to this contract
contract Guardable {
    address public guard;

    event ChangedGuard(address guard);

    /// `guard_` does not implement IERC165.
    error NotIERC165Compliant(address guard_);

    /// @dev Set a guard that checks transactions before execution.
    /// @param _guard The address of the guard to be used or the 0 address to disable the guard.
    function setGuard(address _guard) external {
        if (_guard != address(0)) {
            if (!BaseGuard(_guard).supportsInterface(type(IGuard).interfaceId))
                revert NotIERC165Compliant(_guard);
        }
        guard = _guard;
        emit ChangedGuard(guard);
    }

    function getGuard() external view returns (address _guard) {
        return guard;
    }
}
guard

The address of the currently configured guard.

setGuard

Configures a guard. Passing the zero address disables the guard. A nonzero guard must support the IGuard interface through IERC165. Otherwise the function reverts with NotIERC165Compliant.

For more about ERC-165, see the following article.

[ERC165] Checking whether a contract supports a particular interface

The example preserves the original interface illustration. It does not show authorization for changing the guard; production contracts must restrict this operation appropriately.

getGuard

Returns the address of the currently configured guard.

ChangedGuard

Emitted when the guard configuration changes.

BaseGuard

BaseGuard.sol
pragma solidity >=0.7.0 <0.9.0;

import "./Enum.sol";
import "./IERC165.sol";
import "./IGuard.sol";

abstract contract BaseGuard is IERC165 {
    function supportsInterface(bytes4 interfaceId)
        external
        pure
        override
        returns (bool)
    {
        return
            interfaceId == type(IGuard).interfaceId || // 0xe6d7a83a
            interfaceId == type(IERC165).interfaceId; // 0x01ffc9a7
    }

    /// @dev Module transactions only use the first four parameters: to, value, data, and operation.
    /// Module.sol hardcodes the remaining parameters as 0 since they are not used for module transactions.
    function checkTransaction(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver,
        bytes memory signatures,
        address msgSender
    ) external virtual;

    function checkAfterExecution(bytes32 txHash, bool success) external virtual;
}

BaseGuard is an abstract contract designed around the IGuard and IERC165 interfaces. It defines common guard logic.

Functions

supportsInterface

Checks whether the contract supports a particular interface identifier. The implementation recognizes both IGuard and IERC165.

checkTransaction

An abstract function whose implementation must be provided by an inheriting contract.

checkAfterExecution

An abstract function whose implementation must be provided by an inheriting contract.

Enum contract

Enum.sol
pragma solidity >=0.7.0 <0.9.0;

/// @title Enum - Collection of enums

contract Enum {

    enum Operation {Call, DelegateCall}

}

The Enum contract defines the Operation enumeration to represent execution types.

  • Call
    • A normal contract call, with state changes taking place in the destination contract.
  • DelegateCall
    • Executes the destination contract's code in the calling contract's storage context.

This enumeration specifies how the transaction is executed.

Rationale

ERC-5005 is designed to work with widely used programmable account implementations, such as Gnosis Safe, with minimal changes to existing tools and infrastructure.

Developers can continue using tools and smart contracts built around existing architectures while gradually adopting the modular standard, rather than rebuilding everything from scratch.

Backward compatibility

The proposal identifies no backward-compatibility issues. This does not imply that every existing wallet automatically implements the required interfaces.

Security considerations

Enabled modules have full authority

An enabled module has extensive execution authority over its avatar. In the absence of additional restrictions, this can allow the module to control all assets held by the avatar.

Modules must therefore be selected carefully.

  • Never enable an untrusted module.
  • Enable only modules that can be trusted with the authority they receive over the account's assets.

Risk of race conditions

An avatar can have multiple modules enabled simultaneously. Conflicting operations initiated by different modules can create race conditions.

  • Competition between modules may produce unexpected state transitions or asset movements.
  • Pre-execution and post-execution checks through a guard implementing IGuard are strongly recommended where appropriate.

Removing every module can render the account unusable

If all modules are removed and the avatar has no other execution mechanism, it may become permanently locked, a condition often called bricking.

  • Before disabling the last module, verify that another authorized means of controlling the account remains available.
  • Consider redundant modules or a backup control mechanism.

Citation

Auryn Macmillan (@auryn-macmillan), Kei Kreutler (@keikreutler), "ERC-5005: Zodiac Modular Accounts [DRAFT]," Ethereum Improvement Proposals, no. 5005, April 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5005.

Conclusion

ERC-5005 proposes a modular architecture for contract accounts, separating the account that holds assets and executes transactions from the components that authorize, modify, and validate operations.

If you have questions, feel free to contact me via Twitter.

Twitter @cardene777

I also share technical content on the following platforms.

https://chaldene.net/