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

EIP-1283: Net gas metering for SSTORE without dirty maps #1283

Merged
merged 32 commits into from
Aug 7, 2018
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6e0338f
Net gas metering for SSTORE without dirty maps
sorpaas Aug 1, 2018
f3ee50c
typo: opcode
sorpaas Aug 1, 2018
5f05bc1
Merge branch 'master' of https://github.com/ethereum/EIPs into sp-sst…
sorpaas Aug 1, 2018
8d21d6b
typo: changed
sorpaas Aug 1, 2018
40c9c4e
Self-assign the PR number 1283
sorpaas Aug 1, 2018
6a9400e
Add a dummy discussion url
sorpaas Aug 1, 2018
7074767
Fix R_sclear loopholes
sorpaas Aug 1, 2018
0fca9b3
Properly handle refund for 0 value issue
sorpaas Aug 1, 2018
f859a90
fix: refund should only be added again if new value is 0
sorpaas Aug 1, 2018
6195cd6
clarify if statement
sorpaas Aug 1, 2018
9b5ece7
Clearly state what () means
sorpaas Aug 1, 2018
2d972d1
typo fix: unnecessary wording "additional"
sorpaas Aug 1, 2018
8f9bb86
fix: should have parent clause if original value is not zero
sorpaas Aug 1, 2018
23ebc94
Remove 15k gas from refund counter instead of deduct it as gas cost
sorpaas Aug 2, 2018
30daaa0
Be more clear on EIP-658 enabled only-commit-storage-changes-at-end-o…
sorpaas Aug 2, 2018
598d42e
Move some discussion comments to motivations section
sorpaas Aug 2, 2018
b8f9659
typo: commons -> common
sorpaas Aug 2, 2018
ba8a613
Be more specific when gas reduction won't happen compared with EIP-1087
sorpaas Aug 2, 2018
f0e1590
typo: duplicate description
sorpaas Aug 2, 2018
39505aa
Add explanation section
sorpaas Aug 3, 2018
49b5f22
becomes -> become
sorpaas Aug 3, 2018
0710ff6
typo: covers -> cover
sorpaas Aug 3, 2018
ddfe7ca
Add state transition diagrams
sorpaas Aug 3, 2018
df15cbd
Fix table formatting
sorpaas Aug 3, 2018
ee38de0
typo: 0 -> `current`
sorpaas Aug 3, 2018
8dd32c9
typo: missing -
sorpaas Aug 3, 2018
e5f00a1
Change state transition table to use `(current, original)` vs `new`
sorpaas Aug 6, 2018
7a18e1b
fix: vertical <-> horizontal
sorpaas Aug 6, 2018
d863e66
Be more specific on usages benefited by this EIP
sorpaas Aug 6, 2018
2daf07f
Merge branch 'master' into sp-sstore-no-dirty-map
Arachnid Aug 7, 2018
3125d0e
Typo fix
sorpaas Aug 7, 2018
a9171ac
Merge branch 'sp-sstore-no-dirty-map' of github.com:sorpaas/eips into…
sorpaas Aug 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add explanation section
  • Loading branch information
sorpaas committed Aug 3, 2018
commit 39505aa7e727037660900d218ac1e9e1f5ed4da0
53 changes: 53 additions & 0 deletions EIPS/eip-1283.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,59 @@ the following logic:
Refund counter works as before -- it is limited to half of the gas
consumed.

## Explanation

The new gas cost scheme for SSTORE is divided to three different
types:

* **No-op**: the virtual machine does not need to do anything. This is
the case if *current value* equals *new value*.
* **Fresh**: this storage slot has not been changed, or has been reset
to its original value either on current frame, or on a sub-call
frame for the same contract. This is the case if *current value*
does not equal *new value*, and *original value* equals *current
value*.
* **Dirty**: this storage slot has already been changed, either on
current frame or on a sub-call frame for the same contract. This is
the case if *current value* does not equal *new value*, and
*original value* does not equal *current value*.

We can see that the above three types covers all possible variations
of *original value*, *current value*, and *new value*.

**No-op** is a trivial operation. Below we only consider cases for
**Fresh** and **Dirty**.

All initial (not-**No-op**) SSTORE on a particular storage slot starts
with **Fresh**. After that, it will become **Dirty** if the value has
been changed (either on current call frame or a sub-call frame for the
same contract). When going from **Fresh** to **Dirty**, we charge the
gas cost the same as current scheme.

When entering a sub-call frame, a previously-marked **Dirty** storage
slot will again becomes **Fresh**, but only for this sub-call
frame. Note that we don't charge any more gases compared with current
scheme in this case.

In current call frame, a **Dirty** storage slot can be reset back to
**Fresh** via a SSTORE opcode either on current call frame or a
sub-call frame. For current call frame, this dirtiness is tracked, so
we can issue refunds. For sub-call frame, it is not possible to track
this dirtiness reset, so the refunds (for *current call frame*'s
initial SSTORE from **Fresh** to **Dirty**) are not issued. In the
case where refunds are not issued, the gas cost is the same as the
current scheme.

When a storage slot remains at **Dirty**, we charge 200 gas. In this
case, we would also need to keep track of `R_SCLEAR` refunds -- if we
already issued the refund but it no longer applies (*current value* is
0), then removes this refund from the refund counter. If we didn't
issue the refund but it applies now (*new value* is 0), then adds this
refund to the refund counter. It is not possible where a refund is not
issued but we remove the refund in the above case, because all storage
slot starts with **Fresh** state, either on current call frame or a
sub-call frame.

## Rationale

This EIP mostly archives what EIP-1087 tries to do, but without the
Expand Down