From 4991ec1a0034e95257412d955e7bc0001a7745d7 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Tue, 16 Mar 2021 13:34:46 -0600 Subject: [PATCH 01/15] EIP 3402: Partial removal of refunds --- EIPS/eip-3402.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 EIPS/eip-3402.md diff --git a/EIPS/eip-3402.md b/EIPS/eip-3402.md new file mode 100644 index 00000000000000..5cc9c11ad6d12b --- /dev/null +++ b/EIPS/eip-3402.md @@ -0,0 +1,69 @@ +--- +eip: 3402 +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](https://hackmd.io/@HWeNw8hNRimMm2m2GH56Cw/state_size_management), 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](https://gastoken.io/). 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](https://notes.ethereum.org/@vbuterin/eip_1559_spikes), 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 | + +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 _new value_ and _original value_ both equal 0 but _current value_ does not, refund 15000 gas. + +## Rationale + +Preserving the one case `new = orig = 0 != current` 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. +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. + +## 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. + +[GasToken](https://gastoken.io/) in particular will become valueless. DeFi arbitrage bots, which today frequently use either established GasToken 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 case changes + +TBD + +## Security Considerations + +TBD + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From 572c132e0c71c3bc3e553e0a49ac8baca5f16cfe Mon Sep 17 00:00:00 2001 From: vbuterin Date: Tue, 16 Mar 2021 13:35:40 -0600 Subject: [PATCH 02/15] Fix EIP number --- EIPS/{eip-3402.md => eip-3403.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename EIPS/{eip-3402.md => eip-3403.md} (99%) diff --git a/EIPS/eip-3402.md b/EIPS/eip-3403.md similarity index 99% rename from EIPS/eip-3402.md rename to EIPS/eip-3403.md index 5cc9c11ad6d12b..078a560ed20d74 100644 --- a/EIPS/eip-3402.md +++ b/EIPS/eip-3403.md @@ -1,5 +1,5 @@ --- -eip: 3402 +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 From f3587a32249ccef542c26a1f328269bc4467828a Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 19 Mar 2021 11:41:55 -0600 Subject: [PATCH 03/15] Update EIPS/eip-3403.md Co-authored-by: Micah Zoltu --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 078a560ed20d74..7fe773d06caebf 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -19,7 +19,7 @@ Gas refunds for SSTORE and SELFDESTRUCT were originally introduced to motivate a Gas refunds additionally have multiple harmful consequences: -* Refunds give rise to [GasToken](https://gastoken.io/). 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 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](https://notes.ethereum.org/@vbuterin/eip_1559_spikes), but is still undesirable, especially given that refunds can be used to maintain 2x usage spikes for far longer than EIP 1559 can. ## Specification From 0c48343a174fe4543f58ef63ea4a70613059fd7b Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 19 Mar 2021 11:42:00 -0600 Subject: [PATCH 04/15] Update EIPS/eip-3403.md Co-authored-by: Micah Zoltu --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 7fe773d06caebf..f1a59bf042e1c0 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -15,7 +15,7 @@ Remove gas refunds for SELFDESTRUCT, and restrict gas refunds for SSTORE to one ## 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](https://hackmd.io/@HWeNw8hNRimMm2m2GH56Cw/state_size_management), and if such a solution is implemented, then disused storage slots and contracts would start to be ignored automatically. +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: From 6a42591e4a439330c8ffa0a1cd30b2ab8233727f Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 19 Mar 2021 11:42:24 -0600 Subject: [PATCH 05/15] Update EIPS/eip-3403.md Co-authored-by: Micah Zoltu --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index f1a59bf042e1c0..0b20b5ca4ae620 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -51,7 +51,7 @@ It also preserves two key goals of EIP 3298: 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. -[GasToken](https://gastoken.io/) in particular will become valueless. DeFi arbitrage bots, which today frequently use either established GasToken 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. +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 From 7a341ea73477cf3a3770ba204c3546772e9caf5b Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 19 Mar 2021 11:42:29 -0600 Subject: [PATCH 06/15] Update EIPS/eip-3403.md Co-authored-by: Micah Zoltu --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 0b20b5ca4ae620..ee66a3aab320a0 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -57,7 +57,7 @@ Gas tokens in particular will become valueless. DeFi arbitrage bots, which today TBD -## Test case changes +## Test Cases TBD From c0dad4c4026b2b5b0ba4e5c0ab12869a0b111087 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 19 Mar 2021 11:56:30 -0600 Subject: [PATCH 07/15] Update EIP 3403 --- EIPS/eip-3403.md | 55 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index ee66a3aab320a0..f8e36837090d02 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -20,7 +20,7 @@ Gas refunds for SSTORE and SELFDESTRUCT were originally introduced to motivate a 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](https://notes.ethereum.org/@vbuterin/eip_1559_spikes), 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 can. ## Specification @@ -29,15 +29,16 @@ Gas refunds additionally have multiple harmful consequences: | 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 _new value_ and _original value_ both equal 0 but _current value_ does not, refund 15000 gas. +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. ## Rationale -Preserving the one case `new = orig = 0 != current` ensures that a few key use cases that deserve favorable gas cost treatment continue to receive favorable gas cost treatment, particularly: +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) @@ -59,7 +60,53 @@ TBD ## Test Cases -TBD +### 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). + +| 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 +| 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 From 470cd00c921fea0558ac279ec5bf93dd13760b5d Mon Sep 17 00:00:00 2001 From: Micah Zoltu Date: Sat, 20 Mar 2021 21:37:35 +0800 Subject: [PATCH 08/15] Update EIPS/eip-3403.md --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index f8e36837090d02..3ddab50a41aa3c 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -34,7 +34,7 @@ Gas refunds additionally have multiple harmful consequences: 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. +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. ## Rationale From 8b1c4f7be8580bff9da11c6b099201b72f57fe3f Mon Sep 17 00:00:00 2001 From: Micah Zoltu Date: Sat, 20 Mar 2021 21:37:49 +0800 Subject: [PATCH 09/15] Update EIPS/eip-3403.md --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 3ddab50a41aa3c..d185666cae8b77 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -87,7 +87,7 @@ This table show the values assuming that all touched storage slots were already ### 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 +If refunds were to be partially removed, as specified here, this would be the comparative table | Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | -- | -- | -- | -- | -- | -- | -- | -- | | `0x60006000556000600055` | 212 | 0| 0 | 0 | 0 | | 212 | From 532918261fd6e31c70d25f555425326fe068917e Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sat, 20 Mar 2021 13:48:25 -0600 Subject: [PATCH 10/15] Update EIPS/eip-3403.md Co-authored-by: Micah Zoltu --- EIPS/eip-3403.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index d185666cae8b77..bafd4777686a71 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -60,10 +60,10 @@ TBD ## Test Cases -### Berlin costs +### 2929 Gas 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). +Note, there is a difference between 'hot' and 'cold' slots. +This table shows the values as of [EIP-2929](./eip-2929.md) assuming that all touched storage slots were already 'hot' (the difference being a one-time cost of 2000 gas). | Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | -- | -- | -- | -- | -- | -- | -- | -- | From e01be6bcdea879937f5c4f80e0c5e2d84460f67d Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sat, 20 Mar 2021 15:26:45 -0600 Subject: [PATCH 11/15] Updated --- EIPS/eip-3403.md | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index bafd4777686a71..1411392eda1636 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -56,14 +56,13 @@ Gas tokens in particular will become valueless. DeFi arbitrage bots, which today ## Implementation -TBD +See https://github.com/ethereum/go-ethereum/pull/22539 ## Test Cases ### 2929 Gas Costs -Note, there is a difference between 'hot' and 'cold' slots. -This table shows the values as of [EIP-2929](./eip-2929.md) assuming that all touched storage slots were already 'hot' (the difference being a one-time cost of 2000 gas). +Note, there is a difference between 'hot' and 'cold' slots. This table shows the values as of [EIP-2929](./eip-2929.md) assuming that all touched storage slots were already 'hot' (the difference being a one-time cost of 2000 gas). | Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | -- | -- | -- | -- | -- | -- | -- | -- | @@ -87,12 +86,13 @@ This table shows the values as of [EIP-2929](./eip-2929.md) assuming that all to ### With EIP-3403 partial refunds -If refunds were to be partially removed, as specified here, this would be the comparative table +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'**. + | 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 | +| `0x60016000556000600055` | 20112 | 19000| 0 | 1 | 0 | | 1112 | | `0x60016000556002600055` | 20112 | 0| 0 | 1 | 2 | | 20112 | | `0x60016000556001600055` | 20112 | 0| 0 | 1 | 1 | | 20112 | | `0x60006000556000600055` | 3012 | 0| 1 | 0 | 0 | | 3012 | @@ -105,12 +105,34 @@ If refunds were to be partially removed, as specified here, this would be the co | `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 | +| `0x600160005560006000556001600055` | 40118 | 19000| 0 | 1 | 0 | 1 | 21118 | | `0x600060005560016000556000600055` | 5918 | 0| 1 | 0 | 1 | 0 | 5918 | +## 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': + - Istanbul: 1612 + - Berlin: 212 + - NoRefund: 20112 + - EIP-3403: 1112 +- '1-2-1': + - Istanbul: 1612 + - Berlin: 212 + - NoRefund: 3012 + - EIP-3403: 3012 + + +**Note**: In reality, there are never a negative gas cost, since the refund is capped at 0.5 * gasUsed. +However, these tables show the negative values, since in a more real-world scenario would likely spend the +extra gas on other operations.' + ## Security Considerations -TBD +Refunds are not visible to transaction execution, so this should not have any impact on transaction execution logic. + +The maximum amount of gas that can be spent on execution in a block is limited to the gas limit, if we do not count zero-to-nonzero SSTOREs that were later reset back to zero. It is okay to not count those, because if such an SSTORE is reset, storage is not expanded and the client does not need to actually adjust the Merke tree; the gas consumption is refunded, but the effort normally required by the client to process those opcodes is also cancelled. **Clients should make sure to not do a storage write if `new_value = original_value`; this was a prudent optimization since the beginning of Ethereum but it becomes more important now.** ## Copyright Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From e54b517cf7356e86446b75f3b96e5402184796d7 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sat, 20 Mar 2021 15:28:57 -0600 Subject: [PATCH 12/15] SSTORE refund gas value fix --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 1411392eda1636..84023676b99d31 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -29,7 +29,7 @@ Gas refunds additionally have multiple harmful consequences: | Constant | Value | | - | - | | `FORK_BLOCK` | TBD | -| `SSTORE_REFUND_GAS` | 15000 | +| `SSTORE_REFUND_GAS` | 19000 | For blocks where `block.number >= FORK_BLOCK`, the following changes apply. From 8b5c111b719e049e4b7f7c4e2adced81b233ccee Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sat, 20 Mar 2021 15:34:19 -0600 Subject: [PATCH 13/15] Apply suggestions from code review Co-authored-by: Martin Holst Swende --- EIPS/eip-3403.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 84023676b99d31..498c03f22e9702 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -45,8 +45,8 @@ Preserving refunds in the `new = original = 0 != current` case ensures that a fe 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. -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. +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 storage expansion and not execution, and so does not contribute to short-term DoS risk. ## Backwards Compatibility @@ -62,7 +62,7 @@ See https://github.com/ethereum/go-ethereum/pull/22539 ### 2929 Gas Costs -Note, there is a difference between 'hot' and 'cold' slots. This table shows the values as of [EIP-2929](./eip-2929.md) assuming that all touched storage slots were already 'hot' (the difference being a one-time cost of 2000 gas). +Note, there is a difference between 'hot' and 'cold' slots. This table shows the values as of [EIP-2929](./eip-2929.md) assuming that all touched storage slots were already 'hot' (the difference being a one-time cost of `2100` gas). | Code | Used Gas | Refund | Original | 1st | 2nd | 3rd | Effective gas (after refund) | -- | -- | -- | -- | -- | -- | -- | -- | @@ -125,7 +125,7 @@ There are two typical ways to implement mutexes: '0-1-0' and '1-2-1. Let's see h **Note**: In reality, there are never a negative gas cost, since the refund is capped at 0.5 * gasUsed. -However, these tables show the negative values, since in a more real-world scenario would likely spend the +However, these tables show the negative values, since a more real-world scenario would likely spend the extra gas on other operations.' ## Security Considerations From dcf725ba93552be3f87d62d41d48c3cd8d42ac93 Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sat, 20 Mar 2021 15:35:47 -0600 Subject: [PATCH 14/15] Some rewording --- EIPS/eip-3403.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index 498c03f22e9702..f5df2b3682545e 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -46,7 +46,7 @@ Preserving refunds in the `new = original = 0 != current` case ensures that a fe It also preserves two key goals of EIP 3298: 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 storage expansion and not execution, and so does not contribute to short-term DoS risk. +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. ## Backwards Compatibility From 265288313b2666748e278fa3a6c4c3abc7260df3 Mon Sep 17 00:00:00 2001 From: Micah Zoltu Date: Sun, 21 Mar 2021 20:25:06 +0800 Subject: [PATCH 15/15] Minor fixus to get merged as draft. --- EIPS/eip-3403.md | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/EIPS/eip-3403.md b/EIPS/eip-3403.md index f5df2b3682545e..8684051733bf06 100644 --- a/EIPS/eip-3403.md +++ b/EIPS/eip-3403.md @@ -22,6 +22,26 @@ 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. +### 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': + - Istanbul: 1612 + - Berlin: 212 + - NoRefund: 20112 + - EIP-3403: 1112 +- '1-2-1': + - Istanbul: 1612 + - Berlin: 212 + - NoRefund: 3012 + - EIP-3403: 3012 + + +**Note**: In reality, there are never a negative gas cost, since the refund is capped at 0.5 * gasUsed. +However, these tables show the negative values, since a more real-world scenario would likely spend the +extra gas on other operations.' + ## Specification ### Parameters @@ -54,10 +74,6 @@ Refunds are currently only applied _after_ transaction execution, so they cannot 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 - -See https://github.com/ethereum/go-ethereum/pull/22539 - ## Test Cases ### 2929 Gas Costs @@ -108,26 +124,6 @@ If refunds were to be partially removed, as specified [here](https://github.com/ | `0x600160005560006000556001600055` | 40118 | 19000| 0 | 1 | 0 | 1 | 21118 | | `0x600060005560016000556000600055` | 5918 | 0| 1 | 0 | 1 | 0 | 5918 | -## 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': - - Istanbul: 1612 - - Berlin: 212 - - NoRefund: 20112 - - EIP-3403: 1112 -- '1-2-1': - - Istanbul: 1612 - - Berlin: 212 - - NoRefund: 3012 - - EIP-3403: 3012 - - -**Note**: In reality, there are never a negative gas cost, since the refund is capped at 0.5 * gasUsed. -However, these tables show the negative values, since a more real-world scenario would likely spend the -extra gas on other operations.' - ## Security Considerations Refunds are not visible to transaction execution, so this should not have any impact on transaction execution logic.