tevm-monorepo icon indicating copy to clipboard operation
tevm-monorepo copied to clipboard

CallResult.gasUsed doesn't consider the specific cost of each byte in the tx data

Open 0xpolarzero opened this issue 1 year ago • 2 comments

Description

The specific bytes read/written during a transaction use a different amount of gas, whether they are a zero (4 gas) or any non-zero (16 gas) value.

See these transactions (1 and 2), with a difference of exactly 50 bytes (zero => non-zero), which represent a difference of 600 gas (50 * (16-4)).

This difference in gas used in not caught in the Tevm environment, as both transactions would return the exact same amount of gas used. For reference, this is actually the same behavior as Forge (as of 2024-02-17).

See this example with the same transactions as above.

This should not be mistaken with writing a state from zero to non-zero; it does consider the overhead in such a case, e.g. sending an ERC20 token to an account with a 0 balance vs. with a > 0 balance.

0xpolarzero avatar Feb 17 '24 20:02 0xpolarzero