-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Update EIP-3403: reopen #9431 (eip-3403) #9673
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
Check warning on line 1 in EIPS/eip-3403.md
|
||
eip: 3403 | ||
title: Partial removal of refunds | ||
author: Vitalik Buterin (@vbuterin), Martin Swende (@holiman) | ||
|
@@ -8,8 +8,8 @@ | |
category: Core | ||
created: 2021-03-16 | ||
--- | ||
|
||
Check warning on line 11 in EIPS/eip-3403.md
|
||
## Simple Summary | ||
Check warning on line 12 in EIPS/eip-3403.md
|
||
|
||
Remove gas refunds for SELFDESTRUCT, and restrict gas refunds for SSTORE to one specific case. | ||
|
||
|
@@ -20,22 +20,22 @@ | |
Gas refunds additionally have multiple harmful consequences: | ||
|
||
* Refunds give rise to GasToken. GasToken has benefits in moving gas space from low-fee periods to high-fee periods, but it also has downsides to the network, particularly in exacerbating state size (as state slots are effectively used as a "battery" to save up gas) and inefficiently clogging blockchain gas usage | ||
* Refunds increase block size variance. The theoretical maximum amount of actual gas consumed in a block is nearly twice the on-paper gas limit (as refunds add gas space for subsequent transactions in a block, though refunds are capped at 50% of a transaction's gas used). This is not fatal, but is still undesirable, especially given that refunds can be used to maintain 2x usage spikes for far longer than EIP 1559 can. | ||
* Refunds increase block size variance. The theoretical maximum amount of actual gas consumed in a block is nearly twice the on-paper gas limit (as refunds add gas space for subsequent transactions in a block, though refunds are capped at 50% of a transaction's gas used). This is not fatal, but is still undesirable, especially given that refunds can be used to maintain 2x usage spikes for far longer than [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) can. | ||
Check warning on line 23 in EIPS/eip-3403.md
|
||
|
||
### The mutex usecase | ||
|
||
There are two typical ways to implement mutexes: '0-1-0' and '1-2-1. Let's see how they differ | ||
|
||
- '0-1-0': | ||
Check failure on line 29 in EIPS/eip-3403.md
|
||
- Istanbul: 1612 | ||
Check failure on line 30 in EIPS/eip-3403.md
|
||
- Berlin: 212 | ||
Check failure on line 31 in EIPS/eip-3403.md
|
||
- NoRefund: 20112 | ||
Check failure on line 32 in EIPS/eip-3403.md
|
||
- EIP-3403: 1112 | ||
- [EIP-3403](https://eips.ethereum.org/EIPS/eip-3403): 1112 | ||
Check failure on line 33 in EIPS/eip-3403.md
|
||
- '1-2-1': | ||
Check failure on line 34 in EIPS/eip-3403.md
|
||
- Istanbul: 1612 | ||
Check failure on line 35 in EIPS/eip-3403.md
|
||
- Berlin: 212 | ||
Check failure on line 36 in EIPS/eip-3403.md
|
||
- NoRefund: 3012 | ||
Check failure on line 37 in EIPS/eip-3403.md
|
||
- EIP-3403: 3012 | ||
- [EIP-3403](https://eips.ethereum.org/EIPS/eip-3403): 3012 | ||
Check failure on line 38 in EIPS/eip-3403.md
|
||
|
||
|
||
**Note**: In reality, there are never a negative gas cost, since the refund is capped at 0.5 * gasUsed. | ||
|
@@ -54,16 +54,16 @@ | |
For blocks where `block.number >= FORK_BLOCK`, the following changes apply. | ||
|
||
1. Remove the `SELFDESTRUCT` refund. | ||
2. Remove the `SSTORE` refund in all cases except for one specific case: if the _new value_ and _original value_ of the storage slot both equal 0 but the _current value_ does not (those terms being defined as in [EIP-1283](https://eips.ethereum.org/EIPS/eip-1283)), refund `SSTORE_REFUND_GAS` gas. | ||
Check warning on line 57 in EIPS/eip-3403.md
|
||
|
||
## Rationale | ||
|
||
Preserving refunds in the `new = original = 0 != current` case ensures that a few key use cases that deserve favorable gas cost treatment continue to receive favorable gas cost treatment, particularly: | ||
|
||
* Anti-reentrancy locks (typically flipped from 0 to 1 right before a child call begins, and then flipped back to 0 when the child call ends) | ||
* ERC20 approve-and-send (the "approved value" goes from zero to nonzero when the token transfer is approved, and then back to zero when the token transfer processes) | ||
Check warning on line 64 in EIPS/eip-3403.md
|
||
|
||
It also preserves two key goals of EIP 3298: | ||
Check warning on line 66 in EIPS/eip-3403.md
|
||
|
||
1. Gas tokens continue to be non-viable, because each 19000 refund is only possible because of 19000 extra gas that was paid for flipping that storage slot from zero to nonzero earlier in the same transaction, so you can't clear some storage slots and use that saved gas to fill others. | ||
2. The total amount of gas _spent on execution_ is capped at the gas limit. Every 19000 refund for flipping a storage slot non from zero -> zero is only possible because of 19000 extra gas paid for flipping that slot from zero -> nonzero earlier in the same transaction; that gas paid for a storage write and expansion that were both reverted and so do not actually need to be applied to the Merkle tree. Hence, this extra gas does not contribute to risk. | ||
|
@@ -102,7 +102,7 @@ | |
|
||
### With EIP-3403 partial refunds | ||
|
||
If refunds were to be partially removed, as specified [here](https://github.com/ethereum/EIPs/pull/3403/), this would be the comparative table. **This table also assumes touched storage slots were already 'hot'**. | ||
Check warning on line 105 in EIPS/eip-3403.md
|
||
|
||
| Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | ||
| -- | -- | -- | -- | -- | -- | -- | -- | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to self refer EIPs