eth-infinitism / bundler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`preVerificationGas` calculation seems incorrect

a0ngo opened this issue · comments

commented

Hi,

TL;DR - Calculation of preVerificationGas is incorrect, takes 32 bytes of the packed transaction and considers it as a single word, each word is 4 bytes. This is incorrect after using stackup's bundler since they multiple each byte by 4 instead of each word. Regardless, a word is 2 bytes, not 32, so computation seems off there as well (unless i am missing something).

I've been using this SDK along with stackup's bundler and my uos have been failing because the bundler's preVerificationGas check - here - returns a larger value and results in te uos being failed since we're not providing sufficient value.

Upon checking it further, I think that the issue is within the calcPreVerificationGas.ts file.
You take the length of packed, which is the length in bytes, add 31, and then split it by 32. The result is then multiplied by ov.perUserOpWord.
I might be missing some part of it, but a word is 2 bytes, so generally you'd need to at words add 1 and divide by 2 instead of 32.

Regardless of that, stackup's bundler takes the number of bytes and multiplies it by 4 gas per byte, while with the current code in this sdk, it takes the size of the packed tx in bytes and multiplies it by 4 gas per 32 bytes, which causes txs sent to stackup's bundler to fail since we didn't specify enough gas.

I think that either the code here should be fixed to use the number of bytes in packed instead of the number divide by 32 and multiply that by 4.
Alternatively, divide it for words (2bytes) and then multiply that size by 8 (instead of 4).

The whole change would be in this line, simply remove the addition and division.

Not sure if this is something you're wanting to do since I didn't find a page explaining if there's a uniform interface for the bundler and how to perform the serialization cost computation described in EIP-4337.

Thanks.

we're using the term "word" for a 32-byte EVM word.