How bundlers work
Listening to alternative mempools and packing UserOps into valid EVM L1/L2 transactions.
The Bundler is the primary driver of the ERC-4337 transaction engine. It bridges the gap between off-chain UserOperations and on-chain EVM transactions.
1. The Alternative Mempool (Alt-Mempool)
Standard Ethereum mempools only hold standard transactions signed by EOAs. To prevent spamming the L1 network, ERC-4337 defines a decentralized network of Bundlers that share an Alternative Mempool (Alt-Mempool).
- The client broadcasts the
UserOperationto a bundler node via theeth_sendUserOperationRPC method. - The receiving bundler validates the UserOp locally (verifying the signature and checking if the wallet or Paymaster has deposited gas).
- If valid, the bundler propagates the UserOp to other bundler nodes in the alt-mempool.
2. Bundling and Execution
The bundler is a standard EOA account on the target blockchain network. At regular intervals or when its local queue reaches a threshold, the bundler packages the UserOperations:
- Aggregation: The bundler aggregates multiple UserOps into an array.
- Transaction Construction: The bundler constructs a standard EVM transaction that targets the
EntryPointsmart contract:- Target:
EntryPointAddress - Value:
0 - Data: A call to
entryPoint.handleOps(UserOperation[] ops, address beneficiary)
- Target:
- Submission: The bundler signs the transaction with its own EOA private key and broadcasts it to the standard blockchain mempool.
3. Bundler Economics
Why do bundlers perform this service? Running node infrastructure and submitting transactions costs gas.
Bundlers make a profit through a gas markup system:
- Each
UserOperationspecifies apreVerificationGasandmaxPriorityFeePerGas(the tip). - The EntryPoint contract calculates the total gas used by the operations during execution and pays the bundler out of the user's Smart Account or Paymaster deposit.
- The payout is executed in native tokens at the end of the
handleOpsframe:Payout = GasUsed * GasPrice - If the bundler executes the transaction efficiently, the gas they pay to the network is less than the aggregated fees they collect from the operations, yielding a profit.
Was this lesson helpful?
Let us know what you think of this specification. (submitting anonymously)
