eip | title | author | discussions-to | status | type | category | created | requires |
---|---|---|---|---|---|---|---|---|
2200 |
Rebalance net-metered SSTORE gas cost with consideration of SLOAD gas cost change |
Wei Tang (@sorpaas) |
Draft |
Standards Track |
Core |
2019-07-18 |
1283, 1706, 1884 |
A repricing effort for several trie-size-dependent opcodes are being carried out. This EIP also reprices net-metered SSTORE opcode.
Change the intermediate write and no-op write of SSTORE to always have the same gas cost of SLOAD. Change the refund of resetting after setting for SSTORE to take consideration of gas cost of SLOAD.
Net gas metering for SSTORE was priced according to SLOAD values. For consistency, when SLOAD is repriced, SSTORE should be as well.
Define variables SLOAD_GAS
, SSTORE_SET_GAS
, SSTORE_RESET_GAS
and
SSTORE_CLEARS_SCHEDULE
. The old and new values for those variables are:
SLOAD_GAS
: changed from200
to800
.SSTORE_SET_GAS
:20000
, not changed.SSTORE_RESET_GAS
:5000
, not changed.SSTORE_CLEARS_SCHEDULE
:15000
, not changed.
Change the definition of EIP-1283 using those variables. The new specification, combining EIP-1283 and EIP-1706, will look like below. The terms original value, current value and new value are defined in EIP-1283.
Replace SSTORE opcode gas cost calculation (including refunds) with the following logic:
- If current value equals new value (this is a no-op),
SLOAD_GAS
is deducted. - If current value does not equal new value
- If original value equals current value (this storage slot has
not been changed by the current execution context)
- If original value is 0,
SSTORE_SET_GAS
is deducted. - Otherwise,
SSTORE_RESET_GAS
gas is deducted. If new value is 0, addSSTORE_CLEARS_SCHEDULE
gas to refund counter.
- If original value is 0,
- If original value does not equal current value (this storage
slot is dirty),
SLOAD_GAS
gas is deducted. Apply both of the following clauses.- If original value is not 0
- If current value is 0 (also means that new value is not
0), remove
SSTORE_CLEARS_SCHEDULE
gas from refund counter. We can prove that refund counter will never go below 0. - If new value is 0 (also means that current value is not
0), add
SSTORE_CLEARS_SCHEDULE
gas to refund counter.
- If current value is 0 (also means that new value is not
0), remove
- If original value equals new value (this storage slot is
reset)
- If original value is 0, add
SSTORE_SET_GAS - SLOAD_GAS
to refund counter. - Otherwise, add
SSTORE_RESET_GAS - SLOAD_GAS
gas to refund counter.
- If original value is 0, add
- If original value is not 0
- If original value equals current value (this storage slot has
not been changed by the current execution context)
- If gasleft is less than or equal to 2300, fail the current call frame with 'out of gas' exception.
An implementation should also note EIP-1283's refund counter implementation details, in the Specification section.
The same as EIP-1283's rationale. If EIP-1884 is applied, then SLOAD_GAS
related to SSTORE opcode will also need to be changed.
This EIP has the same backward compatibility property of EIP-1283 and EIP-1706.
To be added.
To be added.
Copyright and related rights waived via CC0.