From a0ef90d2980f676a7c3c01b12c57836b210a5d98 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 19:54:08 +0000 Subject: [PATCH 01/15] Draft EIP for the REVERT opcode --- EIPS/eip-draft_revert_opcode.md | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 EIPS/eip-draft_revert_opcode.md diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-draft_revert_opcode.md new file mode 100644 index 00000000000000..7e2ed1a58bd3cd --- /dev/null +++ b/EIPS/eip-draft_revert_opcode.md @@ -0,0 +1,47 @@ +## Preamble + + EIP: + Title: REVERT instruction in the Ethereum Virtual Machine + Author: Alex Beregszaszi, Nikolai Mushegian (nikolai@nexusdev.us) + Type: Standard Track + Category: Core + Status: Draft + Created: 2017-02-06 + +## Simple Summary + +The `REVERT` instruction provides a way to stop execution and revert state changes, without consuming all provided gas and with the ability to return a reason. + +## Abstract + +The `REVERT` instruction will stop execution, roll back all state changes done so far and provide a pointer to a memory section, which can be interpreted as an error code or message. While doing so, it will not consume all the remaining gas. + +## Motivation + +Currently this is not possible. There are two practical ways to revert a transaction from within a contract: running out of gas or executing an invalid instruction. Both of these options will consume all remaining gas. Additionally, reverting a transaction means that all changes, including LOGs, are lost and there is no way to convey a reason for aborting a transaction. + +## Specification + +The `REVERT` instruction is introduced at `0xfd`. Execution is aborted and state changes are rolled back. + +It expects two stack items, the top item is the `memory_length` followed by `memory_offset`. Both of these can equal to zero. The cost of the `REVERT` instruction equals to that of the `RETURN` instruction. + +In case there is not enough gas left to cover the cost of `REVERT` or there is a stack underflow, the effect of the `REVERT` instruction will equal to that of a regular out of gas exception. + +The content of the optionally provided memory section is not defined by this EIP, but is a candidate for another Informational EIP. + +## Rationale + +TBD + +## Backwards Compatibility + +This change has no effect on contracts created in the past. + +## Test Cases + +TBA + +## Copyright + +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From bb1368137fd7dfa287ba72b271dc22d46b477cc1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 23 Mar 2017 12:32:13 +0000 Subject: [PATCH 02/15] Assign EIP140 to REVERT --- EIPS/eip-draft_revert_opcode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-draft_revert_opcode.md index 7e2ed1a58bd3cd..5c456551fba51f 100644 --- a/EIPS/eip-draft_revert_opcode.md +++ b/EIPS/eip-draft_revert_opcode.md @@ -1,6 +1,6 @@ ## Preamble - EIP: + EIP: 140 Title: REVERT instruction in the Ethereum Virtual Machine Author: Alex Beregszaszi, Nikolai Mushegian (nikolai@nexusdev.us) Type: Standard Track From f1af1f393ca8af73e45d28f756be0be8071ca876 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 23 Mar 2017 12:43:51 +0000 Subject: [PATCH 03/15] Add test case for REVERT --- EIPS/eip-draft_revert_opcode.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-draft_revert_opcode.md index 5c456551fba51f..aad30fff80c983 100644 --- a/EIPS/eip-draft_revert_opcode.md +++ b/EIPS/eip-draft_revert_opcode.md @@ -40,7 +40,14 @@ This change has no effect on contracts created in the past. ## Test Cases -TBA +``` +6c726576657274656420646174616000557f726576657274206d657373616765000000000000000000000000000000000000600052600e6000fd +``` + +should: +- return `726576657274206d657373616765` as `REVERT` data, +- the storage at key `0x0` should be left as unset and +- use 20024 gas in total. ## Copyright From 729b590308862b084a108f7204e05695e84100f8 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 23 Mar 2017 12:47:05 +0000 Subject: [PATCH 04/15] Swap the stack items for REVERT to be in line with RETURN --- EIPS/eip-draft_revert_opcode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-draft_revert_opcode.md index aad30fff80c983..65a293ab5a753d 100644 --- a/EIPS/eip-draft_revert_opcode.md +++ b/EIPS/eip-draft_revert_opcode.md @@ -24,7 +24,7 @@ Currently this is not possible. There are two practical ways to revert a transac The `REVERT` instruction is introduced at `0xfd`. Execution is aborted and state changes are rolled back. -It expects two stack items, the top item is the `memory_length` followed by `memory_offset`. Both of these can equal to zero. The cost of the `REVERT` instruction equals to that of the `RETURN` instruction. +It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. Both of these can equal to zero. The cost of the `REVERT` instruction equals to that of the `RETURN` instruction. In case there is not enough gas left to cover the cost of `REVERT` or there is a stack underflow, the effect of the `REVERT` instruction will equal to that of a regular out of gas exception. From c7944c477a409cfd1491c3882de9e15660fa5918 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 23 Mar 2017 12:59:21 +0000 Subject: [PATCH 05/15] Remove rationale (it is already explained twice) --- EIPS/eip-draft_revert_opcode.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-draft_revert_opcode.md index 65a293ab5a753d..3312facf58100c 100644 --- a/EIPS/eip-draft_revert_opcode.md +++ b/EIPS/eip-draft_revert_opcode.md @@ -30,10 +30,6 @@ In case there is not enough gas left to cover the cost of `REVERT` or there is a The content of the optionally provided memory section is not defined by this EIP, but is a candidate for another Informational EIP. -## Rationale - -TBD - ## Backwards Compatibility This change has no effect on contracts created in the past. From 4455e2c105910d870aab1c500cb8f0bd447b66b2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 23 Mar 2017 13:01:09 +0000 Subject: [PATCH 06/15] Mention that the execution is considered as failed --- EIPS/eip-draft_revert_opcode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-draft_revert_opcode.md index 3312facf58100c..af5b9fcb764b12 100644 --- a/EIPS/eip-draft_revert_opcode.md +++ b/EIPS/eip-draft_revert_opcode.md @@ -22,7 +22,7 @@ Currently this is not possible. There are two practical ways to revert a transac ## Specification -The `REVERT` instruction is introduced at `0xfd`. Execution is aborted and state changes are rolled back. +The `REVERT` instruction is introduced at `0xfd`. Execution is aborted, considered as failed, and state changes are rolled back. It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. Both of these can equal to zero. The cost of the `REVERT` instruction equals to that of the `RETURN` instruction. From 793f88b6ab748b2ccf9b868ca4e67dbf4aad89c7 Mon Sep 17 00:00:00 2001 From: cdetrio Date: Sun, 23 Apr 2017 16:24:24 +0200 Subject: [PATCH 07/15] Rename eip-draft_revert_opcode.md to eip-140.md --- EIPS/{eip-draft_revert_opcode.md => eip-140.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename EIPS/{eip-draft_revert_opcode.md => eip-140.md} (100%) diff --git a/EIPS/eip-draft_revert_opcode.md b/EIPS/eip-140.md similarity index 100% rename from EIPS/eip-draft_revert_opcode.md rename to EIPS/eip-140.md From efd2333c806b278b29f483bd5d41d9d7060e37a6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 30 Jun 2017 15:21:00 +0200 Subject: [PATCH 08/15] Some clarifications. --- EIPS/eip-140.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index af5b9fcb764b12..e6c0f50f047672 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -22,11 +22,19 @@ Currently this is not possible. There are two practical ways to revert a transac ## Specification -The `REVERT` instruction is introduced at `0xfd`. Execution is aborted, considered as failed, and state changes are rolled back. +The `REVERT` instruction is introduced at `0xfd`. It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. It does not return anything because it stops execution. -It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. Both of these can equal to zero. The cost of the `REVERT` instruction equals to that of the `RETURN` instruction. +The semantics of `REVERT` with respect to memory and memory cost are identical to those of `RETURN`. The sequence of bytes given by `memory_offset` and `memory_length` is called "error message" in the following. -In case there is not enough gas left to cover the cost of `REVERT` or there is a stack underflow, the effect of the `REVERT` instruction will equal to that of a regular out of gas exception. +The effect of `REVERT` is that execution is aborted, considered as failed, and state changes are rolled back. The error message will be available to the caller in the returndata buffer and will also be copied to the output area, i.e. it is handled in the same way as the regular return data is handled. + +The cost of the `REVERT` instruction equals to that of the `RETURN` instruction, i.e. the rollback itself does not consume all gas, the contract only has to pay for memory. + +In case there is not enough gas left to cover the cost of `REVERT` or there is a stack underflow, the effect of the `REVERT` instruction will equal to that of a regular out of gas exception, i.e. it will consume all gas. + +In the same way as all other failures, the calling opcode returns `1` on the stack following a `REVERT` opcode in the callee. + +In case `REVERT` is used in the context of a `CREATE` or `CREATE2` call, no code is deployed, `1` is put on the stack and the error message is available in the returndata buffer. The content of the optionally provided memory section is not defined by this EIP, but is a candidate for another Informational EIP. From 8740170c623aa01805aa99ea5a0edc0320094664 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 31 Jul 2017 13:49:08 +0100 Subject: [PATCH 09/15] REVERT returns 0 in CALL/CREATE --- EIPS/eip-140.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index e6c0f50f047672..048596ca83c2c2 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -32,9 +32,9 @@ The cost of the `REVERT` instruction equals to that of the `RETURN` instruction, In case there is not enough gas left to cover the cost of `REVERT` or there is a stack underflow, the effect of the `REVERT` instruction will equal to that of a regular out of gas exception, i.e. it will consume all gas. -In the same way as all other failures, the calling opcode returns `1` on the stack following a `REVERT` opcode in the callee. +In the same way as all other failures, the calling opcode returns `0` on the stack following a `REVERT` opcode in the callee. -In case `REVERT` is used in the context of a `CREATE` or `CREATE2` call, no code is deployed, `1` is put on the stack and the error message is available in the returndata buffer. +In case `REVERT` is used in the context of a `CREATE` or `CREATE2` call, no code is deployed, `0` is put on the stack and the error message is available in the returndata buffer. The content of the optionally provided memory section is not defined by this EIP, but is a candidate for another Informational EIP. From 5051d0f2977a630a17bbd2e5983491f5b648e0f1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 31 Jul 2017 13:49:46 +0100 Subject: [PATCH 10/15] Mark REVERT as accepted --- EIPS/eip-140.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index 048596ca83c2c2..94e89bd8a1b312 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -5,7 +5,7 @@ Author: Alex Beregszaszi, Nikolai Mushegian (nikolai@nexusdev.us) Type: Standard Track Category: Core - Status: Draft + Status: Accepted Created: 2017-02-06 ## Simple Summary From 3355c0903cb8af2621242c821340197e7a5efe80 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 30 Nov 2017 17:16:14 +0100 Subject: [PATCH 11/15] Limit the backward compatibility https://github.com/ethereum/EIPs/pull/206#discussion_r151943639 --- EIPS/eip-140.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index 94e89bd8a1b312..40f31f61224491 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -40,7 +40,7 @@ The content of the optionally provided memory section is not defined by this EIP ## Backwards Compatibility -This change has no effect on contracts created in the past. +This change has no effect on contracts created in the past unless they contain `0xfd` as an instruction. ## Test Cases From 1d93a80c64b5b78e61786a65eada50dc4d08d9b9 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 30 Nov 2017 17:18:39 +0100 Subject: [PATCH 12/15] Change the status to Final --- EIPS/eip-140.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index 40f31f61224491..b7262a0140ff2e 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -5,7 +5,7 @@ Author: Alex Beregszaszi, Nikolai Mushegian (nikolai@nexusdev.us) Type: Standard Track Category: Core - Status: Accepted + Status: Final Created: 2017-02-06 ## Simple Summary From 8e92d5b2e10fc5a17c901b684332b89514f09f0a Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 30 Nov 2017 17:22:02 +0100 Subject: [PATCH 13/15] Improvements after a week of silence on https://github.com/ethereum/EIPs/pull/206 --- EIPS/eip-140.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index b7262a0140ff2e..e449caf0d1c7cb 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -18,11 +18,11 @@ The `REVERT` instruction will stop execution, roll back all state changes done s ## Motivation -Currently this is not possible. There are two practical ways to revert a transaction from within a contract: running out of gas or executing an invalid instruction. Both of these options will consume all remaining gas. Additionally, reverting a transaction means that all changes, including LOGs, are lost and there is no way to convey a reason for aborting a transaction. +Currently this is not possible. There are two practical ways to revert a transaction from within a contract: running out of gas or executing an invalid instruction. Both of these options will consume all remaining gas. Additionally, reverting an EVM execution means that all changes, including LOGs, are lost and there is no way to convey a reason for aborting an EVM execution. ## Specification -The `REVERT` instruction is introduced at `0xfd`. It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. It does not return anything because it stops execution. +The `REVERT` instruction is introduced at `0xfd`. It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. It does not produce any stack elements because it stops execution. The semantics of `REVERT` with respect to memory and memory cost are identical to those of `RETURN`. The sequence of bytes given by `memory_offset` and `memory_length` is called "error message" in the following. @@ -49,7 +49,7 @@ This change has no effect on contracts created in the past unless they contain ` ``` should: -- return `726576657274206d657373616765` as `REVERT` data, +- return `0x726576657274206d657373616765` as `REVERT` data, - the storage at key `0x0` should be left as unset and - use 20024 gas in total. From bccf7d1a3f942e99bef2541092fb9540238b1e34 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 5 Dec 2017 00:59:18 +0000 Subject: [PATCH 14/15] Simplify the title --- EIPS/eip-140.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index fe897d2dc8bb79..1e205e5fabfc40 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -1,7 +1,7 @@ ## Preamble EIP: 140 - Title: REVERT instruction in the Ethereum Virtual Machine + Title: REVERT instruction Author: Alex Beregszaszi, Nikolai Mushegian (nikolai@nexusdev.us) Type: Standard Track Category: Core From 75121e281a8737f979a969394b4360d4d277c115 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 8 Dec 2017 11:59:47 +0100 Subject: [PATCH 15/15] Update eip-140.md --- EIPS/eip-140.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-140.md b/EIPS/eip-140.md index 1e205e5fabfc40..026e30255ae668 100644 --- a/EIPS/eip-140.md +++ b/EIPS/eip-140.md @@ -22,7 +22,7 @@ Currently this is not possible. There are two practical ways to revert a transac ## Specification -The `REVERT` instruction is introduced at `0xfd`. It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. It does not produce any stack elements because it stops execution. +On blocks with `block.number >= BYZANTIUM_FORK_BLKNUM`, the `REVERT` instruction is introduced at `0xfd`. It expects two stack items, the top item is the `memory_offset` followed by `memory_length`. It does not produce any stack elements because it stops execution. The semantics of `REVERT` with respect to memory and memory cost are identical to those of `RETURN`. The sequence of bytes given by `memory_offset` and `memory_length` is called "error message" in the following. @@ -55,4 +55,4 @@ should: ## Copyright -Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). \ No newline at end of file +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).