alchemyplatform / rundler

An ERC-4337 Bundler in Rust
GNU Lesser General Public License v3.0
286 stars 43 forks source link

Bundler gives weird PVG in OP stack chains #908

Open ChiHaoLu opened 1 week ago

ChiHaoLu commented 1 week ago

Describe the bug Hi, I use the alchemy bundler on OP stack chains, but the preVerificationGas returned by the estimateUserOperationGas is weird.

[JsonRpcProvider][eth_estimateUserOperationGas][request] {"jsonrpc":"2.0","id":0,"method":"eth_estimateUserOperationGas","params":[{"sender":"0x886249b36f169612fF75975071Cae0C51f80E8b1","nonce":"0x0","callData":"0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000004800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000886249b36f169612ff75975071cae0c51f80e8b1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000184d64db8fc0000000000000000000000004294dd02e30b9b6c8787d00dde46abe31aac506f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000502801e794fd1b9048ec9c97fd34f62bf0488222000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a40fd8377b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000024c4d66de8000000000000000000000000886249b36f169612ff75975071cae0c51f80e8b10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004294dd02e30b9b6c8787d00dde46abe31aac506f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001443f707e6b00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e58000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002aeeb6ac7a9b98fa7a086f725df0cc10c3cbde2d00000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","factory":"0x5eab992e90ce6144df8f218c359bcafa787acd85","factoryData":"0x4d44ac28000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000124cf7a1d770000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0320000000000000000000000005442f6bd07b08f164a616d829dda50eae93f2dae000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a06b9889c4476b60e9e1764e0a706e8d374c2c8c6ded1369a359102b618a1d1d573f362de3b13b75e9a09a2546d5ad59fda27dfd5531d194faa42ccaff19fb3c6e49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630000000000000000000000004d7f573039fddc84fdb28515ba20d75ef6b987ff000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000","maxFeePerGas":"0xf43ee","maxPriorityFeePerGas":"0xf4240","signature":"0x5442f6bd07b08f164a616d829dda50eae93f2dae000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040e6957b6184564b3c8619910d1c4814da267124d6b633ec4b6ea815b3d0a00c280556ef669e59df09d5ee03d48f76a9c2c5a927d66d51603dffc80330d3adeeef000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005050000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000362c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a35313733222c2263726f73734f726967696e223a66616c73657d0000000000000000000000"},"0x0000000071727De22E5E9d8BAf0edAc6f37da032"]}
[JsonRpcProvider][eth_estimateUserOperationGas][response] {
  "jsonrpc": "2.0",
  "id": 0,
  "result": {
    "preVerificationGas": "0x35b9c5",
    "callGasLimit": "0x85bb8",
    "verificationGasLimit": "0xdcbef",
    "paymasterVerificationGasLimit": null
  }
}

If I send this userOp to bundler, the precheck will failed due to PVG is too low.

Error: {
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": -32000,
    "message": "precheck failed: preVerificationGas is 1133120 but must be at least 2490360"
  }
}

This problem also occurs in all OP stack.

To reproduce Re-estimate the above userOp by calling Alchemy Bundler API again on OP mainnet before the block 0x79ed4e2.

Because I have sent userOp w/ this nonce on chain successfully be re-calculate the PVG by myself.

Expected behavior The PVG should be lower.

dancoombs commented 1 week ago

Couple of things here:

  1. PVG is a dynamic value on L2s as its dependent on both the L2 fees as well as the L1 DA fee (blob or calldata depending on the network). Thus, its important to quickly submit UOs after estimation. A buffer is also recommended to be added to increase the chances of landing the UO. The longer it takes between estimation and submission, the higher buffer you should use.
  2. Gas estimation uses the supplied maxFeePerGas and maxPriorityFeePerGas values when estimating. Since those impact PVG its recommended that they don't change between estimation and submission.
  3. When doing gas estimation is recommended to use dummy signatures that cause the highest amount of gas utilization, including calldata costs.
ChiHaoLu commented 1 week ago

I know all of things you mentioned. But the problem is that the responded PVG is rational or not. It is much higher than other chains.

Below example is my latest userOp which sent successfully on OP mainnet.

The PVG (responded by bundler) is 0x21ea868(= 35,563,624), the total cost for userOp sender is 0x28515a648335 (= 0.000044329873998645 ETH).

[JsonRpcProvider][eth_estimateUserOperationGas][request] {"jsonrpc":"2.0","id":0,"method":"eth_estimateUserOperationGas","params":[{"sender":"0x5F890C1952e8952ACFafc829143aeEA5f2a27a5d","nonce":"0x0","callData":"0xe9ae5c5301000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002600000000000000000000000005f890c1952e8952acfafc829143aeea5f2a27a5d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000184d64db8fc00000000000000000000000092c6e5d5ceb3e069abe4b58caae0d850ae40e51c00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000502801e794fd1b9048ec9c97fd34f62bf0488222000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a40fd8377b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000024c4d66de80000000000000000000000005f890c1952e8952acfafc829143aeea5f2a27a5d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000092c6e5d5ceb3e069abe4b58caae0d850ae40e51c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001443f707e6b00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e58000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002aeeb6ac7a9b98fa7a086f725df0cc10c3cbde2d00000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","factory":"0x5eab992e90ce6144df8f218c359bcafa787acd85","factoryData":"0x4d44ac28000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000124cf7a1d770000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0320000000000000000000000005442f6bd07b08f164a616d829dda50eae93f2dae000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a06f0c704a838d013c0dcfcd626e71908f6d7e83e73f49cb4b8086cb066aa1ba34293c23677b07a0f1df6430d796fee487e382b16155d39903b21d7d7c08d52ad749960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630000000000000000000000004d7f573039fddc84fdb28515ba20d75ef6b987ff000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000","maxFeePerGas":"0x125175","maxPriorityFeePerGas":"0x124f80","signature":"0x5442f6bd07b08f164a616d829dda50eae93f2dae000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040e6957b6184564b3c8619910d1c4814da267124d6b633ec4b6ea815b3d0a00c280556ef669e59df09d5ee03d48f76a9c2c5a927d66d51603dffc80330d3adeeef000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005050000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000362c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a35313733222c2263726f73734f726967696e223a66616c73657d0000000000000000000000"},"0x0000000071727De22E5E9d8BAf0edAc6f37da032"]}
[JsonRpcProvider][eth_estimateUserOperationGas][response] {
  "jsonrpc": "2.0",
  "id": 0,
  "result": {
    "preVerificationGas": "0x21ea868",
    "callGasLimit": "0x85bb8",
    "verificationGasLimit": "0xeab91",
    "paymasterVerificationGasLimit": null
  }
}
[JsonRpcProvider][eth_sendUserOperation][request] {"jsonrpc":"2.0","id":0,"method":"eth_sendUserOperation","params":[{"sender":"0x5F890C1952e8952ACFafc829143aeEA5f2a27a5d","nonce":"0x0","callData":"0xe9ae5c5301000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002600000000000000000000000005f890c1952e8952acfafc829143aeea5f2a27a5d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000184d64db8fc00000000000000000000000092c6e5d5ceb3e069abe4b58caae0d850ae40e51c00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000502801e794fd1b9048ec9c97fd34f62bf0488222000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a40fd8377b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000024c4d66de80000000000000000000000005f890c1952e8952acfafc829143aeea5f2a27a5d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000092c6e5d5ceb3e069abe4b58caae0d850ae40e51c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001443f707e6b00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e58000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002aeeb6ac7a9b98fa7a086f725df0cc10c3cbde2d00000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","factory":"0x5eab992e90ce6144df8f218c359bcafa787acd85","factoryData":"0x4d44ac28000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000124cf7a1d770000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0320000000000000000000000005442f6bd07b08f164a616d829dda50eae93f2dae000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a06f0c704a838d013c0dcfcd626e71908f6d7e83e73f49cb4b8086cb066aa1ba34293c23677b07a0f1df6430d796fee487e382b16155d39903b21d7d7c08d52ad749960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630000000000000000000000004d7f573039fddc84fdb28515ba20d75ef6b987ff000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000","callGasLimit":"0x931b0","verificationGasLimit":"0x119aae","preVerificationGas":"0x21ea868","maxFeePerGas":"0x125175","maxPriorityFeePerGas":"0x47868c00","paymasterVerificationGasLimit":"0x0","paymasterPostOpGasLimit":"0x0","signature":"0x5442f6bd07b08f164a616d829dda50eae93f2dae000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040d12e1763053d948c80ff494b5f5b5c58d84dd3a28ceb33d3f00ef275902109ce132d60711a57eb402b5564b73769fe00b9d3112f8e2b95f3fd4b45ffa73acb1d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005050000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a32c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a35313733222c2263726f73734f726967696e223a66616c73652c226f746865725f6b6579735f63616e5f62655f61646465645f68657265223a22646f206e6f7420636f6d7061726520636c69656e74446174614a534f4e20616761696e737420612074656d706c6174652e205365652068747470733a2f2f676f6f2e676c2f796162506578227d000000000000000000000000000000000000000000000000000000000000"},"0x0000000071727De22E5E9d8BAf0edAc6f37da032"]}
[JsonRpcProvider][eth_sendUserOperation][response] {
  "jsonrpc": "2.0",
  "id": 0,
  "result": "0x04838cbbccca629ad6b038e2da91a1969a7f070bf2a1a3d88f7aaac190b5f9fc"
}
ChiHaoLu commented 1 week ago

Besides, the responded PVG from eth_estimateUserOperationGas is very different from the precheck in eth_sendUserOperation. How can I calculate a rational PVG which can make my userOp on-chain but not exceed too much?

dancoombs commented 1 week ago

PVG is charging for L1 DA costs in L2 gas. So if L1 costs are high, but L2 gas is low, then PVG may be a large number. But in terms of absolute cost, it should be similar to any L2 transaction (maybe slightly higher due to due PVG buffers).

dancoombs commented 1 week ago

Besides, the responded PVG from eth_estimateUserOperationGas is very different from the precheck in eth_sendUserOperation.

What do you mean from the precheck?

How can I calculate a rational PVG which can make my userOp on-chain but not exceed too much?

  1. Estimate gas fees
  2. Submit a eth_estimateUserOperationGas with those fees and dummy signature
  3. Apply a buffer on the returned PVG. This buffer is application dependent.
  4. Sign and submit UO. The faster this is done after (2) the better the PVG estimate will be.
ChiHaoLu commented 1 week ago

My question is the precheck from here which occurs in eth_sendUserOperation. Do you know Alchemy Bundler do a precheck in the eth_sendUserOperation?

Error: {
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": -32000,
    "message": "precheck failed: preVerificationGas is 1133120 but must be at least 2490360"
  }
}

You can reproduce this error by:

  1. Estimating an userOp by eth_estimateUserOperationGas and get the bundler suggests PVG (maybe a x value).
  2. Changing the PVG to 0.
  3. Send it to Bundler by eth_sendUserOperation.
  4. You get a precheck error which requires your userOp at least y which is totally different from the x.
dancoombs commented 4 days ago

Yes, I understand what you mean now. The required preVerificationGas value changes on L2s due to changes in fees and a higher value may be required when you submit. The same suggestions from this comment apply https://github.com/alchemyplatform/rundler/issues/908#issuecomment-2468304797