go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

eth_estimateGas with blobs fails when capped by limited funds

Open nand2 opened this issue 1 year ago • 1 comments

System information

Geth version: 1.14.1-unstable-86a1f0c3-20240502 CL client & version: e.g. [email protected] OS & Version: Ubuntu 23.04 Commit hash : 86a1f0c39494c8f5caddf6bd9fbddd4bdfa944fd

Expected behaviour

When doing an eth_estimateGas call of an eip4844 tx with blobs, with the account holding enough ETH but not too much (not multiple of what is necessary), it should work.

The call includes maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas.

{"jsonrpc":"2.0","id":5,"method":"eth_estimateGas","params":[{"blobVersionedHashes":["0x01728b8444295cdd28e4dde23e352a4dc5aefa1a5a2cfec522fb3fe04af56732"],"blobs":["0x0068656c6c6f20776f726c642066726f6d20657468657265756d20737461746500800000..."],"data":"0xdb93dcef00000000000000000000000000000000....","from":"0x79E374Babb092590eD82f9A7cA5631aEAd710dea","maxFeePerBlobGas":"0xb44997e62","maxFeePerGas":"0x62fc7c875","maxPriorityFeePerGas":"0x3b9aca00","nonce":"0x3","to":"0xbe78dc6a57dfd9f8898C8C8edd5Bc1C9571E391E","value":"0x0"}]}

Actual behaviour

The call fails with Failed with XXX gas: insufficient funds for gas * price + value: address 0x79E374Babb092590eD82f9A7cA5631aEAd710dea have YYY want ZZZ, with XXX looking random and way above the necessary gas, ZZZ being always a bit above YYY.

In the above example, the message was Failed with 2853958 gas: insufficient funds for gas * price + value: address 0x79E374Babb092590eD82f9A7cA5631aEAd710dea have 75833739893214239 want 82177035114105854

Steps to reproduce the behaviour

Calling eth_estimateGas with blobs with the account holding enough ETH, but not too much (not multiple of what is necessary), will trigger the bug.

Reason

I think I have identified the bug. In the gasestimator.go code, when computing the highest gas limit with the account available balance, it does not take into account the gas used to pay for blobs.

It can be seen with the example above : account has 75833739893214239 wei, maxFeePerGas is 26571425909 wei, the code compute an allowance (max gas limit) of 75833739893214239 / 26571425909 = 2853958 gas (which match the error message).

But then it tries to execute the code with a gas fee of 2853958 * 26571425909 + 131072 (blob gas) * 48395550306 (blog gas fee) = 82177035114105854 wei, which match the error message.

A PR will follow shortly.

nand2 avatar May 03 '24 19:05 nand2

Using the attached PR, the bug no longer appears. I'm new to the go-ethereum codebase, so my code may be wrong, please let me know :-)

nand2 avatar May 03 '24 19:05 nand2