Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 11, 2022
1 parent 3a095fa commit ab3a03b
Showing 1 changed file with 103 additions and 70 deletions.
173 changes: 103 additions & 70 deletions docs/storage_change_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

> Analysis of possible storage change statuses in [EIP-2200].
## Specification

1. If *gasleft* is less than or equal to gas stipend, fail the current
call frame with 'out of gas' exception.
2. If *current value* equals *new value* (this is a no-op), `SLOAD_GAS`
is deducted.
3. If *current value* does not equal *new value*
1. If *original value* equals *current value* (this storage slot has
not been changed by the current execution context)
1. If *original value* is 0, `SSTORE_SET_GAS` is deducted.
2. Otherwise, `SSTORE_RESET_GAS` gas is deducted.
1. If *new value* is 0,
add `SSTORE_CLEARS_SCHEDULE` gas to refund counter.
2. If *original value* does not equal *current value* (this storage
slot is dirty), `SLOAD_GAS` gas is deducted. Apply both of the
following clauses.
1. If *original value* is not 0
1. If *current value* is 0 (also means that *new value* is not
0), remove `SSTORE_CLEARS_SCHEDULE` gas from refund
counter.
2. If *new value* is 0 (also means that *current value* is not
0), add `SSTORE_CLEARS_SCHEDULE` gas to refund counter.
2. If *original value* equals *new value* (this storage slot is
reset)
1. If *original value* is 0, add `SSTORE_SET_GAS - SLOAD_GAS` to
refund counter.
2. Otherwise, add `SSTORE_RESET_GAS - SLOAD_GAS` gas to refund
counter.

## Cost constants

| Constant | Value |
Expand All @@ -11,122 +40,126 @@
| RESET | 5000 |
| CLEARS | 15000 |


## Storage change statuses

- `0` - a zero storage value,
- `X` - non-zero storage value,
- `Y` - non-zero storage value different from `X`,
- `Z` - non-zero storage value different form `X` and `Y`,
- `...` - any value.


<table>
<thead>
<tr>
<th>original</th>
<th>current</th>
<th>new</th>
<th>name</th>
<th>o</th>
<th>c</th>
<th>v</th>
<th>dirty?</th>
<th>cost</th>
<th>refund</th>
<th>clause</th>
<th>gas cost</th>
<th>gas refund</th>
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
<td>0</td>
<td>0</td>
<td rowspan="2">UNCHANGED</td>
<td rowspan="2">N/A</td>
<td rowspan="2">800 = SLOAD</td>
<td rowspan="2">0</td>
<td rowspan="7">NOOP</td>
<td>0</td><td>0</td><td>0</td>
<td>no</td>
<td>2</td>
<td rowspan="7">800 = SLOAD</td>
<td rowspan="7">0</td>
</tr>
<tr>
<td>...</td>
<td>X</td>
<td>X</td>
<td>X</td><td>0</td><td>0</td>
<td>yes</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>X</td>
<td>SET / ADDED</td>
<td>no</td>
<td>20000 = SET</td>
<td>0</td>
<td>0</td><td>Y</td><td>Y</td>
<td>yes</td>
<td>2</td>
</tr>
<tr>
<td>X</td>
<td>X</td>
<td>Y</td>
<td>RESET / MODIFIED</td>
<td>no</td>
<td>5000 = RESET</td>
<td>0</td>
<td>X</td><td>Y</td><td>Y</td>
<td>yes</td>
<td>2</td>
</tr>
<tr>
<td>X</td>
<td>X</td>
<td>0</td>
<td>CLEARED / DELETED</td>
<td>Y</td><td>Y</td><td>Y</td>
<td>no</td>
<td>5000 = RESET</td>
<td>15000 = CLEARS</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>X</td>
<td>0</td>
<td>DIRTY_SET_TO_CLEARED</td>
<td>0</td><td>Y</td><td>Z</td>
<td>yes</td>
<td>800 = SLOAD</td>
<td>19200 = SET - SLOAD</td>
<td>3.2</td>
</tr>
<tr>
<td>X</td>
<td>0</td>
<td>X</td>
<td rowspan="2">DIRTY_CLEARED_TO_SET</td>
<td rowspan="2">yes</td>
<td rowspan="2">800 = SLOAD</td>
<td rowspan="2">-15000 = -CLEARS</td>
<td>X</td><td>Y</td><td>Z</td>
<td>yes</td>
<td>3.2</td>
</tr>
<tr>
<td>X</td>
<td>ADDED</td>
<td>0</td><td>0</td><td>Z</td>
<td>no</td>
<td>3.1.1</td>
<td>20000 = SET</td>
<td>0</td>
<td>Y</td>
</tr>
<tr>
<td>DELETED</td>
<td>X</td><td>X</td><td>0</td>
<td>no</td>
<td>3.1.2.1</td>
<td>5000 = RESET</td>
<td>15000 = CLEARS</td>
</tr>
<tr>
<td>MODIFIED</td>
<td>X</td><td>X</td><td>Z</td>
<td>no</td>
<td>3.1.2</td>
<td>5000 = RESET</td>
<td>0</td>
<td>X</td>
<td>Y</td>
<td rowspan="2">DIRTY_RESET_AGAIN</td>
<td rowspan="2">yes</td>
<td rowspan="2">800 = SLOAD</td>
<td rowspan="2">0</td>
</tr>
<tr>
<td>X</td>
<td>Y</td>
<td>Z</td>
<td>deleted added</td>
<td>X</td><td>0</td><td>Z</td>
<td>yes</td>
<td>3.2.1.1</td>
<td>800 = SLOAD</td>
<td>-15000 = -CLEARS</td>
</tr>
<tr>
<td>X</td>
<td>Y</td>
<td>0</td>
<td>DIRTY_RESET_TO_CLEARED</td>
<td>MODIFIED_DELETED</td>
<td>X</td><td>Y</td><td>0</td>
<td>yes</td>
<td>3.2.1.2</td>
<td>800 = SLOAD</td>
<td>15000 = CLEARS</td>
</tr>
<tr>
<td>X</td>
<td>Y</td>
<td>X</td>
<td>DIRTY_RESET_REVERTED</td>
<td>DELETED_RESTORED</td>
<td>X</td><td>0</td><td>X</td>
<td>yes</td>
<td>3.2.1.1 + 3.2.2.2</td>
<td>800 = SLOAD</td>
<td>-15000 = -CLEARS</td>
</tr>
<tr>
<td>ADDED_DELETED</td>
<td>0</td><td>Y</td><td>0</td>
<td>yes</td>
<td>3.2.2.1</td>
<td>800 = SLOAD</td>
<td>19200 = SET - SLOAD</td>
</tr>
<tr>
<td>MODIFIED_RESTORED</td>
<td>X</td><td>Y</td><td>X</td>
<td>yes</td>
<td>3.2.2.2</td>
<td>800 = SLOAD</td>
<td>4200 = RESET - SLOAD</td>
</tr>
Expand Down

0 comments on commit ab3a03b

Please sign in to comment.