From 0185e13541d7bafe663ef5386b21fda69292f974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 9 May 2019 15:04:11 +0200 Subject: [PATCH 01/19] Draft of "EVMC modules for implementations of precompiled contracts" --- EIPS/eip-evmc-precompiles.md | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 EIPS/eip-evmc-precompiles.md diff --git a/EIPS/eip-evmc-precompiles.md b/EIPS/eip-evmc-precompiles.md new file mode 100644 index 00000000000000..5839d7244ac9f9 --- /dev/null +++ b/EIPS/eip-evmc-precompiles.md @@ -0,0 +1,108 @@ +--- +eip: XXXX DO NOT MERGE +title: EVMC modules for implementations of precompiled contracts +author: Paweł Bylica (@chfast) +discussions-to: HERE +status: Draft +type: Informational +created: 2019-05-09 +--- + +## Abstract + +[EVMC] specifies generic API for Ethereum execution engines. +This EIP specifies a way of providing implementations of Ethereum precompiled contracts +as a degenerated EVM implementations using [EVMC VM API]. + + +## Specification + +The EVMC module with implementations of precompiled contracts SHOULD: + +1. Advertise the [`EVMC_CAPABILITY_PRECOMPILES`] capability + in the [`get_capabilities()`] method. +2. Implement the [`execute()`] method in the following way: + 1. Check if the call destination address ([`evmc_message::destination`]) + is within the range of precompiled contracts defined by [EIP-1352]. + If not, abort execution with the [`EVMC_REJECTED`] status code. + 2. Check if the call destination address ([`evmc_message::destination`]) + targets existing precompiled contract. + Consider the EVM revision ([`evmc_revision`]) requested by + the `rev` parameter of [`execute()`]. + If yes, execute as follows: + 1. Inspect the input data ([`evmc_message::input_data`], [`evmc_message::input_size`]) + and calculate the _gas cost_ of the execution. + 2. Compute the amount of _gas left_ after execution by + subtracting the _gas cost_ from the call gas limit ([`evmc_message::gas`]). + 3. If _gas left_ is negative, + abort execution with the [`EVMC_OUT_OF_GAS`] status code. + 4. Otherwise, + execute the code of the precompiled contract, + return the [`EVMC_SUCCESS`] status code, the output and _gas left_ + ([`evmc_result::output_data`], [`evmc_result::output_size`], [`evmc_result::gas_left`]). + 3. Otherwise, emulate execution of empty code by returning + the [`EVMC_SUCCESS`] status code + and _gas left_ equal the call gas limit ([`evmc_message::gas`]). + + +## Rationale + +TODO + + +## Test Cases + +EVMC provides the [evmc-vmtester] tool for checking compatibility with EVMC specification. + + +## Implementations + +- [Example of Precompiles VM implementation][example_precompiles_vm.cpp] +- ewasm/precompiles +- Aleth code for precompiles +- Parity code for precompiles +- Other EVMC VMs? + + +## Copyright + +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). + + +## References + +- [EVMC – Ethereum Client-VM Connector API][EVMC] +- [EVMC documentation] +- [EVMC VM Implementation Guide][EVMC VM API] +- [EIP 1352: Specify restricted address range for precompiles/system contracts][EIP-1352] + + +## TODO + +- What if message::kind is CREATE? +- What if message contains code? +- Add code snippets from the example? +- Links to EVMC repo are not pinned to particular commit. Probably should be pinned to v6.3.0 later on. + + +[EIP-1352]: https://eips.ethereum.org/EIPS/eip-1352 +[EVMC]: https://github.com/ethereum/evmc +[EVMC documentation]: https://ethereum.github.io/evmc/ +[EVMC VM API]: https://ethereum.github.io/evmc/vmguide.html +[evmc-vmtester]: https://ethereum.github.io/evmc/vmtester.html +[example_precompiles_vm.cpp]: https://github.com/ethereum/evmc/blob/master/examples/example_precompiles_vm/example_precompiles_vm.cpp + +[`EVMC_CAPABILITY_PRECOMPILES`]: https://ethereum.github.io/evmc/group__EVMC.html#gga44f9ecb88cf6422a0072936494fd6ac7a43ea2aa7b099a2d67bc53c118ff3683d +[`EVMC_REJECTED`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a2f3e0d8777f8d974ead27ae2a6eb2005 +[`EVMC_OUT_OF_GAS`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920abfc47f75656c996c0b29c0553c00fc18 +[`EVMC_SUCCESS`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a4bc3069fec2bab2a55355a72b7db68b7 +[`execute()`]: https://ethereum.github.io/evmc/structevmc__instance.html#a0823ebff21f9b0395b157e8c6b14a207 +[`get_capabilities()`]: https://ethereum.github.io/evmc/structevmc__instance.html#ae63b9ca898aa41cbd1e2fe86ca8f4e1c +[`evmc_message::destination`]: https://ethereum.github.io/evmc/structevmc__message.html#a88ecfaa03a85a31c6da36fa043b98cea +[`evmc_message::input_data`]: https://ethereum.github.io/evmc/structevmc__message.html#a1adee3454b105eb29cd659ee0cf65c77 +[`evmc_message::input_size`]: https://ethereum.github.io/evmc/structevmc__message.html#a2cf1deebd0dbbb20f25ecdfa299f4b5d +[`evmc_message::gas`]: https://ethereum.github.io/evmc/structevmc__message.html#ae8deff46588584fa27890e74c82db5e7 +[`evmc_result::gas_left`]: https://ethereum.github.io/evmc/structevmc__result.html#af8478c93dbcc3cb2876037c5a5afd4c0 +[`evmc_result::output_data`]: https://ethereum.github.io/evmc/structevmc__result.html#a61978e85f9d795a7b9695b9cbf1748d6 +[`evmc_result::output_size`]: https://ethereum.github.io/evmc/structevmc__result.html#a93bb7419aff492cdef754421c6d74e26 +[`evmc_revision`]: https://ethereum.github.io/evmc/group__EVMC.html#gae5759b1590071966ccf6a505b52a0ef7 From f08d054dd47652962c784d035fb9979b64ca2a04 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 May 2019 15:39:39 +0100 Subject: [PATCH 02/19] Rename and use EIP-2003 --- EIPS/{eip-evmc-precompiles.md => eip-2003.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename EIPS/{eip-evmc-precompiles.md => eip-2003.md} (99%) diff --git a/EIPS/eip-evmc-precompiles.md b/EIPS/eip-2003.md similarity index 99% rename from EIPS/eip-evmc-precompiles.md rename to EIPS/eip-2003.md index 5839d7244ac9f9..f4957deaae81c1 100644 --- a/EIPS/eip-evmc-precompiles.md +++ b/EIPS/eip-2003.md @@ -1,5 +1,5 @@ --- -eip: XXXX DO NOT MERGE +eip: 2003 title: EVMC modules for implementations of precompiled contracts author: Paweł Bylica (@chfast) discussions-to: HERE From a3b5ab778d46ce9e8df26354e6cf050742f41464 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 May 2019 15:43:34 +0100 Subject: [PATCH 03/19] Wording changes --- EIPS/eip-2003.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index f4957deaae81c1..0e95a075b33a56 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -6,14 +6,14 @@ discussions-to: HERE status: Draft type: Informational created: 2019-05-09 +requires: 1352 --- ## Abstract -[EVMC] specifies generic API for Ethereum execution engines. +[EVMC] specifies a generic API for Ethereum execution engines. This EIP specifies a way of providing implementations of Ethereum precompiled contracts -as a degenerated EVM implementations using [EVMC VM API]. - +using the [EVMC VM API]. ## Specification @@ -52,23 +52,20 @@ TODO ## Test Cases -EVMC provides the [evmc-vmtester] tool for checking compatibility with EVMC specification. - +EVMC provides the [evmc-vmtester] tool for checking compatibility with the EVMC specification. ## Implementations - [Example of Precompiles VM implementation][example_precompiles_vm.cpp] -- ewasm/precompiles +- [ewasm precompiles] - Aleth code for precompiles - Parity code for precompiles - Other EVMC VMs? - ## Copyright Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). - ## References - [EVMC – Ethereum Client-VM Connector API][EVMC] @@ -76,7 +73,6 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public - [EVMC VM Implementation Guide][EVMC VM API] - [EIP 1352: Specify restricted address range for precompiles/system contracts][EIP-1352] - ## TODO - What if message::kind is CREATE? @@ -91,6 +87,7 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public [EVMC VM API]: https://ethereum.github.io/evmc/vmguide.html [evmc-vmtester]: https://ethereum.github.io/evmc/vmtester.html [example_precompiles_vm.cpp]: https://github.com/ethereum/evmc/blob/master/examples/example_precompiles_vm/example_precompiles_vm.cpp +[ewasm precompiles]: https://github.com/ewasm/precompiesl [`EVMC_CAPABILITY_PRECOMPILES`]: https://ethereum.github.io/evmc/group__EVMC.html#gga44f9ecb88cf6422a0072936494fd6ac7a43ea2aa7b099a2d67bc53c118ff3683d [`EVMC_REJECTED`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a2f3e0d8777f8d974ead27ae2a6eb2005 From e6836ed70ca1d037c4f271d35a66d45b2ac88170 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 May 2019 15:46:08 +0100 Subject: [PATCH 04/19] More wording --- EIPS/eip-2003.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 0e95a075b33a56..21970b2c41b76d 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -17,6 +17,8 @@ using the [EVMC VM API]. ## Specification +For the complete [EVMC] specification visit the [EVMC documentation first]. + The EVMC module with implementations of precompiled contracts SHOULD: 1. Advertise the [`EVMC_CAPABILITY_PRECOMPILES`] capability @@ -44,6 +46,7 @@ The EVMC module with implementations of precompiled contracts SHOULD: the [`EVMC_SUCCESS`] status code and _gas left_ equal the call gas limit ([`evmc_message::gas`]). +No other result code should be returned by a precompile. ## Rationale From 9f883ec95f86e02cc2f958a7da819707c69d6faa Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 14 May 2019 13:57:39 +0100 Subject: [PATCH 05/19] Add discussion URL --- EIPS/eip-2003.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 21970b2c41b76d..7bf1ab6e55ad5c 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -2,7 +2,7 @@ eip: 2003 title: EVMC modules for implementations of precompiled contracts author: Paweł Bylica (@chfast) -discussions-to: HERE +discussions-to: https://github.com/ethereum/evmc/issues/259 status: Draft type: Informational created: 2019-05-09 From 9b30f28bbe95f650e5b40fab7e49a49bc2eb63fa Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 17 May 2019 02:37:01 +0100 Subject: [PATCH 06/19] Fix typo --- EIPS/eip-2003.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 7bf1ab6e55ad5c..80d317ffda8777 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -90,7 +90,7 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public [EVMC VM API]: https://ethereum.github.io/evmc/vmguide.html [evmc-vmtester]: https://ethereum.github.io/evmc/vmtester.html [example_precompiles_vm.cpp]: https://github.com/ethereum/evmc/blob/master/examples/example_precompiles_vm/example_precompiles_vm.cpp -[ewasm precompiles]: https://github.com/ewasm/precompiesl +[ewasm precompiles]: https://github.com/ewasm/ewasm-precompiles [`EVMC_CAPABILITY_PRECOMPILES`]: https://ethereum.github.io/evmc/group__EVMC.html#gga44f9ecb88cf6422a0072936494fd6ac7a43ea2aa7b099a2d67bc53c118ff3683d [`EVMC_REJECTED`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a2f3e0d8777f8d974ead27ae2a6eb2005 From 00752bbfa3367e85aa0cd8095e0165a20e026860 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 3 Jun 2019 00:31:17 +0100 Subject: [PATCH 07/19] Mention to more error codes --- EIPS/eip-2003.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 80d317ffda8777..73dbb5efa86d66 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -46,7 +46,9 @@ The EVMC module with implementations of precompiled contracts SHOULD: the [`EVMC_SUCCESS`] status code and _gas left_ equal the call gas limit ([`evmc_message::gas`]). -No other result code should be returned by a precompile. +Precompiles are allowed to return two more error codes: +- `EVMC_FAILURE` if the failure was caused due to something other than out of gas (e.g. input validation error) +- `EVMC_REVERT` if the precompile doesn't want to forfeit all supplied gas (as of May 2019 no such precompile exists) ## Rationale From 096001b973e4a8dc8fab9014b9221410ae9a835a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 3 Jun 2019 00:33:31 +0100 Subject: [PATCH 08/19] mention host context being null --- EIPS/eip-2003.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 73dbb5efa86d66..f9b3011c6ebcd9 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -50,6 +50,8 @@ Precompiles are allowed to return two more error codes: - `EVMC_FAILURE` if the failure was caused due to something other than out of gas (e.g. input validation error) - `EVMC_REVERT` if the precompile doesn't want to forfeit all supplied gas (as of May 2019 no such precompile exists) +Note: when interacting with precompiles, the host context does not need to be supplied. + ## Rationale TODO From 353b0a28b4bd76e09b70d42d9275441bf90a1054 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 3 Jun 2019 09:34:57 +0100 Subject: [PATCH 09/19] Mention EVMC6 --- EIPS/eip-2003.md | 1 + 1 file changed, 1 insertion(+) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index f9b3011c6ebcd9..0f135b607ca021 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -18,6 +18,7 @@ using the [EVMC VM API]. ## Specification For the complete [EVMC] specification visit the [EVMC documentation first]. +This EIP is based on and is compatible with EVMC ABI version 6. The EVMC module with implementations of precompiled contracts SHOULD: From 889ffa64c9c7abf22c2898fb3339ab05520511ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 5 Jun 2019 16:43:57 +0200 Subject: [PATCH 10/19] Extend information about Host interface --- EIPS/eip-2003.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 0f135b607ca021..bf5f02348920aa 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -22,7 +22,7 @@ This EIP is based on and is compatible with EVMC ABI version 6. The EVMC module with implementations of precompiled contracts SHOULD: -1. Advertise the [`EVMC_CAPABILITY_PRECOMPILES`] capability +1. Advertise the [`EVMC_CAPABILITY_PRECOMPILES`] capability in the [`get_capabilities()`] method. 2. Implement the [`execute()`] method in the following way: 1. Check if the call destination address ([`evmc_message::destination`]) @@ -30,7 +30,7 @@ The EVMC module with implementations of precompiled contracts SHOULD: If not, abort execution with the [`EVMC_REJECTED`] status code. 2. Check if the call destination address ([`evmc_message::destination`]) targets existing precompiled contract. - Consider the EVM revision ([`evmc_revision`]) requested by + Consider the EVM revision ([`evmc_revision`]) requested by the `rev` parameter of [`execute()`]. If yes, execute as follows: 1. Inspect the input data ([`evmc_message::input_data`], [`evmc_message::input_size`]) @@ -47,15 +47,19 @@ The EVMC module with implementations of precompiled contracts SHOULD: the [`EVMC_SUCCESS`] status code and _gas left_ equal the call gas limit ([`evmc_message::gas`]). -Precompiles are allowed to return two more error codes: -- `EVMC_FAILURE` if the failure was caused due to something other than out of gas (e.g. input validation error) -- `EVMC_REVERT` if the precompile doesn't want to forfeit all supplied gas (as of May 2019 no such precompile exists) +Precompiled contract implementations are allowed to return two more EVMC error codes: +- [`EVMC_FAILURE`] if the failure was caused due to something other than out of gas (e.g. input validation error) +- [`EVMC_REVERT`] if the precompile doesn't want to forfeit all supplied gas (as of May 2019 no such precompile exists) + +The Client is not required to provide the Host interface (by setting the [`evmc_context`] argument of [`execute()`] to null). +Therefore, the precompiled contracts implementation MUST NOT access the `evmc_context`. -Note: when interacting with precompiles, the host context does not need to be supplied. ## Rationale -TODO +It is very unlikely that any precompile will need to access or modify a contract state. +Not requiring the Client to implement the EVMC Host interface removes the big portion of work +needed for full EVMC integration. ## Test Cases @@ -68,7 +72,7 @@ EVMC provides the [evmc-vmtester] tool for checking compatibility with the EVMC - [ewasm precompiles] - Aleth code for precompiles - Parity code for precompiles -- Other EVMC VMs? + ## Copyright @@ -85,7 +89,6 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public - What if message::kind is CREATE? - What if message contains code? -- Add code snippets from the example? - Links to EVMC repo are not pinned to particular commit. Probably should be pinned to v6.3.0 later on. From e97a2d3ea9fdbeba32c7373432261a2267098dc9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 6 Jun 2019 11:34:05 +0200 Subject: [PATCH 11/19] Add eip1962-evmc example --- EIPS/eip-2003.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index bf5f02348920aa..e8a21ee8e6647a 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -15,6 +15,7 @@ requires: 1352 This EIP specifies a way of providing implementations of Ethereum precompiled contracts using the [EVMC VM API]. + ## Specification For the complete [EVMC] specification visit the [EVMC documentation first]. @@ -66,18 +67,21 @@ needed for full EVMC integration. EVMC provides the [evmc-vmtester] tool for checking compatibility with the EVMC specification. + ## Implementations - [Example of Precompiles VM implementation][example_precompiles_vm.cpp] - [ewasm precompiles] - Aleth code for precompiles - Parity code for precompiles +- [EIP-1962 implemented as an EVMC precompile module](https://github.com/axic/eip1962-evmc) ## Copyright Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). + ## References - [EVMC – Ethereum Client-VM Connector API][EVMC] @@ -85,6 +89,7 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public - [EVMC VM Implementation Guide][EVMC VM API] - [EIP 1352: Specify restricted address range for precompiles/system contracts][EIP-1352] + ## TODO - What if message::kind is CREATE? From 3ed58eb72c7fb373970ca20617362b31c54e427f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 6 Jun 2019 11:34:24 +0200 Subject: [PATCH 12/19] move references above copyright --- EIPS/eip-2003.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index e8a21ee8e6647a..0c46d20861e8ba 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -77,11 +77,6 @@ EVMC provides the [evmc-vmtester] tool for checking compatibility with the EVMC - [EIP-1962 implemented as an EVMC precompile module](https://github.com/axic/eip1962-evmc) -## Copyright - -Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). - - ## References - [EVMC – Ethereum Client-VM Connector API][EVMC] @@ -90,6 +85,11 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public - [EIP 1352: Specify restricted address range for precompiles/system contracts][EIP-1352] +## Copyright + +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). + + ## TODO - What if message::kind is CREATE? From aca040b65aef9fc727ce4808370ec91846b15b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 12:22:47 +0200 Subject: [PATCH 13/19] Reword the specification Co-Authored-By: Andrei Maiboroda --- EIPS/eip-2003.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 0c46d20861e8ba..4b4d936441f329 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -52,7 +52,7 @@ Precompiled contract implementations are allowed to return two more EVMC error c - [`EVMC_FAILURE`] if the failure was caused due to something other than out of gas (e.g. input validation error) - [`EVMC_REVERT`] if the precompile doesn't want to forfeit all supplied gas (as of May 2019 no such precompile exists) -The Client is not required to provide the Host interface (by setting the [`evmc_context`] argument of [`execute()`] to null). +The Client is not required to provide the Host interface ([`evmc_context`] argument of [`execute()`] is set to NULL). Therefore, the precompiled contracts implementation MUST NOT access the `evmc_context`. From e80116a1588b00bd02a0e8b04730fb80816a3f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 12:38:27 +0200 Subject: [PATCH 14/19] Add additional requirements about incoming execution request --- EIPS/eip-2003.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 4b4d936441f329..c950c82e256a25 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -26,9 +26,12 @@ The EVMC module with implementations of precompiled contracts SHOULD: 1. Advertise the [`EVMC_CAPABILITY_PRECOMPILES`] capability in the [`get_capabilities()`] method. 2. Implement the [`execute()`] method in the following way: - 1. Check if the call destination address ([`evmc_message::destination`]) - is within the range of precompiled contracts defined by [EIP-1352]. - If not, abort execution with the [`EVMC_REJECTED`] status code. + 1. Validate the incoming execution request requirements: + 1. The message kind ([`evmc_message::kind`]) is a call ([`EVMC_CALL`]). + 2. The call destination address ([`evmc_message::destination`]) + is within the range of precompiled contracts defined by [EIP-1352]. + 3. There is no code provided (the `code` argument is `NULL` and `code_size` argument is `0`). + If the requirements are not fulfilled, abort execution with the [`EVMC_REJECTED`] status code. 2. Check if the call destination address ([`evmc_message::destination`]) targets existing precompiled contract. Consider the EVM revision ([`evmc_revision`]) requested by @@ -92,8 +95,6 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public ## TODO -- What if message::kind is CREATE? -- What if message contains code? - Links to EVMC repo are not pinned to particular commit. Probably should be pinned to v6.3.0 later on. @@ -105,6 +106,7 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public [example_precompiles_vm.cpp]: https://github.com/ethereum/evmc/blob/master/examples/example_precompiles_vm/example_precompiles_vm.cpp [ewasm precompiles]: https://github.com/ewasm/ewasm-precompiles +[`EVMC_CALL`]: https://ethereum.github.io/evmc/group__EVMC.html#ggab2fa68a92a6828064a61e46060abc634abcf3ae29d9a88ff70b98374fc665694a [`EVMC_CAPABILITY_PRECOMPILES`]: https://ethereum.github.io/evmc/group__EVMC.html#gga44f9ecb88cf6422a0072936494fd6ac7a43ea2aa7b099a2d67bc53c118ff3683d [`EVMC_REJECTED`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a2f3e0d8777f8d974ead27ae2a6eb2005 [`EVMC_OUT_OF_GAS`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920abfc47f75656c996c0b29c0553c00fc18 @@ -115,6 +117,7 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public [`evmc_message::input_data`]: https://ethereum.github.io/evmc/structevmc__message.html#a1adee3454b105eb29cd659ee0cf65c77 [`evmc_message::input_size`]: https://ethereum.github.io/evmc/structevmc__message.html#a2cf1deebd0dbbb20f25ecdfa299f4b5d [`evmc_message::gas`]: https://ethereum.github.io/evmc/structevmc__message.html#ae8deff46588584fa27890e74c82db5e7 +[`evmc_message::kind`]: https://ethereum.github.io/evmc/structevmc__message.html#a691cb93e81d6dfd4fd7e2fa3d06a6bfa [`evmc_result::gas_left`]: https://ethereum.github.io/evmc/structevmc__result.html#af8478c93dbcc3cb2876037c5a5afd4c0 [`evmc_result::output_data`]: https://ethereum.github.io/evmc/structevmc__result.html#a61978e85f9d795a7b9695b9cbf1748d6 [`evmc_result::output_size`]: https://ethereum.github.io/evmc/structevmc__result.html#a93bb7419aff492cdef754421c6d74e26 From 561ae27ef15486213718e8b75a6d25c13cec2df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 12:42:15 +0200 Subject: [PATCH 15/19] Fix markdown list layout --- EIPS/eip-2003.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index c950c82e256a25..2dc3f3c29499c3 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -25,28 +25,41 @@ The EVMC module with implementations of precompiled contracts SHOULD: 1. Advertise the [`EVMC_CAPABILITY_PRECOMPILES`] capability in the [`get_capabilities()`] method. + 2. Implement the [`execute()`] method in the following way: + 1. Validate the incoming execution request requirements: + 1. The message kind ([`evmc_message::kind`]) is a call ([`EVMC_CALL`]). + 2. The call destination address ([`evmc_message::destination`]) is within the range of precompiled contracts defined by [EIP-1352]. + 3. There is no code provided (the `code` argument is `NULL` and `code_size` argument is `0`). + If the requirements are not fulfilled, abort execution with the [`EVMC_REJECTED`] status code. + 2. Check if the call destination address ([`evmc_message::destination`]) targets existing precompiled contract. Consider the EVM revision ([`evmc_revision`]) requested by the `rev` parameter of [`execute()`]. + If yes, execute as follows: + 1. Inspect the input data ([`evmc_message::input_data`], [`evmc_message::input_size`]) and calculate the _gas cost_ of the execution. + 2. Compute the amount of _gas left_ after execution by subtracting the _gas cost_ from the call gas limit ([`evmc_message::gas`]). + 3. If _gas left_ is negative, abort execution with the [`EVMC_OUT_OF_GAS`] status code. + 4. Otherwise, execute the code of the precompiled contract, return the [`EVMC_SUCCESS`] status code, the output and _gas left_ ([`evmc_result::output_data`], [`evmc_result::output_size`], [`evmc_result::gas_left`]). + 3. Otherwise, emulate execution of empty code by returning the [`EVMC_SUCCESS`] status code and _gas left_ equal the call gas limit ([`evmc_message::gas`]). From 6b1d0c9a8081c89b236875ae76b15cf7721b485f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 12:43:31 +0200 Subject: [PATCH 16/19] Add Alex --- EIPS/eip-2003.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 2dc3f3c29499c3..8f2f6c60ee376d 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -1,7 +1,7 @@ --- eip: 2003 title: EVMC modules for implementations of precompiled contracts -author: Paweł Bylica (@chfast) +author: Paweł Bylica (@chfast), Alex Beregszaszi (@axic) discussions-to: https://github.com/ethereum/evmc/issues/259 status: Draft type: Informational From 1ac10a7720a23a6c330526a616e455005682cfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 12:48:10 +0200 Subject: [PATCH 17/19] Add missing links --- EIPS/eip-2003.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 8f2f6c60ee376d..7948d49bd13c67 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -121,8 +121,10 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public [`EVMC_CALL`]: https://ethereum.github.io/evmc/group__EVMC.html#ggab2fa68a92a6828064a61e46060abc634abcf3ae29d9a88ff70b98374fc665694a [`EVMC_CAPABILITY_PRECOMPILES`]: https://ethereum.github.io/evmc/group__EVMC.html#gga44f9ecb88cf6422a0072936494fd6ac7a43ea2aa7b099a2d67bc53c118ff3683d -[`EVMC_REJECTED`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a2f3e0d8777f8d974ead27ae2a6eb2005 +[`EVMC_FAILURE`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920aed5b2a4afa5a47af732569445920a4a9 [`EVMC_OUT_OF_GAS`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920abfc47f75656c996c0b29c0553c00fc18 +[`EVMC_REJECTED`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a2f3e0d8777f8d974ead27ae2a6eb2005 +[`EVMC_REVERT`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920aed708e84d49cc1270e54ec20b0ca0a05 [`EVMC_SUCCESS`]: https://ethereum.github.io/evmc/group__EVMC.html#gga4c0be97f333c050ff45321fcaa34d920a4bc3069fec2bab2a55355a72b7db68b7 [`execute()`]: https://ethereum.github.io/evmc/structevmc__instance.html#a0823ebff21f9b0395b157e8c6b14a207 [`get_capabilities()`]: https://ethereum.github.io/evmc/structevmc__instance.html#ae63b9ca898aa41cbd1e2fe86ca8f4e1c From 11db2417ec3e274b6fbb5c26c52ba14e79abf074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 12:51:13 +0200 Subject: [PATCH 18/19] Remove TODO section --- EIPS/eip-2003.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 7948d49bd13c67..24306248b2f0e6 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -106,11 +106,6 @@ EVMC provides the [evmc-vmtester] tool for checking compatibility with the EVMC Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). -## TODO - -- Links to EVMC repo are not pinned to particular commit. Probably should be pinned to v6.3.0 later on. - - [EIP-1352]: https://eips.ethereum.org/EIPS/eip-1352 [EVMC]: https://github.com/ethereum/evmc [EVMC documentation]: https://ethereum.github.io/evmc/ From 1086974b41e175715cf0e0c88217ab8278f705e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 6 Jun 2019 14:35:37 +0200 Subject: [PATCH 19/19] Fix typo --- EIPS/eip-2003.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2003.md b/EIPS/eip-2003.md index 24306248b2f0e6..08786e9e815611 100644 --- a/EIPS/eip-2003.md +++ b/EIPS/eip-2003.md @@ -18,7 +18,7 @@ using the [EVMC VM API]. ## Specification -For the complete [EVMC] specification visit the [EVMC documentation first]. +For the complete [EVMC] specification visit the [EVMC documentation] first. This EIP is based on and is compatible with EVMC ABI version 6. The EVMC module with implementations of precompiled contracts SHOULD: