From b82330cf066d4418e062ca0a0b69c73a80ccfc85 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 20:10:17 -0700 Subject: [PATCH 01/12] EXTCLEAR draft --- EIPS/eip-draft-extclear.md | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 EIPS/eip-draft-extclear.md diff --git a/EIPS/eip-draft-extclear.md b/EIPS/eip-draft-extclear.md new file mode 100644 index 00000000000000..7fb759d3388cb4 --- /dev/null +++ b/EIPS/eip-draft-extclear.md @@ -0,0 +1,75 @@ +--- +eip: +title: EXTCLEAR Opcode For SELFDESTRUCTed contracts +author: William Morriss (@wjmelements) +discussions-to: +status: Draft +type: Standards Track +category Core +created: 2020-09-03 +replaces: 2751 +--- + + +`EXTCLEAR` Opcode For `SELFDESTRUCT`ed contracts + +## Simple Summary + +Enable new opcode to clear storage for `SELFDESTRUCTED`ed contracts. + +## Abstract + +`SELFDESTRUCT` complexity can be reduced by deferring state cleanup. + +## Motivation + +`SELFDESTRUCT` is unnecessarily complex because it clears an unbounded amount of state from contract storage. +It is computationally expensive for nodes to track all of the storage used in every contract in case the contract `SELFDESTRUCT`s. +Further, contracts can be re-initialized using `CREATE2`, and then `SLOAD` prior storage. +Therefore, several ethereum clients do not clear storage at all, and just check if the contract was initiated since `SLOAD`. +Nobody expected `SELFDESTRUCT` and `CREATE2` to increase the cost of `SLOAD`. +Also, bugs in this implementation could split the network. + +Instead this defers the time of storage cleanup, and leaves the storage in-place, which reduces the complexity of `SLOAD` and `SELFDESTRUCT`. + +This empowers the `CREATE2` reincarnation proxy pattern by retaining storage during upgrade, which would otherwise have to be reset again. +An atomic reincarnation upgrade could clear a subset of storage during the upgrade, while the contract is destroyed, before reinstating it. + +## Specification + + +After `FORK_BLOCK_NUM`, a new opcode, `EXTCLEAR`, is enabled at `0x5c` to clear storage for `SELFDESTRUCT`ed contracts. +`EXTCLEAR`: +* does not push any words onto the stack +* pops two words off the stack: the destroyed contract address and a storage address +* if the contract exists, charge the same gas cost as `EXTCODEHASH` +* otherwise, if the storage is zero, charge the same gas as `EXTCODEHASH` plus `SLOAD` +* otherwise, the destroyed contract's slot is reset to 0, charging the same gas as `EXTCODEHASH` and `SSTORE` when resetting storage, while also refunding the amount specified in `SSTORE`. + +`SELFDESTRUCT` is modified to not clear contract storage. +This change also works retroactively: all prior destroyed contracts can be cleaned up. + +## Rationale + +`0x5c` is available in the same range as `SSTORE` and `SLOAD`. + +Opcode pricing is compatible with both EIP 2929 and 2200. + +## Backwards Compatibility + +A reincarnation upgrade mechanism that expects all internal storage to be cleared might break, but such an upgrade mechanism would allow adaptation to this new behavior. + +## Test Cases + +TODO + +## Implementation + +Implementation is required on all major clients to add the opcode. + +## Security Considerations + +A reincarnated contract that does not expect its state to be cleared by malicious actors SHOULD reinitialize itself to avoid antagonistic `EXTCLEAR`. + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From c36e1639c826cc5afaeba3bf34ccf5c78ed9630c Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 20:15:10 -0700 Subject: [PATCH 02/12] missing colon --- EIPS/eip-draft-extclear.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft-extclear.md b/EIPS/eip-draft-extclear.md index 7fb759d3388cb4..5f12a3f206d95b 100644 --- a/EIPS/eip-draft-extclear.md +++ b/EIPS/eip-draft-extclear.md @@ -5,7 +5,7 @@ author: William Morriss (@wjmelements) discussions-to: status: Draft type: Standards Track -category Core +category: Core created: 2020-09-03 replaces: 2751 --- From 3cb45733d5ec11f0948bbf363da0949971061043 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 20:21:46 -0700 Subject: [PATCH 03/12] set discussions-to --- EIPS/eip-draft-extclear.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft-extclear.md b/EIPS/eip-draft-extclear.md index 5f12a3f206d95b..eeb9d0ef0fac1a 100644 --- a/EIPS/eip-draft-extclear.md +++ b/EIPS/eip-draft-extclear.md @@ -2,7 +2,7 @@ eip: title: EXTCLEAR Opcode For SELFDESTRUCTed contracts author: William Morriss (@wjmelements) -discussions-to: +discussions-to: https://ethereum-magicians.org/t/eip-2936-extclear-for-selfdestruct/4569 status: Draft type: Standards Track category: Core From a3bdf0ddbfd201922c766eaa48236d026aea2520 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 20:25:24 -0700 Subject: [PATCH 04/12] clarity --- EIPS/eip-draft-extclear.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-draft-extclear.md b/EIPS/eip-draft-extclear.md index eeb9d0ef0fac1a..f7f24d25417f63 100644 --- a/EIPS/eip-draft-extclear.md +++ b/EIPS/eip-draft-extclear.md @@ -23,10 +23,10 @@ Enable new opcode to clear storage for `SELFDESTRUCTED`ed contracts. ## Motivation -`SELFDESTRUCT` is unnecessarily complex because it clears an unbounded amount of state from contract storage. +`SELFDESTRUCT` is unnecessarily complex because it clears an unbounded amount of contract storage. It is computationally expensive for nodes to track all of the storage used in every contract in case the contract `SELFDESTRUCT`s. Further, contracts can be re-initialized using `CREATE2`, and then `SLOAD` prior storage. -Therefore, several ethereum clients do not clear storage at all, and just check if the contract was initiated since `SLOAD`. +Therefore, several ethereum clients do not clear storage at all, and just check if the contract was initiated since `SSTORE` during `SLOAD`. Nobody expected `SELFDESTRUCT` and `CREATE2` to increase the cost of `SLOAD`. Also, bugs in this implementation could split the network. From be83489763340437437badd9872cc014aa93fe0f Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 21:54:14 -0700 Subject: [PATCH 05/12] designate eip 2936 and @lightlient comments --- EIPS/{eip-draft-extclear.md => eip-2936.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename EIPS/{eip-draft-extclear.md => eip-2936.md} (100%) diff --git a/EIPS/eip-draft-extclear.md b/EIPS/eip-2936.md similarity index 100% rename from EIPS/eip-draft-extclear.md rename to EIPS/eip-2936.md From 2c20c9cad9d21ed5f503b28a47c4495860e03485 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 21:56:56 -0700 Subject: [PATCH 06/12] designate eip2936 and @lightclient changes --- EIPS/eip-2936.md | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index f7f24d25417f63..5bf223e665449a 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -1,5 +1,5 @@ --- -eip: +eip: 2936 title: EXTCLEAR Opcode For SELFDESTRUCTed contracts author: William Morriss (@wjmelements) discussions-to: https://ethereum-magicians.org/t/eip-2936-extclear-for-selfdestruct/4569 @@ -10,23 +10,19 @@ created: 2020-09-03 replaces: 2751 --- - `EXTCLEAR` Opcode For `SELFDESTRUCT`ed contracts ## Simple Summary - Enable new opcode to clear storage for `SELFDESTRUCTED`ed contracts. ## Abstract - `SELFDESTRUCT` complexity can be reduced by deferring state cleanup. ## Motivation - -`SELFDESTRUCT` is unnecessarily complex because it clears an unbounded amount of contract storage. +`SELFDESTRUCT` (`0xFF`) is unnecessarily complex because it clears an unbounded amount of contract storage. It is computationally expensive for nodes to track all of the storage used in every contract in case the contract `SELFDESTRUCT`s. -Further, contracts can be re-initialized using `CREATE2`, and then `SLOAD` prior storage. -Therefore, several ethereum clients do not clear storage at all, and just check if the contract was initiated since `SSTORE` during `SLOAD`. +Further, contracts can be re-initialized using `CREATE2` (`0xF5`), and then `SLOAD` (`0x54`) prior storage. +Therefore, several ethereum clients do not clear storage at all, and just check if the contract was initiated since `SSTORE` (`0x55`) during `SLOAD`. Nobody expected `SELFDESTRUCT` and `CREATE2` to increase the cost of `SLOAD`. Also, bugs in this implementation could split the network. @@ -36,13 +32,12 @@ This empowers the `CREATE2` reincarnation proxy pattern by retaining storage dur An atomic reincarnation upgrade could clear a subset of storage during the upgrade, while the contract is destroyed, before reinstating it. ## Specification - -After `FORK_BLOCK_NUM`, a new opcode, `EXTCLEAR`, is enabled at `0x5c` to clear storage for `SELFDESTRUCT`ed contracts. +After `FORK_BLOCK_NUM`, a new opcode, `EXTCLEAR`, is enabled at `0x5C` to clear storage for `SELFDESTRUCT`ed contracts. `EXTCLEAR`: * does not push any words onto the stack * pops two words off the stack: the destroyed contract address and a storage address -* if the contract exists, charge the same gas cost as `EXTCODEHASH` +* if the contract exists, charge the same gas cost as `EXTCODEHASH` (`0x3F`) * otherwise, if the storage is zero, charge the same gas as `EXTCODEHASH` plus `SLOAD` * otherwise, the destroyed contract's slot is reset to 0, charging the same gas as `EXTCODEHASH` and `SSTORE` when resetting storage, while also refunding the amount specified in `SSTORE`. @@ -50,13 +45,11 @@ After `FORK_BLOCK_NUM`, a new opcode, `EXTCLEAR`, is enabled at `0x5c` to clear This change also works retroactively: all prior destroyed contracts can be cleaned up. ## Rationale - `0x5c` is available in the same range as `SSTORE` and `SLOAD`. Opcode pricing is compatible with both EIP 2929 and 2200. ## Backwards Compatibility - A reincarnation upgrade mechanism that expects all internal storage to be cleared might break, but such an upgrade mechanism would allow adaptation to this new behavior. ## Test Cases @@ -64,11 +57,9 @@ A reincarnation upgrade mechanism that expects all internal storage to be cleare TODO ## Implementation - Implementation is required on all major clients to add the opcode. ## Security Considerations - A reincarnated contract that does not expect its state to be cleared by malicious actors SHOULD reinitialize itself to avoid antagonistic `EXTCLEAR`. ## Copyright From c2466816f7f83e2811b3c594484074086a89ab41 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 23:03:16 -0700 Subject: [PATCH 07/12] remove double title Co-authored-by: Micah Zoltu --- EIPS/eip-2936.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index 5bf223e665449a..a914ca130bc61f 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -10,8 +10,6 @@ created: 2020-09-03 replaces: 2751 --- -`EXTCLEAR` Opcode For `SELFDESTRUCT`ed contracts - ## Simple Summary Enable new opcode to clear storage for `SELFDESTRUCTED`ed contracts. From 5adfe7fda533f9457cce8e4c82fedcca4acfaea7 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 23:03:59 -0700 Subject: [PATCH 08/12] abstract in the abstract Co-authored-by: Micah Zoltu --- EIPS/eip-2936.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index a914ca130bc61f..72ff334708ce81 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -14,7 +14,7 @@ replaces: 2751 Enable new opcode to clear storage for `SELFDESTRUCTED`ed contracts. ## Abstract -`SELFDESTRUCT` complexity can be reduced by deferring state cleanup. +Changes `SELFDESTRUCT` (`0xff') to not clear any storage and adds a new `EXTCLEAR` (`0x5c`) opcode that will clear a specific storage slot for a contract that has previously been self destructed. ## Motivation `SELFDESTRUCT` (`0xFF`) is unnecessarily complex because it clears an unbounded amount of contract storage. From 49f41560311ad8a07a162ee1a59190c158b1bd4d Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 23:22:54 -0700 Subject: [PATCH 09/12] fix backtick Co-authored-by: Micah Zoltu --- EIPS/eip-2936.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index 72ff334708ce81..6c99767cb72fca 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -14,7 +14,7 @@ replaces: 2751 Enable new opcode to clear storage for `SELFDESTRUCTED`ed contracts. ## Abstract -Changes `SELFDESTRUCT` (`0xff') to not clear any storage and adds a new `EXTCLEAR` (`0x5c`) opcode that will clear a specific storage slot for a contract that has previously been self destructed. +Changes `SELFDESTRUCT` (`0xff`) to not clear any storage and adds a new `EXTCLEAR` (`0x5c`) opcode that will clear a specific storage slot for a contract that has previously been self destructed. ## Motivation `SELFDESTRUCT` (`0xFF`) is unnecessarily complex because it clears an unbounded amount of contract storage. From 5d079a18a2c77d8685812e1759dce1393e46e6d4 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 3 Sep 2020 23:22:24 -0700 Subject: [PATCH 10/12] being specific --- EIPS/eip-2936.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index 6c99767cb72fca..ee688488ef55d8 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -21,7 +21,7 @@ Changes `SELFDESTRUCT` (`0xff`) to not clear any storage and adds a new `EXTCLEA It is computationally expensive for nodes to track all of the storage used in every contract in case the contract `SELFDESTRUCT`s. Further, contracts can be re-initialized using `CREATE2` (`0xF5`), and then `SLOAD` (`0x54`) prior storage. Therefore, several ethereum clients do not clear storage at all, and just check if the contract was initiated since `SSTORE` (`0x55`) during `SLOAD`. -Nobody expected `SELFDESTRUCT` and `CREATE2` to increase the cost of `SLOAD`. +`CREATE2` was not intended to complicate `SLOAD`, and this change reverts that complexity. Also, bugs in this implementation could split the network. Instead this defers the time of storage cleanup, and leaves the storage in-place, which reduces the complexity of `SLOAD` and `SELFDESTRUCT`. @@ -43,7 +43,7 @@ After `FORK_BLOCK_NUM`, a new opcode, `EXTCLEAR`, is enabled at `0x5C` to clear This change also works retroactively: all prior destroyed contracts can be cleaned up. ## Rationale -`0x5c` is available in the same range as `SSTORE` and `SLOAD`. +`0x5C` is available in the same range as `SSTORE` and `SLOAD`. Opcode pricing is compatible with both EIP 2929 and 2200. From 220d4ee3c1c526e1e219069317e39375d234513b Mon Sep 17 00:00:00 2001 From: William Morriss Date: Fri, 4 Sep 2020 00:07:28 -0700 Subject: [PATCH 11/12] Remove obvious rationale Co-authored-by: Micah Zoltu --- EIPS/eip-2936.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index ee688488ef55d8..23af470d1e743e 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -45,8 +45,6 @@ This change also works retroactively: all prior destroyed contracts can be clean ## Rationale `0x5C` is available in the same range as `SSTORE` and `SLOAD`. -Opcode pricing is compatible with both EIP 2929 and 2200. - ## Backwards Compatibility A reincarnation upgrade mechanism that expects all internal storage to be cleared might break, but such an upgrade mechanism would allow adaptation to this new behavior. From 7b7edf7cc7a31368f950e265fdcd48ddd69454ed Mon Sep 17 00:00:00 2001 From: William Morriss Date: Fri, 4 Sep 2020 00:08:08 -0700 Subject: [PATCH 12/12] rm reference to non-final eip --- EIPS/eip-2936.md | 1 - 1 file changed, 1 deletion(-) diff --git a/EIPS/eip-2936.md b/EIPS/eip-2936.md index 23af470d1e743e..19a122d169c8c7 100644 --- a/EIPS/eip-2936.md +++ b/EIPS/eip-2936.md @@ -7,7 +7,6 @@ status: Draft type: Standards Track category: Core created: 2020-09-03 -replaces: 2751 --- ## Simple Summary