1

We have 2 identical transactions, one spends 22409, and the other 37345 gas, why so?

https://etherscan.io/tx/0xaeefbb8aab4fd61fc057b4013f8ca2accd4ed573ec4dcfacc02a1bcfb99cb3f8

https://etherscan.io/tx/0x42071ede01368cd04c621ccbc2197da91302a54da320ee03147bd86e3742cb02

2

The difference of ~15,000 makes me believe the difference is in the balances before hand. A SSTORE operation (change to a storage slot) in the EVM has different costs based on the value pre-execution and post-execution. If the pre-value is 0 and the post-value is non-zero, it costs 20k. If the pre-value is non-0, and the post-value is 0 it costs 5k and a 15k refund is added to the refund balance. If the pre-value is non-0 and the post-value is non-0, it costs 5k.

The transaction that cost ~22k is likely one where the sender and receiver have non-0 balances before, and the sender has a 0 balance after. So there is a 5k+5k charge for updating both balances, and a 15k refund for the zeroing of the sender balance.

The transaction that cost ~37k is likely one where both have a non-zero pre and post balance.

EDIT: You can actually see these to be accurate if you click the State Changes tab on the transactions on Etherscan.

  • 1
    Thank you! I missed the fact that the balance of the sender becomes 0, and geth debug trace on etherscan does not display refunds. – AleXau Apr 3 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.