A transactions gasUsed amount is not the same as the amount of gas required for a transaction.
Gas refunds are deducted from the gasUsed amount, but the refunded amount must be available when running the transactions
For some OPCODES (like CALL) 1/64th of the current gasLeft is withheld from the CALL. This has a strange side effect that can cause the CALL (et al) opcode's internal context to run out of gas, even if the transaction itself DOES have enough gas (i.e., gasLeft - gasUsed >= 0).
Since istanbul, some opcodes, under certain circumstances, actually require more gas to run than they actually spend.
The gasLimit of a transaction can cause the transaction's gasUsed as well as the required gas to vary.
@nicholasjpaterno, did I miss any other tricky cases?
Take a look at ganache-core's gas estimation algorithm for implementation details.
Gas estimation is tricky.
gasUsed
amount is not the same as the amount of gas required for a transaction.CALL
) 1/64th of the current gasLeft is withheld from the CALL. This has a strange side effect that can cause theCALL
(et al) opcode's internal context to run out of gas, even if the transaction itself DOES have enough gas (i.e.,gasLeft - gasUsed >= 0
).gasLimit
of a transaction can cause the transaction'sgasUsed
as well as the required gas to vary.@nicholasjpaterno, did I miss any other tricky cases?
Take a look at ganache-core's gas estimation algorithm for implementation details.