I notice the gas table states:

((value != 0) && (storage_location == 0)) ? 20000 : 5000

for SSTORE. What does it mean by storage_location?


((value != 0) && (storage_location == 0)) ? 20000 : 5000

This is basically saying that it costs 20,000 gas to set any given storage location - i.e. storage slot - from 0 to value, and 5,000 gas to change its value thereafter.

So storage_location in the above will mean whichever slot in the storage we are considering.

e.g. If we are considering slot number 5 in storage, then in the above pseudo-code storage_location will be set to 5, and we are checking whether its current value is 0.

Appendix G in the Yellow Paper puts it thusly:

Gsset   20000  Paid for an SSTORE operation when the storage value is set to non-zero from zero.
Gsreset 5000   Paid for an SSTORE operation when the storage value’s zeroness remains unchanged or
is set to zero
  • So, the gas cost of update operation is 5000, right? – chenzhongpu Apr 16 at 9:40
  • That's correct, yes. – Richard Horrocks Apr 16 at 10:22

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.