How can I compute the gas consumed in order to be sure that the miner does not cheat on gas used?

Moreover, I don't understand how gas consume is computed, e.g. why writing to a storage variable with value 0 can cost more gas than if it was non-zero?

1 Answer 1


Miners can't cheat because if they did, their blocks would be invalid. Normally you would leave your Ethereum node to check this for you automatically, but it can also be confirmed manually by tracing each step in transaction and checking the gas cost of each operation against the gas schedule specified in the yellowpaper, multiplied by the gas price set by the transaction.

Writing a zero value should always cost the same as writing a positive value, and also result in a gas refund if the value was previously non-zero. If you're seeing some specific behaviour that doesn't follow that principle, try posting an explanation of where you're seeing it. (Probably better as a new question, as Stack Exchange works best if you ask one question at a time.)

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.