Bundler is a special class of actor that act as a relayer between account abstraction transaction (called userOperation
) and actual transaction on-chain through EntryPoint contract. Bundler fetch userOperation
from alternate mempool, do validation and simulation before send it to EntryPoint contract, and return any response back through RPC. This bundler implement EIP-4337 RPC calls without debug_*
calls.
Further read:
https://www.blocknative.com/blog/account-abstraction-erc-4337-guide#7
Bundler receive RPC methods from endpoint and return any result. The methods including:
-
eth_sendUserOperation
-
eth_getUserOperationByHash
-
eth_getUserOperationReceipt
-
eth_chainId
-
eth_supportedEntryPoints
-
eth_estimateUserOperationGas
-
web3_clientVersion
: returnaa-bundler
+/erc4337RuntimeVersion
(version of@account-abstraction/utils
SDK) +/unsafe
if bundler run with unsafe mode
For parameter required and return value, refer EIP4337 article.
-
validate EntryPoint input
-
validate
userOperation
input parameters -
simulate validate
userOperation
by Geth traceCall (or by EntryPoint if input--unsafe
when run bundler) -
validate if signature is correct
-
validate if
userOperation
is expired / going to expire soon
Add into mempool after all validation passed
Auto-bundler create bundle for at most autoBundleMempoolSize
amount of userOperation
from mempool every autoBundleInterval
seconds set in bundler.config.json
-
sort
userOperation
s from mempool descending by highest priority fee -
skip (or remove if banned)
userOperation
s that use throttled factory/paymaster -
skip
userOperation
s that execute by same AA account (no duplicate AA account execution in one bundle, multiple execution within same AA account can use batch execution in singleuserOperation
) -
do validation check for
userOperation
again (in caseuserOperation
been skipped in first attempt bundle), and remove from mempool if failed -
check if Paymaster balance is enough to pay all
userOperation
s that rely on Paymaster in the bundle
Bundler signer sign and send bundle to EntryPoint. If bundle failed on-chain, sender/paymaster/factory that cause it will be recorded in reputation system
-
Run
yarn && yarn preprocess
-
Change parameters in
./packages/bundler/localconfig/bundler.config.json
-
network
: RPC to connect i.e. Arbitrum RPC URL -
beneficiary
: wallet to receive gas reimbursement -
minBalance
: minimum balance in bundler signer, if lower than this value,beneficiary
will auto assign to bundler signer -
mnemonic
: mnemonic of bundler signer to execute AA transaction -
maxBundleGas
: gas limit per bundle -
minStake
: Paymaster minimum stake in EntryPoint -
minUnstakeDelay
: minimum seconds Paymaster stake locked in EntryPoint before able to unstake, Paymaster will be rejected if lower than this value -
autoBundleInterval
: interval seconds to bundle at mostautoBundleMempoolSize
amount ofuserOperation
s in mempool -
autoBundleMempoolSize
: maximum amount ofuserOperation
per bundle
-
Fund bundler signer at least
minBalance
ETH -
Run bundler with
yarn run bundler
, oryarn run bundler --unsafe
if connect to RPC that doesn't support Geth trace calldebug_traceCall
. (i.e. Alchemy free RPC)
Debug: run debug mode with DEBUG=* yarn run bundler
Why forbidden opcodes?
These opcodes are forbidden because their outputs may differ between simulation and execution, so simulation of calls using these opcodes does not reliably tell what would happen if these calls are later done on-chain.
Refer full paragraph here
This bundler currently not support signature aggregator
User send userOperation
through bundler RPC. Bundler run some validation on userOperation
, and only add it into mempool if the validation check passed. Then, bundler attempt to bundle all userOperation
s that sit in mempool follow these criteria: every autoBundleInterval
seconds or total userOperation
s in mempool exceed autoBundleMempoolSize
. When criteria met, bundler first remove previous userOperation
s that had executed successfully on-chain, and record into reputation system (success + 1). Then follow by create a new bundle. In the process of bundle creation, if the userOperation
use banned Factory or Paymaster contract, userOperation
will be removed directly from mempool. Throttled Factory or Paymaster will not be included in bundle and keep in mempool until their reputation become better (as time goes by). userOperation
with same AA wallet in bundle will also been skipped (which can be included in next bundle). After that, same validation check on userOperation
again before finally add into bundler, and remove the userOperation
from mempool if check failed. Other check including total gas used of userOperation
in bundle cannot exceed maxBundleGas
(skip subsequence userOperation
if exceed), and Paymaster ETH balance that able to sponsor all userOperation
s that rely on it in same bundle (skip subsequence userOperation
s if exceed).
TODO: explain in simple term
Refer full explanation here
TODO: different between safe and unsafe bundler
Why need safe bundler? Some explanation here
TL:DR, to prevent success on validation but failed on execution.