Compatible With ERC-4337
ERC-4337 is an Ethereum Improvement Proposal proposed by Vitalik Buterin and others. Its purpose is to achieve account abstraction without changing the Ethereum consensus layer.
ERC-4337 defines a new specification. For example, it transforms transactions into UserOperation objects. Through a Bundler, the intentions, signatures and other data of multiple users can be bundled and passed to an Entry Point for batch validation and execution of transactions. The Paymaster mechanism is introduced to achieve decentralized transaction fee payment.
The overall protocol of ERC-4337 is very complex. To help everyone understand the entire process, we can break it down into parts:
UserOperation objects: ERC-4337 transforms raw transactions into UserOperation objects that include the user's intention, signature and other data.
Bundler: Multiple UserOperation objects from different users are bundled together and passed to the Entry Point. This allows for batch validation and execution.
Entry Point: The bundled UserOperation objects are received and validated by the Entry Point. Valid operations are then executed on Ethereum.
Paymaster: The Paymaster mechanism is used to pay transaction fees in a decentralized manner, bypassing the need for users to include fees in each transaction.
Account abstraction: All of this allows ERC-4337 to achieve account abstraction at the application layer, without changing Ethereum's consensus rules or protocol.
UserOperation & Bundler
The contract wallet user creates a transaction, referred to as a "UserOperation", signed by the contract wallet user. Although UserOperation is structurally different from transactions signed by externally owned accounts, it can essentially be treated the same.
In order to submit the UserOperation to the blockchain, the contract wallet needs to use an entity known as a "Bundler". The Bundler acts as an intermediary that aggregates multiple UserOperations into a single transaction and submits it to the network.
Here are the specific steps:
The user signs a UserOperation, representing their transaction.
The signed UserOperation is sent to the UserOperation memory pool (also referred to as the Alternative memory pool in the latest ERC-4337 specification), which serves a similar purpose as the regular Transaction memory pool.
The Bundler selects UserOperations from the memory pool and combines them into a single "Bundle Transaction".
The Bundler then submits this Bundle Transaction to the blockchain. (The full execution process also involves verification and execution by an "Entry Point", which we can discuss in more detail separately).
Essentially:
Contract wallet users create UserOperations instead of typical transactions
The Bundler aggregates multiple UserOperations into a single transaction
The Bundler submits the bundled transaction to the blockchain
Entry Point
Now let's briefly understand how transactions are validated and executed after submission to the blockchain. An Entry Point Smart Contract (referred to as the Entry Point) acts as the unified validation entry point called by UserOperation. The Bundler will call the handleOps() function in the Entry Point to validate and execute the transaction submitted to the chain.
Of course, to improve the success rate of on-chain transactions, after bundling the Bundle Transaction, the Bundler will first use an RPC call to call simulateValidation() in the Entry Point locally. This ensures that the signatures of these UserOperations are correct and that gas fees can be paid normally, before broadcasting the transaction to the chain.
The key points are:
An Entry Point smart contract validates and executes UserOperations
The Bundler calls the Entry Point's handleOps() function to validate bundled transactions
The Bundler uses simulateValidation() to validate signatures and gas fees locally, before submission to the chain
The Entry Point acts as a unified validation entry point for UserOperations, ensuring they are properly signed, have sufficient gas fees, etc. before execution on the blockchain.
Paymaster
The Paymaster pays gas fees on behalf of users, potentially in any token
The Entry Point validates UserOperations and executes transactions
The Bundler calls the Entry Point to bundle and submit multiple UserOperations
The key roles are:
The Bundler calls the handleOps() function in the Entry Point.
The EntryPoint passes the UserOperation as a parameter to validateUserOp() in the Wallet Contract, verifying all transactions that need validating. Only when validation succeeds will subsequent operations continue.
At this point, the Entry Point first confirms the status of the specified Paymaster in UserOperation, such as whether the Paymaster has enough ETH to pay the transaction fee.
Then, the Entry Point calls validatePaymasterUserOp() in the Paymaster Contract to confirm whether the Paymaster is willing to pay the transaction fee. If so, the transaction will continue; otherwise, it will fail.
Next, the Entry Point calls the Wallet Contract and executes the content specified in UserOperation itself.
Then, the Entry Point calls the Post-Op() in the Paymaster Contract, which processes custom logic such as direct sponsorship or deduction of ERC20 tokens on behalf of the user.
The Entry Point deducts the gas fee required for the transaction from the ETH balance pledged by the Paymaster.
Finally, the Entry Point collects the total gas fee required for all transactions and refunds it to the Bundler. The transaction is completed.
Here are the detailed steps:
Finally, we will provide a detailed explanation of the operations executed by the Bundler after calling the handleOps() function in the Entry Point. Additionally, we will introduce an important role called the Paymaster. The Paymaster assists users in paying gas fees and enables them to pay gas fees using any token.
Last updated