stackup-wallet / stackup-bundler

A fast, reliable, and modular ERC-4337 Bundler written in Go.
https://docs.stackup.sh
GNU General Public License v3.0
226 stars 132 forks source link

Gas Price Suggesting may cause loss to the bundler #342

Open wanliqun opened 1 year ago

wanliqun commented 1 year ago

Before sending a bundle transaction, gas price has to be estimated base on the current network status and max gas price settings of all batch user operations. The current method used is to calculate the average gas price of the entire batch without considering the max available gas limit each user operation may consume. This may cause some loss of gas fee to the bundler.

Let's say, we have three user operations (op0, op1, op2) as a batch, with gas price of (10 Gwei, 20 Gwei, 30 Gwei) and max gas limit of (300k, 200k, 100k) respectively. The estimated gas price from chain rpc is 10 Gwei, so that all user operation can be included in a bundle transaction.

If we don't take gas limit of each user operation into consideration, the suggested gas price for this bundle transaction would be MAX(10 Gwei, (10+20+30)/3 Gwei) = 20Gwei. Assumed the gas estimate is very accurate so that all gas limit of each user opearion is fully consumed, so the bundler would take (100k + 200k + 300k) 20 Gwei = 12000k Gwei gas fee, whereas the prefunded gas fee from all user operations is 300k 10 Gwei + 200k 20 Gwei + 100k 30Gwei = 10000k Gwei. As a result, the bundler would loss an extra of 2000k Gwei gas fee.

hazim-j commented 1 year ago

Hi @wanliqun. Yup, that's a valid point. Thanks for bringing it up. Happy to chat through some possible ideas for a more scalable solution. Gas price for bundler transactions are a challenge. Set it too low and userOps with high gas price may not be getting their ideal inclusion speed. But set it too high and bundler looses even more funds from the UserOps with low gas price.

This current solution was the easiest compromise.