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:
- UserOperation is a data structure that describes a transaction to be sent on behalf of a user.
- 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.
- 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.
- Wallet Contracts are smart contract accounts owned by users, also called smart account.
- Paymastersare optional smart contract accounts that can sponsor transactions for Contract Accounts.
- 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:
Field | Type | Description |
---|---|---|
sender | address | The address of the smart account sending the User Operation. |
nonce | uint256 | Anti-replay protection. |
initCode | bytes | Code used to deploy the sender if not yet on-chain. |
callData | bytes | Data that's passed to the sender for execution. |
callGasLimit | uint256 | Gas limit for the execution phase. |
verificationGasLimit | uint256 | Gas limit for the verification phase. |
preVerificationGas | uint256 | Gas to compensate the bundler for the overhead to submit the User Operation. |
maxFeePerGas | uint256 | Similar to EIP-1559 maxFeePerGas |
maxPriorityFeePerGas | uint256 | Similar to EIP-1559 maxPriorityFeePerGas. |
paymasterAndData | bytes | Paymaster 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. |
signature | bytes | Used 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](https://files.readme.io/13c473d-image.png)
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:
- 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.
- The client gets suggested gas price from blockchain node, constructs the UserOperation and sends it to bundler(by eth_sendUserOperation API).
- The bundler validates the UserOperation and put valid UserOperation into mempool.
- The bundler loads a batch of UserOperations from mempool.
- 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](https://files.readme.io/9ca07d6-fig1_Copy.png)
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.
Updated 11 months ago