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 explores ERC4337, a proposal for implementing account abstraction without changing the protocol.

The explanation below translates, summarizes, and expands on the specification linked here.

Accessible explanations of AA (Account Abstraction) and ERC4337 are also collected in the latter part of this article. This article is specifically an overview of the ERC4337 proposal.

At the time of writing, ERC4337 is in the Draft stage. Its contents may therefore change in the future.

The following resource explains the mechanism in simpler terms.

The following slides provide a concise overview of ERC4337.

The following article covers account abstraction standards, including ERC4337.

https://mirror.xyz/0xcE77b9fCd390847627c84359fC1Bc02fC78f0e58/HaPTTeXZeXRG3K5JfXesmKet9eKTbcFUixW6IaMvt4c

Overview

ERC4337 proposes a mechanism for achieving account abstraction without modifying Ethereum's consensus layer (the underlying protocol). Instead of changing the existing transaction structure, it introduces a structure called UserOperation.

Users submit a UserOperation to a dedicated mempool, and nodes known as bundler nodes aggregate them and construct a transaction that calls handleOps. The transaction is included in a block and processed normally, so the mechanism works without conflicting with the existing Ethereum protocol.

Here is a brief overview of Ethereum's layered architecture.

Ethereum network layer This is the underlying Ethereum network. Nodes exchange information and group transactions into blocks that are subsequently finalized. This layer remains unchanged by the proposal.

Consensus layer This is where agreement is reached across the network. The proposed account abstraction mechanism works without modifying this layer. No new protocol changes or transaction types are introduced.

Application layer The proposed account abstraction mechanism operates at this layer. A new concept, the UserOperation, represents operations executed within smart contract wallets. Users construct these operations and submit them to a dedicated mempool.

Motivation

See the following links for details.

The proposal adopts a new approach to implementing account abstraction. The following sections explain its objectives and implementation approach.

Goals of account abstraction

ERC4337 aims to enable users to operate using contract accounts alone, without depending on EOAs (externally owned accounts). Specifically, it aims to allow users to use an account with arbitrary validation logic as their primary account through a smart contract wallet. This removes the need for users to hold an EOA and allows them to perform complex operations through a smart contract wallet, including the following.

  • Arbitrary signature schemes (e.g., quantum-resistant signatures)
  • Multisignature authorization and social recovery
  • Gas payments in arbitrary tokens (e.g., ERC20 tokens)
  • Wallet upgrades and custom logic

Decentralization

ERC4337 allows all interactions to take place through a public mempool. Users do not need to know specific nodes or IP addresses, and any bundler can handle a UserOperation. This removes dependence on centralized relays and gateways and enables more decentralized processing.

Avoiding changes to the Ethereum protocol

Changes to the consensus layer take considerable time, often requiring years of coordination and implementation. Because ERC4337 does not require consensus-layer changes, it lowers barriers to implementation and adoption and can accelerate practical deployment.

Supporting a broad range of use cases

ERC4337 can also support the following use cases.

  • Privacy-preserving applications
  • Atomic batches of operations (executing multiple operations together in a single transaction)
  • Developer-sponsored gas fees (sponsored transactions)
  • Gas payments in ERC20 tokens
  • Cross-chain gas payment models

Abstracting validation (signature verification), gas payment, and execution separately greatly expands the flexibility previously available in transaction design.

Specification

Definitions

UserOperation

A structure containing the data for an operation a user wants to execute. It resembles a conventional Ethereum transaction but is named UserOperation to distinguish it from ordinary transactions. It includes fields such as the following (described in detail later).

  • to
  • calldata
  • maxFeePerGas
  • maxPriorityFeePerGas
  • nonce
  • signature

The Ethereum protocol does not define how the signature is validated; each contract account implements its own validation logic.

Sender

A contract account that submits a UserOperation. It is an account with code rather than an EOA (externally owned account).

EntryPoint

A central contract that accepts and processes UserOperations. Bundlers execute multiple UserOperations together through the contract's handleOps() function. There is one such contract on the network, as described in this proposal. Bundlers must allowlist the corresponding EntryPoint in advance.

Bundler

A node responsible for collecting UserOperations, constructing a transaction to the EntryPoint, and including it in a block. It can operate in the following ways.

  • Act directly as a block builder.
  • Integrate with proposer-builder separation (PBS) infrastructure using mev-boost or compliant with EIP7732.
  • Use the eth_sendRawTransactionConditional RPC defined in ERC-7796, where available.

Paymaster

A smart contract that pays gas fees on behalf of users. A Paymaster can cover gas fees in ETH even if the user does not hold ETH.

Factory

A contract that deploys a new contract account (sender) when it does not yet exist. The address can be determined in advance using mechanisms such as CREATE2.

Aggregator

A contract that aggregates and verifies the signatures of multiple UserOperations together. Also known as an authorizer contract, it is specified in ERC7766.

Canonical UserOperation mempool

A permissionless, decentralized peer-to-peer mempool compliant with ERC7562. Bundlers share UserOperation objects in this mempool and verify their validity.

Alternative UserOperation mempool

A separate peer-to-peer mempool that determines validity under rules other than ERC7562. It is used for optimization or specialized use cases.

Deposit

ETH (or the native currency of an L2) deposited in the EntryPoint contract in advance by a Sender or Paymaster. Gas fees are deducted from the deposit when a UserOperation executes, and the funds are used to compensate the bundler.

UserOperation

A UserOperation is a structure that allows users to execute operations through a contract account (CA). To implement account abstraction without modifying the Ethereum protocol (consensus layer), ERC4337 processes operations using its own structure rather than the existing transaction format.

This structure is submitted to a dedicated UserOperation mempool, where bundlers aggregate and process operations.

UserOperation fields

Field Type Description
sender address Address of the contract account executing this UserOperation.
nonce uint256 Number used to prevent replay attacks; incremented per account.
factory address Address of the factory contract used to create a new account.For EIP7702, use 0x7702; for an existing account, use address(0).
factoryData bytes Initialization data passed to the factory, or EIP7702 initialization information. Empty if unused.
callData bytes Execution data passed to the sender; the main operation payload.
callGasLimit uint256 Amount of gas allocated to executing the callData above.
verificationGasLimit uint256 Gas allocated to the validateUserOp validation process.
preVerificationGas uint256 Additional gas reserved for the bundler (for packing and mempool-related processing).
maxFeePerGas uint256 Corresponds to max_fee_per_gas in EIP1559.Maximum fee allowed for the transaction as a whole.
maxPriorityFeePerGas uint256 Corresponds to max_priority_fee_per_gas in EIP1559.Priority fee for the bundler.
paymaster address Address of the Paymaster contract sponsoring gas fees. Zero address (0x0) for self-funded operations.
paymasterVerificationGasLimit uint256 Gas limit for executing the paymaster validation code (only when specified).
paymasterPostOpGasLimit uint256 Gas limit for paymaster postprocessing (postOp), only when specified.
paymasterData bytes Additional data passed to the paymaster, potentially including a signature.
signature bytes Signature data passed to the authentication logic within the sender. Each SCA can define its own signature structure and validation method.

See the following article for more about EIP1559.

[EIP1559] Understanding Ethereum's new gas pricing mechanism

Security considerations

To prevent replay attacks (the risk of the same operation being executed again on another chain or through another EntryPoint), signatures must be designed to depend on chainid and the EntryPoint address.

Relationship with EIP7702

The EIP7702 authorization tuple is provided separately from the UserOperation structure. This authorization information is supplied externally alongside the UserOperation to complement more flexible authentication methods beyond its signature.

See the following article for more about EIP7702.

[EIP7702] Understanding how EOAs can use contract-account functionality

EntryPoint interface

The EntryPoint is the central contract in ERC4337. It is responsible for processing multiple UserOperation objects together. For onchain efficiency and lower gas costs, a UserOperation is passed to the EntryPoint in a packed form (PackedUserOperation).

PackedUserOperation structure

Field Type Description
sender address Address of the contract account executing the operation.
nonce uint256 Counter for preventing replay attacks.
initCode bytes Concatenation of the factory address and initialization data for creating a new account.Also supports EIP7702.
callData bytes Actual operation to be executed by the account.
accountGasLimits bytes32 Concatenation of verificationGasLimit (16 bytes) and callGasLimit (16 bytes).
preVerificationGas uint256 Additional gas compensating the bundler for validation and packing.
gasFees bytes32 Concatenation of maxPriorityFeePerGas (16 bytes) and maxFeePerGas (16 bytes).
paymasterAndData bytes Concatenation of the paymaster address, validation-related data, and postOp-related data (empty if unused).
signature bytes Signature data passed to the validation logic defined by the sender.

Efficiently packing multiple UserOperation objects in advance improves gas efficiency and enables batch processing within the EntryPoint.

handleOps

js
function handleOps(PackedUserOperation[] calldata ops, address payable beneficiary);

The core function of ERC4337.

  • ops
    • Array of PackedUserOperation objects (multiple UserOperations).
  • beneficiary
    • Address receiving compensation for the bundler that included the UserOperation in a block, or an executor (an address that executes UserOperations, like a bundler).

The processing flow is as follows.

  1. The EntryPoint contract validates ops in order, initializing wallets or Paymasters as necessary.
  2. Execute the callData of validated UserOperation objects.
  3. After execution finishes, pay the fee to beneficiary according to the amount of gas consumed.

This structure allows multiple UserOperation objects to be processed safely and efficiently within one transaction.

Contract account interface

IAccount

js
interface IAccount {
  function validateUserOp(
    PackedUserOperation calldata userOp,
    bytes32 userOpHash,
    uint256 missingAccountFunds
  ) external returns (uint256 validationData);
}

A function called by the EntryPoint contract to validate a UserOperation and pay the required gas fees.

Arguments
Argument Type Description
userOp PackedUserOperation calldata UserOperation structure to execute, including its signature.
userOpHash bytes32 Hash including userOp (excluding the signature), the EntryPoint contract address, and chainId.
missingAccountFunds uint256 Minimum amount to deposit into the EntryPoint contract.Cannot be zero if the sender's deposit is insufficient.
  • Verify that msg.sender is the trusted EntryPoint contract.
  • If signature verification fails, returning SIG_VALIDATION_FAILED (1) instead of reverting is recommended. However, errors other than signature failures must revert.
  • For gas estimation purposes, even when returning SIG_VALIDATION_FAILED, the function should complete its processing instead of stopping early.
  • Pay missingAccountFunds to the EntryPoint contract through the depositTo function. Excess deposits can later be withdrawn using withdrawTo.
Return value

The following three values must be returned in a bit-packed format.

Variable Description
aggregator/authorizer Signature validation status.0 = valid signature1 = invalid signatureAny other value = Aggregator address (delegated signature verifier).
validUntil Expiration of the UserOperation (UNIX timestamp of at most six bytes).Zero means no expiration.
validAfter Start of the UserOperation validity period (six-byte UNIX timestamp).The operation is invalid before this time.

IAccountExecute

An extended interface.

js
interface IAccountExecute {
  function executeUserOp(
    PackedUserOperation calldata userOp,
    bytes32 userOpHash
  ) external;
}

A function that executes the operation specified by callData. Normally, the EntryPoint contract invokes the account directly to execute callData; this extension allows it to invoke this function instead. This makes it possible to customize execution logic, including more complex controls.

Semi-abstracted Nonce Support

Conventional Ethereum transactions use a single nonce to prevent replay attacks and control transaction ordering. However, this mechanism limits the flexibility of contract accounts in managing their own ordering and operations.

ERC4337 introduces a mechanism called the Semi-abstracted Nonce to remove this restriction while preserving security and uniqueness.

Changes to the nonce structure

ERC4337 divides UserOperation.nonce (uint256) as follows.

Bits Meaning Length
Upper 192 bits key (classification key) 192 bits
Lower 64 bits sequence (sequence number) 64 bits

This format lets one account have multiple operation categories (keys), each with independent sequencing.

Retrieving and validating nonces

The EntryPoint contract provides the following interface.

js
function getNonce(address sender, uint192 key) external view returns (uint256 nonce);

A function that retrieves the current sequence number for the specified sender account and key.

When validating a UserOperation, a bundler needs to use this function to check the nonce in advance.

nonce requirements

  • Sequence numbers must always increase in order.
  • Two or more UserOperation objects cannot be processed simultaneously for the same key.
  • A new key can use any value and starts with sequence = 0.

This enables advanced account control, such as progressing operations in different categories in parallel.

Examples

Simple ordering (sequential nonce)

To retain conventional behavior, impose the following restriction.

js
require(userOp.nonce < type(uint64).max);

This is a simple model using only the sequence, with key = 0 fixed.

Separating administrative and ordinary operations

If a contract account needs two operation channels, administrative (ADMIN) and ordinary (NORMAL), different keys can be used for each.

js
bytes4 sig = bytes4(userOp.callData[0 : 4]);
uint key = userOp.nonce >> 64;

if (sig == ADMIN_METHODSIG) {
    require(key == ADMIN_KEY, "wrong nonce-key for admin operation");
} else {
    require(key == 0, "wrong nonce-key for normal operation");
}

This allows administrative and ordinary operations to proceed in parallel with independent ordering, enabling flexible operation control.

Required functionality of the EntryPoint contract

The central function of the ERC4337 EntryPoint contract is handleOps(). It processes multiple UserOperation objects together, covering validation, execution, and gas fee payments.

The processing flow is as follows.

The figures are reproduced from the original Japanese article; any Japanese labels are retained.

Sequence of bundled UserOperations

Calling handleOps

js
function handleOps(PackedUserOperation[] calldata ops, address payable beneficiary)
  • ops
    • Array of UserOperation objects to process.
  • beneficiary
    • Address receiving gas fees after processing (typically the bundler).

Verification loop

The following steps are performed for each UserOperation.

  1. Create the contract account (if initCode is provided)

    • If the sender has not been deployed, it is newly deployed using UserOperation.initCode.
    • If the factory contract is specified as 0x7702, verify consistency between the EOA and authorization information according to EIP7702.
    • Processing fails if initCode is empty and the sender does not exist, or if the deployment address does not match.
  2. Estimate the maximum gas fee

    • Calculate the maximum payment from validationGasLimit, callGasLimit, and the current maxFeePerGas.
  3. Calculate and check the required deposit

    • Check whether funds are already deposited with the EntryPoint contract and calculate the shortfall as missingAccountFunds.
  4. Call validateUserOp()

    • Validate the signature and nonce for the sender and pay the required deposit if necessary.
    • An invalid signature results in SIG_VALIDATION_FAILED, whereas errors other than signature failures cause a revert.
    • A UserOperation that fails at this stage is excluded from subsequent execution (the entire handleOps call can also revert as necessary).
  5. Verify the deposit

    • Finally, check that the deposit is sufficient to cover all required gas costs.

Execution loop

The following steps are performed for each successfully validated UserOperation.

  1. Execute callData

    • Call callData directly, or, if the initial function selector is that of executeUserOp() (the IAccountExecute interface), execute the following function within the contract account.
    js
    executeUserOp(userOp, userOpHash)
  2. Penalty for unused gas

    • When at least 40,000 gas remains unused from callGasLimit or paymasterPostOpGasLimit, a 10% penalty is deducted.
    • This prevents deliberately reserving excessive gas and blocking other transactions.
    • Because a block has a maximum gas capacity, excessive gas reservations leave less room for other transactions and can delay the processing of other UserOperations.
  3. Refund remaining gas fees

    • Refund the sender for the difference between the gas charged in advance and the gas actually used.
  4. Pay the beneficiary

    • Transfer the fees collected from all UserOperation objects (gasUsed × effectiveGasPrice) to beneficiary, typically the bundler.

Before accepting a UserOperation, a bundler is encouraged to simulate EntryPoint.handleOps() locally. This enables the following preliminary checks.

  • Whether the signature is valid
  • Whether the deposited gas funds are sufficient
  • Whether the gas fees will be paid correctly

A failing UserOperation must not be added to the mempool or propagated to other nodes.

JSON-RPC API in ERC4337

ERC4337 requires additional endpoints in the standard Ethereum JSON-RPC API so that users can submit a UserOperation rather than a conventional transaction. This allows bundlers to receive UserOperation objects and relay and share them through a peer-to-peer mempool.

Main JSON-RPC methods

Two methods are particularly important in ERC4337.

These RPC interfaces are defined in ERC7769. Following this specification allows wallets, applications, and bundlers to communicate using a common protocol.

See the following article for more about ERC7769.

[ERC7769] Understanding the JSON-RPC API for ERC4337-compliant contract accounts

eth_sendUserOperation

A method for submitting a UserOperation object to a bundler node. The submitted UserOperation is added to the bundler's local mempool and relayed to other nodes.

eth_getUserOperationReceipt

A method for retrieving the execution result (receipt) of the specified UserOperation. If it has executed, information such as the following is returned.

  • Number and hash of the block in which it executed
  • Processing result from the EntryPoint contract
  • Success or failure status
  • Amount of gas used

EIP712 signature support

ERC4337 supports EIP712 signatures to provide flexibility in validating signatures over a UserOperation. EIP712 is a standard for signing structured data.

See the following article for more about EIP712.

[EIP712] Understanding typed structured data hashing and signing

Generating userOpHash

The hash identifying a UserOperation and used as signing data (userOpHash) consists of the following two steps in accordance with EIP712.

Hash of the domain information (TYPE_HASH)

First, hash the following information to define the signing domain.

js
bytes32 constant TYPE_HASH =
    keccak256(
        "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
    );

The domain information includes the following.

Field Description
name Name of the EIP712 message
version Version information
chainId Chain ID (e.g., 1 for Ethereum Mainnet)
verifyingContract Verifying contract (the EntryPoint contract address)

This hash is used to ensure uniqueness of the signing domain.

Hash of the PackedUserOperation type information

Define the data structure corresponding to the body of the UserOperation as follows and hash its type information.

js
bytes32 constant PACKED_USEROP_TYPEHASH =
    keccak256(
        "PackedUserOperation(address sender,uint256 nonce,bytes initCode,bytes callData,bytes32 accountGasLimits,uint256 preVerificationGas,bytes32 gasFees,bytes paymasterAndData)"
    );

The structure contains transaction details, including the sender, call contents, and gas limits. The signing hash is generated based on this type.

EIP7702 signed authorization support

By supporting EIP7702, ERC4337 enables a flexible transition from EOAs (externally owned accounts) to contract-account functionality and specialized authorization processing.

The data structure (tuple) containing authorization information, which grants a CA permission to execute a particular operation, contains the following data.

  • EOA address providing the authorization
  • Contract account receiving the authorization
  • Signature data for the authorization (signed by the EOA)

By attaching this tuple to a UserOperation, the EOA can authorize the contract account in advance to treat the operation as legitimate.

The eip7702Auth parameter in eth_sendUserOperation

On networks where EIP7702 is enabled, the eth_sendUserOperation RPC method supports an additional parameter called eip7702Auth.

  • eip7702Auth must be an EIP7702-compliant authorization tuple.
  • It must be signed by the sender (the user's EOA).

The bundler aggregates the eip7702Auth entries included with all UserOperation objects into an authorizationList and executes the bundle using the special transaction type SET_CODE_TX_TYPE.

Special processing with initCode (EIP7702 support)

When a UserOperation has a specially formatted initCode, the following processing occurs.

Ordinary initCode processing
  • First 20 bytes
    • Factory contract address
  • Remaining bytes
    • Initialization calldata passed to the factory contract

The EntryPoint contract calls the factory contract to create the CA.

Special processing for EIP7702
  • initCode starts with 0x7702 (the EIP7702 flag).
  • The following bytes of the address portion are zero-padded.

The UserOperation is treated as using a contract account established through delegation by an EOA rather than through a factory contract.

In this case, when computing the hash (userOpHash), replace the factory address normally at the beginning of initCode with the delegation target contract address obtained through the EXTCODECOPY opcode.

The remaining portion of initCode (after the first 20 bytes) is used to invoke the contract account's own initialization logic.

This design provides flexibility by allowing an EOA to initialize its own authorized account directly without using a factory contract.

It is also possible for initCode to be empty. In that case, the EntryPoint contract does not include the EIP7702 delegation information in the hash, and the operation executes against the existing account.

Gas cost of authorization processing

Each EIP7702 authorization requires PER_EMPTY_ACCOUNT_COST = 25000 gas. This gas consumption occurs outside the EntryPoint contract and cannot be measured by it. Users must therefore account for that gas by increasing preVerificationGas accordingly.

Extending sponsorship through a Paymaster

Adding a Paymaster to the ERC4337 EntryPoint processing flow enables a variety of use cases, such as application developers sponsoring users' gas fees or users paying fees with ERC20 tokens. The following flow is used.

UserOperation bundle sequence with a paymaster

Processing a UserOperation with a Paymaster

If the UserOperation has a nonempty paymasterAndData field, EntryPoint.handleOps() performs the following extended processing.

Validation phase

  1. Call the account's validateUserOp

    • The call uses missingAccountFunds = 0 (the account's deposit is not used).
  2. Check the Paymaster deposit

    • Verify whether the Paymaster has deposited enough ETH with the EntryPoint contract to pay the fees.
  3. Paymaster validation

    • Call validatePaymasterUserOp(userOp, userOpHash, maxCost).
    • If the returned context is nonempty, it is used in the subsequent postOp call.
    • validationData is used for signature verification and validity periods, among other purposes.

context is arbitrary byte data returned by the Paymaster's validatePaymasterUserOp() function. This context is generated during validation and passed unchanged to postOp() during execution.

This mechanism allows values temporarily calculated or retrieved by the Paymaster during validation to be retained and reused during subsequent processing. Examples include the following.

  • A token-payment Paymaster retrieves the user's token balance or the exchange rate for calculating fees.
  • Temporarily retain state or access information associated with the account.

This allows the Paymaster to save gas while passing the required information to postOp() and implementing logic such as charging or refunds based on the operation's success or failure.

validationData is bit-packed data of type uint256 returned by validatePaymasterUserOp() or validateUserOp().

| Field | Contents | | Lower 20 bits | Signature verification result (e.g., 1 = invalid signature) | | Middle 64 bits | validUntil: expiration time of the UserOperation | | Upper 64 bits | validAfter: start of the UserOperation validity period |

This data allows a UserOperation to be valid only within a specified time range and enables control of signature validity and deadlines.

Execution phase

  1. Execute the account's executeUserOp function (or call callData)

  2. Call postOp on the Paymaster if necessary

    • If the context returned by validatePaymasterUserOp is nonempty, the call takes the following form.
    js
    postOp(mode, context, actualGasCost, actualUserOpFeePerGas)
    • mode has one of the following values.
      • opSucceeded
        • If the UserOperation succeeds
      • opReverted
        • If the UserOperation fails (the Paymaster still pays gas fees)

How the Paymaster pays gas fees

The Paymaster pays the user's gas fees using its deposit in the EntryPoint contract. The Paymaster must make this deposit in advance using EntryPoint.depositTo().

Establishing trust through staking

To mitigate denial-of-service attacks by malicious Paymasters, such as the following, Paymasters are encouraged to maintain a stake (locked ETH).

  • Pass validation but deliberately revert during execution.
  • Consume excessive gas, affecting the bundler and other UserOperations.

Requiring ETH to be locked for a period through addStake() allows mechanisms such as temporarily suspending transaction acceptance when problematic behavior is detected.

Stake management functions (EntryPoint)
js
function addStake(uint32 _unstakeDelaySec) external payable;
function unlockStake() external;
function withdrawStake(address payable withdrawAddress) external;
  • addStake
    • Lock ETH as a stake.
    • Specify unstakeDelaySec, the waiting period before the stake can be unlocked.
  • unlockStake
    • Request unlocking (a waiting period is required).
  • withdrawStake
    • Withdraw the stake after unlocking.
Deposit management (EntryPoint)
js
function balanceOf(address account) public view returns (uint256);
function depositTo(address account) public payable;
receive() external payable;
function withdrawTo(address payable withdrawAddress, uint256 withdrawAmount) external;
  • depositTo
    • Add ETH to the specified account's deposit.
  • withdrawTo
    • Withdraw ETH from the deposit.
  • balanceOf
    • Check the current deposit balance.

Accounts as well as Paymasters can manage deposits using the same interface.

Bundler behavior: processing a received UserOperation

In ERC4337, a bundler receives UserOperation objects and submits them to the EntryPoint contract. This resembles the flow leading to ordinary Ethereum transaction execution, but involves multiple validation stages and mempool controls, requiring more sophisticated processing.

The following describes bundler behavior and the associated validation logic.

Full sequence for building a UserOperation bundle

Basic bundler processing steps

  1. Receive a UserOperation

    • The client invokes the eth_sendUserOperation RPC method and sends a UserOperation to the bundler.
  2. First validation (on receipt)

    • The bundler performs initial validation before adding the UserOperation to the mempool.
    • A UserOperation that fails this validation is discarded and an error is returned.
  3. Second validation (during bundle construction)

    • When constructing a bundle from the UserOperation objects in the mempool, revalidate each UserOperation.
    • Add valid operations to the bundle and skip those that fail.
  4. Third validation (immediately before block submission)

    • Validate the entire constructed bundle again.
    • If invalid UserOperation objects are found, remove them and update reputation scores (see ERC7562 for details).

See the following article for more about ERC7562.

[ERC7562] Understanding transaction validation rules for account abstraction

Initial validation

A bundler performs the following basic checks before adding a UserOperation to its mempool.

Check Description
Account existence consistency The sender is an existing contract or initCode is nonempty (exactly one of these conditions).
initCode format Its first 20 bytes are a factory contract address or the 0x7702 flag.
Factory stake status A factory contract that reads global state must be staked.
Verification gas limit verificationGasLimit and paymasterVerificationGasLimit are below MAX_VERIFICATION_GAS (=500000).
preVerificationGas Covers the gas cost of serialized calldata plus PRE_VERIFICATION_OVERHEAD_GAS (=50000).
Paymaster validity If paymasterAndData is nonempty:1. Contract code exists. 2. Its deposit is sufficient. 3. It is not banned.
callGasLimit Exceeds the minimum gas required for a CALL with value.
Minimum fee settings maxFeePerGas and maxPriorityFeePerGas meet the base fee and bundler-configured minimums.
Sender uniqueness There is no existing UserOperation with the same sender and nonce (if one exists, replacement is allowed only with a higher fee).Only staked senders are exceptionally permitted multiple UserOperation objects.

Example of bundle construction and block submission

  1. Alice and Bob submit UserOperation objects, which reach the bundler RPC.
  2. The bundler adds them to its mempool (only after validation).
  3. When constructing a bundle for the next block, the bundler validates them again.
  4. A bundle containing only successfully validated UserOperation objects executes through EntryPoint.handleOps().

UserOperation simulation

ERC4337 introduces simulation to validate a UserOperation in advance. Unlike ordinary Ethereum transaction validation, this is necessary to accommodate UserOperation objects whose validation results may change depending on EVM state or other transactions.

Why simulation is necessary

Ordinary Ethereum transactions permit static checks such as the following.

  • Verify the signer (EOA) using ecrecover.
  • Check whether the nonce matches the EOA's current nonce.
  • Check whether the account balance is sufficient.
  • Check whether gasLimit exceeds the base cost.
  • Check whether chainId matches the current chain.

The original explanation describes these checks as simple because they do not depend on other transactions or EVM state.

By contrast, a UserOperation requires state-dependent validation such as the following.

  • Call account.validateUserOp.
    • Function that validates the UserOperation.
  • Call paymaster.validatePaymasterUserOp.
    • The Paymaster verifies gas payment.
  • Deploy the contract account using initCode.
  • Check time restrictions (validAfter, validUntil).
    • validAfter
      • Start time at which the UserOperation becomes valid (Unix timestamp).
    • validUntil
      • Time at which the UserOperation expires.

Simulation is introduced because safely checking these state-dependent operations in advance requires executing the UserOperation provisionally on the EVM and inspecting the results.

Simulation specification

How to execute it

The bundler makes a read-only call to handleOps() containing only the target UserOperation. This is not written to the chain and is used for offchain validation.

Simulation scope

Only the validation phase is simulated; the execution phase (executing callData) is outside the required scope. To terminate simulation early, a UserOperation that always fails may also be included as the second operation in the bundle's array.

Validation steps

Simulation performs the following checks.

  1. Create the sender account if initCode is present.
  2. Call account.validateUserOp().
  3. Call paymaster.validatePaymasterUserOp() if a Paymaster is specified.
  4. If the return values from validateUserOp or validatePaymasterUserOp contain validAfter / validUntil, check that the current block time is within that range.
Notes
  • If simulation fails, the UserOperation is considered invalid and discarded from the mempool.
  • If a UserOperation is about to expire (its validUntil is too close), the bundler must also discard it.
  • The bundler needs to decode the return values using an EVM trace to check validAfter / validUntil.
DoS mitigation and restrictions

The following restrictions are necessary to protect bundlers against denial-of-service attacks during simulation.

  • Restrict the opcodes and storage operations permitted within validateUserOp() and validatePaymasterUserOp().
  • These rules are defined by ERC7562 and are designed to ensure simulation can complete safely.

Estimating preVerificationGas

In ERC4337, preVerificationGas represents the gas required before executing a UserOperation onchain. It accounts for fixed gas costs associated with transmitting and validating UserOperation data so the bundler can recover its costs appropriately.

What is preVerificationGas?

preVerificationGas covers the gas required for transmitting the calldata containing the UserOperation's execution data, fixed data, and static memory allocation. It covers the minimum overhead incurred before the EntryPoint contract's validation processing, separately from actual execution (executing callData). To process a UserOperation safely, the bundler must estimate this value accurately. If the estimate is inadequate, transaction processing may fail or the bundler may be unable to recover its upfront costs.

Components of the estimate

The specification does not prescribe a standard calculation formula, but the following costs must be included.

Base transaction cost

An Ethereum transaction requires at least 21000 gas. This cost is divided according to the number of UserOperations in the bundle. Example: a bundle with three UserOperations → 21000 / 3 = 7000 gas.

calldata gas costs (EIP2028-compliant)

Each byte of calldata incurs gas according to its value.

  • Zero byte
    • 4 gas
  • Nonzero byte
    • 16 gas

See the following article for more about EIP2028.

[EIP2028] Understanding the proposal to reduce calldata gas costs

Processing static code in the EntryPoint contract

Gas for executing static code inside the EntryPoint contract associated with the validateUserOp call.

Memory loading cost for fixed-length fields

Static memory usage when loading fixed fields of the UserOperation structure (e.g., nonce and sender) into EVM memory.

Memory cost of the context from the Paymaster's validatePaymasterUserOp (optional)

If the Paymaster returns context, include gas consumed in reading, expanding, and retaining the associated memory.

External call gas for innerHandleOp()
  • The cost of invoking innerHandleOp(), a major part of the EntryPoint contract's internal processing.
  • This cost varies depending on the operation's position within the bundle.
EIP7702 authorization cost (optional)
  • If an EIP7702 authorization is included, an additional 25000 gas is expected.
EIP7623 calldata gas floor
  • Based on the new tx.gasUsed calculation, use the following estimated values.
    • Total gas consumed by validation during simulation (account creation, validateUserOp, and the Paymaster).
    • 10% of the combined execution and postOp gas.

Bundler requirements

preVerificationGas needs a margin for future memory expansion and changes in the operation's position within the bundle. Estimating preVerificationGas at the absolute minimum creates the following risks.

  • Execution of validateUserOp() inside the EntryPoint contract fails because of insufficient gas.
  • Insufficient gas causes the entire UserOperation to fail, potentially affecting other bundled operations.
  • The bundler is unable to recover part of the gas fees it paid.

Alternative mempools

ERC4337 defines strict simulation rules to preserve security when validating a UserOperation. These help prevent denial-of-service attacks from malicious Paymasters and network instability. However, some Paymasters may be disallowed by the standard rules despite being demonstrably safe.

Alternative mempools were introduced to accommodate such situations.

Why alternative mempools are needed

Conventional mempools strictly apply the opcode and storage access restrictions defined in ERC7562. This is intended to prevent unknown or malicious Paymasters from behaving improperly during simulation. However, some use cases require Paymasters to operate without these constraints.

What is an alternative mempool?

A mechanism for applying custom validation rules that differ from those of the conventional mempool. It is used to relax particular restrictions (e.g., on opcode usage or gas limits) and operates as an independent mempool within a peer-to-peer network shared by a subset of bundlers. This enables more flexible validation rules, such as allowing only Paymasters that meet specified conditions.

Why a simple allowlist is insufficient

If individual bundlers simply accept a Paymaster because they consider it safe, the UserOperation may propagate only to a subset of bundlers, fragmenting the network. This makes behavior unpredictable for users and undermines network-wide consistency.

Alternative mempools as a solution

All participating bundlers explicitly signal their adoption of a particular set of relaxed rules and establish a separate mempool with common validation and propagation rules. This ensures that UserOperation objects complying with the relaxed rules can be propagated and processed reliably across participating bundlers.

ERC7562

The definitions and rules for alternative mempools are specified in ERC7562. It also describes which rules can be relaxed, how bundlers propagate operations, and how reputation is handled.

See the following article for more about ERC7562.

[ERC7562] Understanding transaction validation rules for account abstraction

Bundling

Bundling is the process of collecting multiple UserOperation objects and submitting them to the blockchain as a single transaction.

Required processing during bundling

A bundler must satisfy the following conditions when constructing a bundle.

  • Exclude any UserOperation that accesses the sender address of another UserOperation.
  • Also exclude any UserOperation that accesses an address created by a factory contract during validation of another UserOperation.
  • For multiple UserOperation objects using the same Paymaster, track the Paymaster's balance and verify that it can cover all fees.

Validation after constructing the transaction

Before including a bundle in a block, bundlers are encouraged to perform the following checks.

  • Run a simulation using debug_traceCall with the maximum available gas to verify that the entire handleOps call executes correctly. (Also check for violations of opcode and storage access restrictions.)
  • If simulation fails, identify the contract account most recently invoked by a CALL from the EntryPoint contract and treat it as the cause. Note that bundlers should avoid determining the cause solely from the reported FailedOp event.

Handling invalid UserOperation objects

Any invalid UserOperation must be removed from both the bundle and the mempool. If the failure is attributable to a factory contract or Paymaster, proceed as follows.

  • If the sender is not staked:
    • Ban the factory contract or Paymaster.
  • If the sender is staked:
    • Ban the sender instead of banning the factory contract or Paymaster.
  • Repeat these adjustments until debug_traceCall succeeds.

Security considerations

Staked entities (sender, factory contract, or Paymaster) may temporarily share data with other UserOperation objects. Therefore, the same restrictions (prohibited opcodes and storage access restrictions) must apply to validation of the entire handleOps call, just as they do to individual UserOperation objects. Otherwise, an attacker may use prohibited opcodes to distinguish onchain execution and deliberately trigger a FailedOp event.

Considerations when including a bundle in a block

Prevent UserOperation failures caused by preceding transactions in the block. The following measures are recommended.

  • Use EIP2930 access lists to avoid conflicts.
  • Alternatively, place the bundle as the first transaction in the block.

See the following article for more about EIP2930.

[EIP2930] Understanding the proposal to introduce a new transaction type with an access list

Handling error codes

The EntryPoint contract must revert when an error occurs during validation of a UserOperation. However, the bundler needs to determine accurately which entity (sender, factory contract, or Paymaster) caused the error.

Identifying the source of an error

The entity responsible for the failure (sender, factory contract, or Paymaster) is identified as follows. Use the call trace to identify the contract invoked through CALL immediately before the revert that occurred during EntryPoint processing.

A call trace is a record of the call history of operations executed on the EVM. During EVM execution, one contract may invoke a function on another contract using the CALL opcode. A call trace reveals in detail which contracts invoked which functions and in what order. Call traces can be retrieved through RPC methods such as debug_traceCall.

  • The last entity invoked (sender, factory contract, or Paymaster) is treated as the source of the error.

Error formats

The EntryPoint contract must revert using only the following explicit error types during simulation or actual execution.

  • SignatureValidationFailed()
  • FailedOp()
  • FailedOpWithRevert()

This enables bundlers to identify the cause accurately in combination with call-tracing.

Error code conventions (AA##)

Each error has an identifying code (AA##), with the prefix identifying the error category.

Error code Where it occurs Meaning
AA1x Sender creation Account creation error in the factory
AA2x Sender validation Error executing validateUserOp
AA3x Paymaster validation Error executing validatePaymasterUserOp

These error codes allow the error category to be identified quickly.

Additional notes

Separating validation and execution as a DoS mitigation

When implementing account abstraction solely through contract accounts, one difficulty is that it would otherwise be necessary to execute an operation to determine whether its gas fees will actually be paid. Such a mechanism would permit denial-of-service attacks in which an attacker submits many malicious UserOperation objects that revert at the end of execution, imposing excessive load on bundlers and block builders.

To prevent this, ERC4337 separates validation (signature verification and checking the ability to pay) from execution. Accounts implement validateUserOp, which verifies signatures and confirms payment in advance. Execution using callData occurs only when validation succeeds.

Improving security through validation restrictions

Restrictions on storage and opcodes used during validation prevent bundlers from inadvertently including invalid UserOperation objects. These restrictions address cases such as the following.

  • A UserOperation that passes validation individually but fails when included in a block.
  • A UserOperation that fails validation because it interferes with another UserOperation.

To prevent these cases, bundlers must accept UserOperation objects according to the validation rules defined in ERC7562.

Reputation-based controls and throttling

Global entities such as Paymasters and factory contracts are shared by multiple UserOperation objects, so one instance of misbehavior can invalidate multiple operations. The following mechanisms help prevent this.

  • Entities that invalidate UserOperation objects at a certain rate are subject to throttling (reduced processing rates) or temporary bans from the mempool.
  • Requiring a stake (a deposit of ETH) raises attack costs and mitigates Sybil attacks involving the creation of many fake entities.
  • Stakes are not confiscated or slashed and can be withdrawn after the specified unstakeDelay.

Gas abstraction through a Paymaster

A Paymaster is a contract that allows someone other than the transaction sender to cover gas fees. For example, a token Paymaster that accepts ERC20 tokens for gas fees can charge the maximum estimated payment in advance and refund the excess to the user after execution.

Initial creation of a contract account

A factory contract is used to create a contract account. By generating its address deterministically using CREATE2 (opcode 0xF5), the address can be predicted even before the account is created.

  • The initCode field contains the 20-byte factory contract address and initialization calldata passed to it.
  • The UserOperation is aborted if executing initCode does not create a contract at the specified sender address, or if the contract at that address is not the expected one.
  • If a factory contract accesses storage, it needs a stake as a DoS mitigation.

This mechanism allows users to prepare an address and send funds to it safely without deploying the contract in advance. It provides the experience of an account that can receive funds immediately, just like an EOA.

Compatibility

Because ERC4337 does not change Ethereum's consensus layer (the underlying mechanism responsible for block production and transaction finality), it does not introduce compatibility problems for Ethereum as a whole.

However, it is not directly compatible with contract accounts created before ERC4337. These accounts do not implement validateUserOp, a key function in ERC4337.

If an existing account has a mechanism for allowing trusted UserOperation senders, such as access control through authorized controllers, compatibility can be maintained by creating an ERC4337-compliant account that wraps the original account's validation logic and configuring the new account as a trusted sender.

Reference implementation

Security considerations

Because the EntryPoint contract is central to all operation processing in ERC4337, it requires thorough auditing and formal verification. This design reduces the responsibilities of individual contract accounts and limits the scope they need to verify, but the EntryPoint becomes a single point of failure and therefore needs to be highly robust.

EntryPoint security

Two points are particularly important when verifying the EntryPoint contract.

  • Preventing unauthorized calls The EntryPoint must execute callData only for a sender account whose validateUserOp has already succeeded.

  • Preventing improper fee payments Only when validateUserOp succeeds must the EntryPoint execute the callData specified by the UserOperation.

Secure caller verification by each contract

Under the EntryPoint security model, each contract must restrict callers as follows.

  • Factory contracts Verify that createAccount() is called only from entryPoint.senderCreator().

  • Paymaster contracts Restrict validatePaymasterUserOp() and postOp() to calls from the EntryPoint.

  • Aggregator contracts Restrict validateSignatures() to calls from the EntryPoint contract.

  • EIP7702-based accounts Restrict the initialization function to calls from entryPoint.senderCreator(), and ensure that the same initialization code cannot run multiple times.

Because the EntryPoint itself cannot determine whether an EIP7702 account has been initialized, wallet applications should avoid repeatedly submitting initCode.

Additional considerations for contract accounts

  • Avoiding storage layout collisions Many accounts are designed to be upgradeable and must avoid storage collisions between different implementations. Techniques such as the diamond storage pattern defined by ERC7201 are recommended.

See the following article for more about ERC7201.

[ERC7201] Understanding efficient namespaced storage management

  • Handling transient storage When using transient storage defined by EIP1153, remember that ERC4337 may include multiple UserOperation objects from different senders within one transaction. Manually clean up transient storage if it is used for access control or sensitive information.

References

Vitalik Buterin (@vbuterin), Yoav Weiss (@yoavw), Dror Tirosh (@drortirosh), Shahaf Nacson (@shahafn), Alex Forshtat (@forshtat), Kristof Gazso (@kristofgazso), Tjaden Hess (@tjade273), "ERC-4337: Account Abstraction Using Alt Mempool [DRAFT]," Ethereum Improvement Proposals, no. 4337, September 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4337.

References

Vitalik Buterin (@vbuterin), Yoav Weiss (@yoavw), Dror Tirosh (@drortirosh), Shahaf Nacson (@shahafn), Alex Forshtat (@forshtat), Kristof Gazso (@kristofgazso), Tjaden Hess (@tjade273), "ERC-4337: Account Abstraction Using Alt Mempool [DRAFT]," Ethereum Improvement Proposals, no. 4337, September 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4337.

This section collects accessible articles about AA (Account Abstraction) and ERC4337. Use the resources in this section for further reading.

Understanding account abstraction (ERC4337) by following concrete processing steps

Account abstraction study session

A world centered on contract wallets beyond AA (Account Abstraction)

Applying signature aggregation to AA (Account Abstraction)

Learning blockchain through video: Ethereum account abstraction — 中城元臣

Understanding account abstraction through ERC4337

What is account abstraction?

https://medium.com/@bluesky-aozora/account-abstraction-%E3%82%A2%E3%82%AB%E3%82%A6%E3%83%B3%E3%83%88%E6%8A%BD%E8%B1%A1%E5%8C%96-%E3%81%A8%E3%81%AF-9fa34a5de876

ERC 4337: account abstraction without Ethereum protocol changes

https://medium.com/infinitism/erc-4337-account-abstraction-without-ethereum-protocol-changes-d75c9d94dc4a

Misconceptions and truths about account abstraction

ERC-4337 Documentation

ERC-4337 Progress report

[EIP-4337] From submitting a UserOperation to a bundler to issuing a transaction

Ethereum wallets today and tomorrow — EIP-3074 vs. ERC-4337

https://medium.com/nethermind-eth/ethereum-wallets-today-and-tomorrow-eip-3074-vs-erc-4337-a7732b81efc8

The power of account abstraction: technical overview of RaisePay Wallet

https://medium.com/@bluesky-aozora/account-abstraction%E3%81%AE%E5%A8%81%E5%8A%9B-raisepay-wallet%E3%81%AE%E6%8A%80%E8%A1%93%E7%9A%84%E6%A6%82%E8%A6%81-76d6f9898e37

Why we need wide adoption of social recovery wallets

https://vitalik.ca/general/2021/01/11/recovery.html

Conclusion

This article covered ERC4337, a proposal for implementing account abstraction without changing the protocol. I hope the explanation was useful.

If you have any questions, feel free to contact me through Twitter direct messages using the link below.

Twitter @cardene777