From e74c17ef87dd77de1357471265c171071eee32bf Mon Sep 17 00:00:00 2001 From: Pandapip1 Date: Tue, 20 Dec 2022 16:25:23 -0500 Subject: [PATCH 01/10] Functional selfdestruct --- EIPS/eip-functional-selfdestruct.md | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 EIPS/eip-functional-selfdestruct.md diff --git a/EIPS/eip-functional-selfdestruct.md b/EIPS/eip-functional-selfdestruct.md new file mode 100644 index 00000000000000..72d3734f9ea22f --- /dev/null +++ b/EIPS/eip-functional-selfdestruct.md @@ -0,0 +1,51 @@ +--- +eip: +title: Functional SELFDESTRUCT +description: Changes SELFDESTRUCT to only cause a finite number of state changes +author: Pandapip1 (@Pandapip1), Alex Beregszaszi (@axic) +discussions-to: +status: Draft +type: Standards Track +category: Core +created: 2022-12-20 +requires: +--- + +## Abstract + +Changes `SELFDESTRUCT` to only cause a finite number of state changes. + +## Motivation + +The `SELFDESTRUCT` instruction has a fixed price, but is unbounded in storage/account changes (it needs to delete all keys). This has been an outstanding concern for some time. + +Furthermore, *Verkle trees* might accounts will be organised differently. Account properties, including storage, would have individual keys. It would not be possible to traverse and find all used keys. This makes `SELFDESTRUCT` very challenging to support in Verkle trees. This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. + +## Specification + +The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119. + +### `SELFDESTRUCT` + +Instead of destroying the contract at the end of the transaction, instead, the following will occur at the end of the transaction in which it is invoked: + +1. The contract's code is set to `0x1`, and its nonce is set to `2^64-1`. +2. Starting at the contract's address plus one, while either that address's code or nonce are not equal to zero, increment it. The contract's `0`th storage slot is set to that address. +3. The contract's balance is transferred, in its entirety, to the address on the top of the stack. +4. The top of the stack is popped. + +## Rationale + +This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. It is a minimal change to the current behaviour, and does not change the gas cost of `SELFDESTRUCT`. + +## Backwards Compatibility + +This EIP requires a protocol upgrade, since it modifies consensus rules. + +## Security Considerations + +None. + +## Copyright + +Copyright and related rights waived via [CC0](../LICENSE.md). From 60ef465759968eaab195ef7c8da0f51afd7c7650 Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:32:04 -0500 Subject: [PATCH 02/10] Assign EIP-6190 --- EIPS/eip-functional-selfdestruct.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-functional-selfdestruct.md b/EIPS/eip-functional-selfdestruct.md index 72d3734f9ea22f..cea696b099f809 100644 --- a/EIPS/eip-functional-selfdestruct.md +++ b/EIPS/eip-functional-selfdestruct.md @@ -1,5 +1,5 @@ --- -eip: +eip: 6190 title: Functional SELFDESTRUCT description: Changes SELFDESTRUCT to only cause a finite number of state changes author: Pandapip1 (@Pandapip1), Alex Beregszaszi (@axic) @@ -8,7 +8,7 @@ status: Draft type: Standards Track category: Core created: 2022-12-20 -requires: +requires: 6189 --- ## Abstract From 0dab63446e6fcfaa9f9fd42215ec459014ffa04a Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:32:57 -0500 Subject: [PATCH 03/10] Rename eip-functional-selfdestruct.md to eip-6190.md --- EIPS/{eip-functional-selfdestruct.md => eip-6190.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename EIPS/{eip-functional-selfdestruct.md => eip-6190.md} (100%) diff --git a/EIPS/eip-functional-selfdestruct.md b/EIPS/eip-6190.md similarity index 100% rename from EIPS/eip-functional-selfdestruct.md rename to EIPS/eip-6190.md From 5523e0ae5f646a2a76a685fa15c4f6c9b56e8c68 Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:37:43 -0500 Subject: [PATCH 04/10] Add discussions url --- EIPS/eip-6190.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index cea696b099f809..06eac67b967d19 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -3,7 +3,7 @@ eip: 6190 title: Functional SELFDESTRUCT description: Changes SELFDESTRUCT to only cause a finite number of state changes author: Pandapip1 (@Pandapip1), Alex Beregszaszi (@axic) -discussions-to: +discussions-to: https://ethereum-magicians.org/t/eip-6190-functional-selfdestruct/12232 status: Draft type: Standards Track category: Core From 842fb6f9cdbec8a3548b493fd6e42068b70a463a Mon Sep 17 00:00:00 2001 From: Pandapip1 Date: Wed, 21 Dec 2022 11:01:57 -0500 Subject: [PATCH 05/10] Add RFC 8174 --- EIPS/eip-6190.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index 06eac67b967d19..43423e244386c7 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -23,7 +23,7 @@ Furthermore, *Verkle trees* might accounts will be organised differently. Accoun ## Specification -The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119. +The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174. ### `SELFDESTRUCT` From a4ac349b404e213af1d8ef5705f92266e573e512 Mon Sep 17 00:00:00 2001 From: Pandapip1 Date: Wed, 21 Dec 2022 11:15:54 -0500 Subject: [PATCH 06/10] Adjust some things to make SELFDESTRUCT work a bit smoother --- EIPS/eip-6190.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index 43423e244386c7..30e6be64a94701 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -8,7 +8,7 @@ status: Draft type: Standards Track category: Core created: 2022-12-20 -requires: 6189 +requires: 2929, 6189 --- ## Abstract @@ -25,18 +25,23 @@ Furthermore, *Verkle trees* might accounts will be organised differently. Accoun The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174. -### `SELFDESTRUCT` +### `SELFDESTRUCT` Behaviour Instead of destroying the contract at the end of the transaction, instead, the following will occur at the end of the transaction in which it is invoked: 1. The contract's code is set to `0x1`, and its nonce is set to `2^64-1`. 2. Starting at the contract's address plus one, while either that address's code or nonce are not equal to zero, increment it. The contract's `0`th storage slot is set to that address. -3. The contract's balance is transferred, in its entirety, to the address on the top of the stack. -4. The top of the stack is popped. +3. If the contract was self-destructed after the call being forwarded by one or more alias contracts, the alias contract's `0`th storage slot is set to the address calculated in step 2. +4. The contract's balance is transferred, in its entirety, to the address on the top of the stack. +5. The top of the stack is popped. + +### Gas Cost of `SELFDESTRUCT` + +The base gas cost of `SELFDESTRUCT` is set to `5000`. The gas cost of `SELFDESTRUCT` is increased by `5000` for each alias contract that forwarded to the contract being self-destructed. Finally, the [EIP-2929](./eip-2929.md) gas cost increase is applied. ## Rationale -This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. It is a minimal change to the current behaviour, and does not change the gas cost of `SELFDESTRUCT`. +This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. It is a minimal change to the current behaviour. ## Backwards Compatibility From c92c987ee027b3006f91ffedbccc946d36b50998 Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Wed, 21 Dec 2022 12:31:00 -0500 Subject: [PATCH 07/10] Make verkle trees expected Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com> --- EIPS/eip-6190.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index 30e6be64a94701..9c596de003fab9 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -19,7 +19,7 @@ Changes `SELFDESTRUCT` to only cause a finite number of state changes. The `SELFDESTRUCT` instruction has a fixed price, but is unbounded in storage/account changes (it needs to delete all keys). This has been an outstanding concern for some time. -Furthermore, *Verkle trees* might accounts will be organised differently. Account properties, including storage, would have individual keys. It would not be possible to traverse and find all used keys. This makes `SELFDESTRUCT` very challenging to support in Verkle trees. This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. +Furthermore, with *Verkle trees* accounts will be organised differently. Account properties, including storage, would have individual keys. It would not be possible to traverse and find all used keys. This makes `SELFDESTRUCT` very challenging to support in Verkle trees. This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. ## Specification From eb98f832c818e28573f2a677749a98979cbfc878 Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Sun, 25 Dec 2022 18:12:58 -0500 Subject: [PATCH 08/10] Add gas cost Rationale --- EIPS/eip-6190.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index 9c596de003fab9..bbfccb3fe8488b 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -41,7 +41,9 @@ The base gas cost of `SELFDESTRUCT` is set to `5000`. The gas cost of `SELFDESTR ## Rationale -This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. It is a minimal change to the current behaviour. +This EIP is designed to be a step towards supporting `SELFDESTRUCT` in Verkle trees while making the minimum amount of changes. + +The `5000` base gas cost and additional alias contracts represents the cost of setting the account nonce and first storage slot. The EIP-2929 gas cost increase is preserved for the reasons mentioned in said EIP's Rationale. ## Backwards Compatibility From 8148d8f4192fb89dc2b6eaf74a2457bddb4189ce Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Sun, 25 Dec 2022 18:16:10 -0500 Subject: [PATCH 09/10] Add proper Rationale --- EIPS/eip-6190.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index bbfccb3fe8488b..70c5cfdb604b01 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -8,7 +8,7 @@ status: Draft type: Standards Track category: Core created: 2022-12-20 -requires: 2929, 6189 +requires: 2929, 6188, 6189 --- ## Abstract @@ -25,6 +25,10 @@ Furthermore, with *Verkle trees* accounts will be organised differently. Account The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174. +### Prerequisites + +[EIP-6188](./eip-6188.md) and [EIP-6189](./eip-6189.md) must be used for this EIP to function correctly. + ### `SELFDESTRUCT` Behaviour Instead of destroying the contract at the end of the transaction, instead, the following will occur at the end of the transaction in which it is invoked: @@ -43,7 +47,9 @@ The base gas cost of `SELFDESTRUCT` is set to `5000`. The gas cost of `SELFDESTR This EIP is designed to be a step towards supporting `SELFDESTRUCT` in Verkle trees while making the minimum amount of changes. -The `5000` base gas cost and additional alias contracts represents the cost of setting the account nonce and first storage slot. The EIP-2929 gas cost increase is preserved for the reasons mentioned in said EIP's Rationale. +The `5000` base gas cost and additional alias contracts represents the cost of setting the account nonce and first storage slot. The [EIP-2929](./eip-2929.md) gas cost increase is preserved for the reasons mentioned in said EIP's Rationale. + +The nonce of `2^64-1` was chosen since it is the nonce protected by [EIP-6188](./eip-6188.md). The account code of `0x1` was chosen since it was the code specified in [EIP-6189](./eip-6189.md). ## Backwards Compatibility From 7ae269ed8b6a7c34321c84f8aa7a23f0a452914f Mon Sep 17 00:00:00 2001 From: Pandapip1 <45835846+Pandapip1@users.noreply.github.com> Date: Sat, 7 Jan 2023 19:36:15 -0500 Subject: [PATCH 10/10] CREATE-based addresses --- EIPS/eip-6190.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-6190.md b/EIPS/eip-6190.md index 70c5cfdb604b01..e8f5aa9bfc46f7 100644 --- a/EIPS/eip-6190.md +++ b/EIPS/eip-6190.md @@ -34,7 +34,7 @@ The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL Instead of destroying the contract at the end of the transaction, instead, the following will occur at the end of the transaction in which it is invoked: 1. The contract's code is set to `0x1`, and its nonce is set to `2^64-1`. -2. Starting at the contract's address plus one, while either that address's code or nonce are not equal to zero, increment it. The contract's `0`th storage slot is set to that address. +2. The contract's `0`th storage slot is set to the address that would be issued if the contract used the `CREATE` opcode (`keccak256(contractAddress, nonce)`). Note that the nonce is always `2^64-1`. 3. If the contract was self-destructed after the call being forwarded by one or more alias contracts, the alias contract's `0`th storage slot is set to the address calculated in step 2. 4. The contract's balance is transferred, in its entirety, to the address on the top of the stack. 5. The top of the stack is popped. @@ -51,13 +51,15 @@ The `5000` base gas cost and additional alias contracts represents the cost of s The nonce of `2^64-1` was chosen since it is the nonce protected by [EIP-6188](./eip-6188.md). The account code of `0x1` was chosen since it was the code specified in [EIP-6189](./eip-6189.md). +The address being the same as the one created by `CREATE` is designed to reduce possible attack vectors by not introducing a new mechanism by which accounts can be created at specific addresses. + ## Backwards Compatibility This EIP requires a protocol upgrade, since it modifies consensus rules. ## Security Considerations -None. +Needs discussion. ## Copyright