0

As stated here, my current understanding is that an unused gas is refund when the transaction succeeds (otherwise it is fully consumed)

Lately I found an article about some fee mistakes that led to more than 5M$ spending in transaction fees in only two transactions !

Eventually two questions come to my mind:

  1. Why the extra fee (totalFee - consumedGas) was not sent back to the sender? It seems that the miner was able to keep everything.
  2. How is it possible to have a transaction fee of 2.5M$ included compared to the block gas limit?

Thanks

2

1 Answer 1

0

I think you may be mixing up two different concepts: gas price and gas limit. Let's clarify those.

Gas limit

Gas limit is the maximum amount of gas you allow the execution of your transaction to consume. In many cases this can be simply left as a very big number as the leftover gas is (typically) returned. But if you for example don't trust some of the contracts you use then you can limit the amount of gas - that way a malicious/buggy contract can't spend too much of your precious gas.

Both transactions and blocks have a gas limit; you can only influence the gas limit of your transaction. Block gas limit is currently around 10 million and it can be influenced only by miners - it doesn't change often.

The block's gas limit does not care about gas prices, it only restricts the amount of gas used. So it's used to limit the amount of computation, not the total amount of Ethers spent on gas. So if the limit is for example 50 and your transaction uses 40 gas but has a very high gas price, the transaction fits inside a block. The same is true for the transaction's gas limit: it only limits the amount of computations and does not care about gas prices.

Gas price

Gas price is the price you are willing to pay for each unit of gas consumed by the computation of your transaction. The higher this number is the more you have to pay for the same transaction. But the higher the number is the more likely miners are to include your transaction in their next block because miners get to keep this fee themselves. So in your example the sender simply used a very high gas price.

Typically if there is extra gas left at the end of the transaction it is returned to the sender. But if the transaction throws an exception no gas is consumed. Exceptions should be rare. Some more info can be found here: Why does a Solidity throw consume all gas?

4
  • Thanks a lot for the clarification. You mentioned that in the case of M$ transactions the sender put a very high gas price, understood. But we can fairly assume that he also set a high gas limit otherwise the transaction would have thrown "Out of gas" right? Also, these transactions don't exceed the block gas limit ?
    – petherlipo
    Jul 28, 2020 at 7:24
  • I haven't looked at the actual transactions but my guess is that they are simply Ether transfers and not contract calls. Ether transfer costs always 21000 gas so there is no need for a higher gas limit. Or if they were contract calls then yes, he probably used a high enough gas limit. If they had exceeded the block gas limit they would've been refused. Jul 28, 2020 at 7:31
  • Indeed they are simply Ether transfers. But if the gas limit was set to 21000 and the gasPrice really high, with your clarification it makes me say that the gasPrice*nbInstructions would have exceed clearly the gasLimit and then revert the transaction accordingly right?
    – petherlipo
    Jul 28, 2020 at 8:34
  • Edited my answer to clarify how gas price is used in the limiting calculations (spoiler: it's not used). Jul 28, 2020 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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