-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 3403: Partial removal of refunds #3403
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4991ec1
EIP 3402: Partial removal of refunds
vbuterin 572c132
Fix EIP number
vbuterin f3587a3
Update EIPS/eip-3403.md
vbuterin 0c48343
Update EIPS/eip-3403.md
vbuterin 6a42591
Update EIPS/eip-3403.md
vbuterin 7a341ea
Update EIPS/eip-3403.md
vbuterin c0dad4c
Update EIP 3403
vbuterin 470cd00
Update EIPS/eip-3403.md
MicahZoltu 8b1c4f7
Update EIPS/eip-3403.md
MicahZoltu 5329182
Update EIPS/eip-3403.md
vbuterin e01be6b
Updated
vbuterin e54b517
SSTORE refund gas value fix
vbuterin 8b5c111
Apply suggestions from code review
vbuterin dcf725b
Some rewording
vbuterin 2652883
Minor fixus to get merged as draft.
MicahZoltu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
eip: 3403 | ||
title: Partial removal of refunds | ||
author: Vitalik Buterin (@vbuterin), Martin Swende (@holiman) | ||
discussions-to: https://ethereum-magicians.org/t/eip-3298-removal-of-refunds/5430 | ||
status: Draft | ||
type: Standards Track | ||
category: Core | ||
created: 2021-03-16 | ||
--- | ||
|
||
## Simple Summary | ||
|
||
Remove gas refunds for SELFDESTRUCT, and restrict gas refunds for SSTORE to one specific case. | ||
|
||
## Motivation | ||
|
||
Gas refunds for SSTORE and SELFDESTRUCT were originally introduced to motivate application developers to write applications that practice "good state hygiene", clearing storage slots and contracts that are no longer needed. However, they are not widely used for this, and poor state hygiene continues to be the norm. It is now widely accepted that the only solution to state growth is some form of statelessness or state expiry, and if such a solution is implemented, then disused storage slots and contracts would start to be ignored automatically. | ||
|
||
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. | ||
|
||
## Specification | ||
|
||
### Parameters | ||
|
||
| Constant | Value | | ||
| - | - | | ||
| `FORK_BLOCK` | TBD | | ||
| `SSTORE_REFUND_GAS` | 15000 | | ||
|
||
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. | ||
MicahZoltu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## 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) | ||
|
||
It also preserves two key goals of EIP 3298: | ||
|
||
1. Gas tokens continue to be non-viable, because each 15000 refund is only possible because of 15000 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. | ||
vbuterin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. The total amount of gas _spent on execution_ is capped at the gas limit. Every 15000 refund for flipping a storage slot non from zero -> zero is only possible because of 15000 extra gas paid for flipping that slot from zero -> nonzero earlier in the same transaction; that gas paid for storage expansion and not execution, and so does not contribute to short-term DoS risk. | ||
vbuterin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Backwards Compatibility | ||
|
||
Refunds are currently only applied _after_ transaction execution, so they cannot affect how much gas is available to any particular call frame during execution. Hence, removing them will not break the ability of any code to execute, though it will render some applications economically nonviable. | ||
|
||
Gas tokens in particular will become valueless. DeFi arbitrage bots, which today frequently use either established gas token schemes or a custom alternative to reduce on-chain costs, would benefit from rewriting their code to remove calls to these no-longer-functional gas storage mechanisms. | ||
|
||
## Implementation | ||
|
||
TBD | ||
|
||
## Test Cases | ||
|
||
### Berlin costs | ||
|
||
With Berlin, and [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929), the gas costs changes. Note, there is a difference between 'hot' and 'cold' slots. | ||
This table show the values assuming that all touched storage slots were already 'hot' (the difference being a one-time cost of 2000 gas). | ||
vbuterin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
| Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | ||
| -- | -- | -- | -- | -- | -- | -- | -- | | ||
| `0x60006000556000600055` | 212 | 0| 0 | 0 | 0 | | 212 | | ||
| `0x60006000556001600055` | 20112 | 0| 0 | 0 | 1 | | 20112 | | ||
| `0x60016000556000600055` | 20112 | 19900| 0 | 1 | 0 | | 212 | | ||
| `0x60016000556002600055` | 20112 | 0| 0 | 1 | 2 | | 20112 | | ||
| `0x60016000556001600055` | 20112 | 0| 0 | 1 | 1 | | 20112 | | ||
| `0x60006000556000600055` | 3012 | 15000| 1 | 0 | 0 | | -11988 | | ||
| `0x60006000556001600055` | 3012 | 2800| 1 | 0 | 1 | | 212 | | ||
| `0x60006000556002600055` | 3012 | 0| 1 | 0 | 2 | | 3012 | | ||
| `0x60026000556000600055` | 3012 | 15000| 1 | 2 | 0 | | -11988 | | ||
| `0x60026000556003600055` | 3012 | 0| 1 | 2 | 3 | | 3012 | | ||
| `0x60026000556001600055` | 3012 | 2800| 1 | 2 | 1 | | 212 | | ||
| `0x60026000556002600055` | 3012 | 0| 1 | 2 | 2 | | 3012 | | ||
| `0x60016000556000600055` | 3012 | 15000| 1 | 1 | 0 | | -11988 | | ||
| `0x60016000556002600055` | 3012 | 0| 1 | 1 | 2 | | 3012 | | ||
| `0x60016000556001600055` | 212 | 0| 1 | 1 | 1 | | 212 | | ||
| `0x600160005560006000556001600055` | 40118 | 19900| 0 | 1 | 0 | 1 | 20218 | | ||
| `0x600060005560016000556000600055` | 5918 | 17800| 1 | 0 | 1 | 0 | -11882 | | ||
|
||
### 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 | ||
MicahZoltu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | ||
| -- | -- | -- | -- | -- | -- | -- | -- | | ||
| `0x60006000556000600055` | 212 | 0| 0 | 0 | 0 | | 212 | | ||
| `0x60006000556001600055` | 20112 | 0| 0 | 0 | 1 | | 20112 | | ||
| `0x60016000556000600055` | 20112 | 15000| 0 | 1 | 0 | | 5112 | | ||
| `0x60016000556002600055` | 20112 | 0| 0 | 1 | 2 | | 20112 | | ||
| `0x60016000556001600055` | 20112 | 0| 0 | 1 | 1 | | 20112 | | ||
| `0x60006000556000600055` | 3012 | 0| 1 | 0 | 0 | | 3012 | | ||
| `0x60006000556001600055` | 3012 | 0| 1 | 0 | 1 | | 3012 | | ||
| `0x60006000556002600055` | 3012 | 0| 1 | 0 | 2 | | 3012 | | ||
| `0x60026000556000600055` | 3012 | 0| 1 | 2 | 0 | | 3012 | | ||
| `0x60026000556003600055` | 3012 | 0| 1 | 2 | 3 | | 3012 | | ||
| `0x60026000556001600055` | 3012 | 0| 1 | 2 | 1 | | 3012 | | ||
| `0x60026000556002600055` | 3012 | 0| 1 | 2 | 2 | | 3012 | | ||
| `0x60016000556000600055` | 3012 | 0| 1 | 1 | 0 | | 3012 | | ||
| `0x60016000556002600055` | 3012 | 0| 1 | 1 | 2 | | 3012 | | ||
| `0x60016000556001600055` | 212 | 0| 1 | 1 | 1 | | 212 | | ||
| `0x600160005560006000556001600055` | 40118 | 15000| 0 | 1 | 0 | 1 | 25118 | | ||
| `0x600060005560016000556000600055` | 5918 | 0| 1 | 0 | 1 | 0 | 5918 | | ||
|
||
## Security Considerations | ||
|
||
TBD | ||
|
||
## Copyright | ||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.