Bundler
(under ERC-4337)
jiahui.cui (doublespending) @ imToken Labs
Dec 21 2023 | Dapp Learning & imToken
Equal access to the Tokenized World
SPEAKER
Jiahui Cui
Researcher @ imToken Labs
AGENDA
Bundler in ERC-4337
01
UserOp Lifecycle with Bundler
02
Tips for Developers
03
Bundler in the Future
04
Bundler in ERC-4337
01
Role of Bundler in ERC-4337
Bundler Simulation
We need to “simulate” userOp validation (defined by contract) to make sure it is valid, and that it is capable of paying for its own execution.
Bundler Simulation
validateUserOp() {
if block.basefee < 30 gwei {
do something…
}�}�—---------------------------------------------�⇒ Pass ✅
1
2
validateUserOp() {
if block.basefee < 30 gwei {
do something…
}�}�—---------------------------------------------�⇒ Fail ❌
runs simulation at �block number N (basefee = 29 gwei)
sends userOp tx at �block number N+1 (basefee = 31 gwei)
Bundler Simulation
Forbidden Opcodes During Validation
Forbidden Storage Access During Validation
source: https://eips.ethereum.org/EIPS/eip-4337
Forbidden Storage Access During Validation
Account storage access | undeployed account | account |
factory (stake) | account (self & associated storage) | account (self & associated storage) |
factory (not stake) | account (self) | account (self & associated storage) |
Forbidden Storage Access During Validation
Paymaster storage access | undeployed account | account |
paymaster (stake) | account (self & associated storage) paymaster (self & associated storage) | account (self & associated storage) paymaster (self & associated storage) |
paymaster (not stake) | account (self) | account (self & associated storage) |
Forbidden Storage Access During Validation
Factory storage access | undeployed account | account |
factory (stake) | account (self & associated storage) factory (self & associated storage) | account (self & associated storage) factory (self & associated storage) |
factory (not stake) | account (self) | account (self & associated storage) |
Forbidden Storage Access During Validation
Why facotry/paymaster should stake to access its storage?
Because factory/paymaster can be used by multi userOps. So, hey can invalid multi userOps at the same time if they can access their storage in validation.
If they stake, we can ban them when they misbehave.
UserOp Lifecycle with Bundler
02
UserOp Lifecycle with Bundler
UserOp Lifecycle with Bundler
STEPS | EOA by Node | AA by Bundler | |
1. Get Sender | Derive from Private Key | `eth_call` EntryPoint | |
2. Get Nonce | `eth_getTransactionCount` | `eth_call` EntryPoint | |
UserOp Lifecycle with Bundler
STEPS | EOA by Node | AA by Bundler | |
3. Get GasLimit | `eth_estimateGas` | `eth_estimateUserOperationGas`
|
|
4. Get GasPrice | `eth_getBlockByNumber` -> baseFee ============== `eth_maxPriorityFeePerGas` -> priorityFee | To protect bundler, we cannot use priority fee from `eth_maxPriorityFeePerGas` directly on some chains like Arbitrum & Optimism. | |
UserOp Lifecycle with Bundler
STEPS | EOA by Node | AA by Bundler | |
5. Send TX | `eth_sendTransaction` | `eth_sendUserOperation`
|
|
6. Get Recipent | `eth_getTransactionReceipt` | `eth_getUserOperationReceipt` | You can just filter `UserOperationEvent` on EntryPoint instead.
|
UserOp Lifecycle with Bundler
OTHER APIS | EOA By Node | AA By Bundler |
Get chainId | eth_chainId | eth_chainId |
Get supported EntryPoints | | eth_supportedEntryPoints |
Get Tx By Hash | eth_getTransactionByHash | eth_getUserOperationByHash |
Tips for Developers
03
How to inspect a userOp
polygonscan.com
How to inspect a userOp
polygonscan.com
How to inspect a userOp
jiffyscan.xyz
eth_getUserOperationReceipt vs eth_getUserOperationByHash
eth_getUserOperationReceipt | eth_getUserOperationByHash |
Only for onchain userOp
| Only for onchain userOp
|
Tx Error
How I get error messages from my Account / Paymaster / Bundler?
Tx Error
Error Code | Reason |
-32602 | invalid UserOperation struct/fields |
-32500 | transaction rejected by entryPoint’s simulateValidation, during wallet creation or validation |
-32501 | transaction rejected by paymaster’s validatePaymasterUserOp |
-32502 | transaction rejected because of opcode validation |
-32503 | UserOperation out of time-range |
-32504 | transaction rejected because paymaster (or signature aggregator) is throttled/banned |
-32505 | transaction rejected because paymaster (or signature aggregator) stake or unstake-delay is too low |
-32506 | transaction rejected because wallet specified unsupported signature aggregator |
-32507 | transaction rejected because of wallet signature check failed (or paymaster signature) |
Validation Rules
Why I cannot pass bundler simulation when my userOp works in foundry?
It is usually because you go against validation rules of bundler.
Forbidden opcodes during validation
PimlicoERC20Paymaster
Forbidden Storage access during validation
Why my ERC-20 paymaster works for USDT but not USDC?
It is because USDC is a proxy contract. The implementation slot of USDC is not associated storage of account/paymaster.
Paymaster storage access | undeployed account | account |
paymaster (stake) | account (self & associated storage) paymaster (self & associated storage) | account (self & associated storage) paymaster (self & associated storage) |
paymaster (not stake) | account (self) | account (self & associated storage) |
Forbidden Storage access during validation
Can we implement a Token Bound Account (TBA) based on ERC-4337?
It’s hard to implement. TBA uses tokenId to fetch owner from the corresponding ERC-721 contract in validation. However, tokenId is not associated storage of account/paymaster.
Paymaster storage access | undeployed account | account |
paymaster (stake) | account (self & associated storage) paymaster (self & associated storage) | account (self & associated storage) paymaster (self & associated storage) |
paymaster (not stake) | account (self) | account (self & associated storage) |
Some Implicit Rules
Some Implicit Rules
Throttled paymaster can only be used once in a bundle.
Gas Estimation - Dummy Signature
Gas Estimation - Gas Settings
Gas Estimation - Gas Settings
Bundler is expected to handle gas setting for us. However, this setting is out of ERC-4337 spec. So, some bundler cannot handle it well.
Gas Estimation - Bundler Interaction
There is currently no spec for bundler gas estimation. Different bundler may use different implementations.
So, if we handle gas estimation in bundler A, the return gas limit from bundler A may be rejected by bundler B.
Gas Price - Priority Fee
Gas Price - Buffer
To compensate the bundler, the buffer of gas price is different from normal EOA transaction
Gas Price - Buffer
To compensate the bundler, the buffer of gas price is different from normal EOA transaction
Bundler in the Future
04
P2P Bundler Mempool
UserOp
UserOp
UserOp
userOp mempool
UserOp
UserOp
UserOp
Bundler
Bundler
Bundler
Gas Price Estimation
Gas Estimation Specs
Alternative Mempools
UserOp
UserOp
UserOp
Main mempool
UserOp
UserOp
UserOp
Bundler
Bundler
Bundler
UserOp
Alt mempool (white list USDC contract)
Support Aggregator
Thank you
Equal access to the Tokenized World
Dec 21 2023 | Dapp Learning & imToken