ERC-4337 Overview

Introduction

This page briefly outlines the ERC-4377, including its architecture, workflow, and conclusion.

Architecture

In the ERC-4337 proposal, there are several main components:

  1. UserOperation is a data structure that describes a transaction to be sent on behalf of a user.
  2. Bundlers are actors that handle and bundling UserOperations. UserOperations are bundling into transactions, and then Bundlers send the transactions to the EntryPoint contract on the blockchain.
  3. EntryPoint is a smart contract deployed on the blockchain. The EntryPoint contract validate every UserOperations of Transaction, get found from wallet contract or paymaster and pass callData to wallet contracts.
  4. Wallet Contracts are smart contract accounts owned by users, also called smart account.
  5. Paymastersare optional smart contract accounts that can sponsor transactions for Contract Accounts.
  6. Aggregators are optional smart contracts that can validate signatures for multiple Contract Accounts.

UserOperation

UserOperation is the core data structure in ERC-4337, and it is passed between most of the components. It represents the user's intent or action. The following is its structure definition:

FieldTypeDescription
senderaddressThe address of the smart account sending the User Operation.
nonceuint256Anti-replay protection.
initCodebytesCode used to deploy the sender if not yet on-chain.
callDatabytesData that's passed to the sender for execution.
callGasLimituint256Gas limit for the execution phase.
verificationGasLimituint256Gas limit for the verification phase.
preVerificationGasuint256Gas to compensate the bundler for the overhead to submit the User Operation.
maxFeePerGasuint256Similar to EIP-1559 maxFeePerGas
maxPriorityFeePerGasuint256Similar to EIP-1559 maxPriorityFeePerGas.
paymasterAndDatabytesPaymaster contract address and any extra data the paymaster contract needs for verification and execution. When set to 0x or the zero address, no paymaster is used.
signaturebytesUsed to validate a User Operation during verification.

Workflow

The workflow proposed by ERC-4337 can be divided into two parts: on-chain and off-chain. We will now provide a detailed explanation of each part.

Off-Chain

Figure1: The off-chain part of workflow

Figure1: The off-chain part of workflow

The off-chain workflow of ERC-4337 is illustrated in Figure 1. The detailed steps are as follows:

  1. The client calls the eth_estimateUserOperationGas API to estimate the gas consumption (callGasLimit, verificationGasLimit, and preVerificationGas) for the UserOperation, which was sent in the next step.
  2. The client gets suggested gas price from blockchain node, constructs the UserOperation and sends it to bundler(by eth_sendUserOperation API).
  3. The bundler validates the UserOperation and put valid UserOperation into mempool.
  4. The bundler loads a batch of UserOperations from mempool.
  5. The bundler bundles a batch of valid UserOperations into a transaction, and send the transaction to EntryPoint smart contract deployed on blockchain.

On-Chain

Figure2: The on-chain part of workflow

Figure2: The on-chain part of workflow

As shown in Figure 2, the on-chain part of the workflow can be mainly divided into two parts: validation phase and execution phase.

In the validation phase, EntryPoint smart contract verifies that each UserOperation is valid by checking it with either the Wallet contract or the Paymaster contract.

In the execution phase, EntryPoint smart contract sends the callData in each UserOperation to the Wallet contract.

Please note: bundler runs simulations to check the verification phase, but it doesn't check the execution phase.

Conclusion

As described before, by using Bundler, users can express their transaction intent through UserOperation, thus achieving decoupling of transaction actions from the possession of an EOA account key.