Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM: SSTORE/SLOAD gas costs split into processing and storage costs #142

Open
axic opened this issue Aug 29, 2016 · 5 comments

Comments

@axic
Copy link
Member

commented Aug 29, 2016

Overview

Split the specified gas cost of SSTORE and SLOAD to processing and storage cost elements.

Specification

SSTORE to have the following gas costs:

  • processing: 50 gas
  • storage charges:
    • set to non-zero from zero: 19950
    • any other case: 4950
  • storage refunds:
    • set to zero from non-zero (ie. deletion): 15000

i.e. setting to non-zero from zero is a total of 20000, while setting to zero is a refund of 10000. (No change here to current behaviour)

Rationale

Based on the Merkle Patricia Tree Specification, inserts and lookups should be the same complexity.

As SLOAD currently takes 50 gas to load (lookup), we can assume that is the processing cost for traversing the trie. SSTORE should have the same cost for processing.

Making this split now will be beneficial when blockchain rent needs to define the rent figures as opposed to the processing costs.

@axic

This comment has been minimized.

Copy link
Member Author

commented Aug 29, 2016

The figures above are given as a starting point for discussion. The specification on trie complexity might be entirely off and that invalidates the above.

Based on the Yellow Paper, the processing fee is 5000 gas for SSTORE, because:

Gset - 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.
Rsclear - 15000 - Refund given (added into refund counter) when the storage value is set to zero from non-zero.

@chfast

This comment has been minimized.

Copy link
Contributor

commented Sep 8, 2016

-15000 = -15050 + 50

@axic

This comment has been minimized.

Copy link
Member Author

commented Sep 14, 2016

@chfast thanks, updated!

@vbuterin

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2016

The 5000 cost for a value-changing SSTORE is meant to represent the cost to history growth and the Merkle tree recalculations. So it should definitely be much larger than an SLOAD.

@axic

This comment has been minimized.

Copy link
Member Author

commented Oct 13, 2016

@chfast @vbuterin updated description to map the YP 1:1.

Is there a sensible way to split up the 5000 to processing and storage costs?

  • processing: 2000 gas (10x as much as SLOAD in EIP150.1)
  • storage charges:
    • set to non-zero from zero: 18000
    • any other case: 3000
  • storage refunds:
    • set to zero from non-zero (ie. deletion): 15000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.