From 55308e9eb6aed6f56bc3c97626deca5161ad767f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 31 Aug 2018 21:49:04 +0100 Subject: [PATCH 1/5] Reduced gas cost for call to self --- ...draft_reduced_gas_cost_for_call_to_self.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md diff --git a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md new file mode 100644 index 00000000000000..854900d1b32c63 --- /dev/null +++ b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md @@ -0,0 +1,39 @@ +--- +eip: +title: Reduced gas cost for call to self +author: Alex Beregszaszi (@axic) +discussions-to: +status: Draft +type: Standards Track +category: Core +created: 2018-08-31 +requires: 150 +--- + +## Abstract +Reduce the gas cost for call instructions, when the goal is to run a new instance of the currently loaded contract. + +## Motivation +TBA (there's a lot to write here) + +## Specification +If `block.number >= FORK_BLKNUM`, then decrease the cost of `CALL`, `DELEGATECALL`, `CALLCODE` and `STATICCALL` from 700 to 40, +if and only if, the destination address of the call equals to the address of the caller. + +## Rationale +EIP150 has increased the cost of these instructions from 40 to 700 to more fairly charge for loading new contracts from disk, e.g. to reflect the I/O charge more closely. +By assuming that 660 is the cost of loading a contract from disk, one can assume that the original 40 gas is a fair cost of creating a new VM instance of an already loaded contract code. + +## Backwards Compatibility +This should pose no risk to backwards compatibility. Currently existing contracts should not notice the difference, just see cheaper execution. +With EIP150 contract (and language) developers had a lesson that relying on strict gas costs is not feasible as costs may change. +The impact of this EIP is even less that of EIP150 because the costs are changing downwards and not upwards. + +## Test Cases +TBA + +## Implementation +TBA + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From 470ed9e3a7eb3ce0834d687505d99afb2d7eaa46 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 4 Sep 2018 10:14:50 +0100 Subject: [PATCH 2/5] Add motivation section by jacqueswww --- ...draft_reduced_gas_cost_for_call_to_self.md | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md index 854900d1b32c63..fd1af8c160f789 100644 --- a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md +++ b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md @@ -1,7 +1,7 @@ --- eip: title: Reduced gas cost for call to self -author: Alex Beregszaszi (@axic) +author: Alex Beregszaszi (@axic), Jacques Wagener (@jacqueswww) discussions-to: status: Draft type: Standards Track @@ -14,7 +14,23 @@ requires: 150 Reduce the gas cost for call instructions, when the goal is to run a new instance of the currently loaded contract. ## Motivation -TBA (there's a lot to write here) +The current gas cost of 700 for all call types (`CALL`, `DELEGATECALL`, `CALLCODE` and `STATICCALL`) does not take into account that a call to a contract itself +does not need to perform additional I/O operations as with an external contract call, as the current contract code has already been loaded into the VM memory. + +Reducing the call-to-self gas cost would greatly benefit smart contract languages, such as Solidity and Vyper, who would then be able to utilise `CALL` instead +of `JUMP` opcodes for internal function calls. + +Using `JUMP` comes at a considerable cost in complexity to the implementation of a smart contract language and/or compiler. The context (including stack and memory) +must be swapped in and out of the calling functions context. + +Using call-to-self provides the guarentee that when making an internal call the function can rely on a clear reset state of memory or context, benefiting both +contract writers and contract consumers against potentially undetetected edge cases were memory could poison the context of the internal function. + +Because of the `JUMP` usage for internal functions a smart contract languages are also at risk of reaching the stack depth limit considerbly faster, if nested +function calls with many in and/or outputs are required. + +Reducing the gas cost, and thereby incentivising of using call-to-self instead of `JUMP`s for the internal function implementation will also benefit static +analyzers and tracers. ## Specification If `block.number >= FORK_BLKNUM`, then decrease the cost of `CALL`, `DELEGATECALL`, `CALLCODE` and `STATICCALL` from 700 to 40, From 04059857fa19110a5f8d6bb4bb4a55fcc13e749a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 4 Sep 2018 18:17:50 +0100 Subject: [PATCH 3/5] Some additions to the motivation section --- EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md index fd1af8c160f789..c4718617c9f902 100644 --- a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md +++ b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md @@ -15,13 +15,15 @@ Reduce the gas cost for call instructions, when the goal is to run a new instanc ## Motivation The current gas cost of 700 for all call types (`CALL`, `DELEGATECALL`, `CALLCODE` and `STATICCALL`) does not take into account that a call to a contract itself -does not need to perform additional I/O operations as with an external contract call, as the current contract code has already been loaded into the VM memory. +does not need to perform additional I/O operations, because the current contract code has already been loaded into memory. Reducing the call-to-self gas cost would greatly benefit smart contract languages, such as Solidity and Vyper, who would then be able to utilise `CALL` instead -of `JUMP` opcodes for internal function calls. +of `JUMP` opcodes for internal function calls. While languages can already utilise `CALL` for internal function calls, they are discouraged to do so due to the +gas costs associated with it. Using `JUMP` comes at a considerable cost in complexity to the implementation of a smart contract language and/or compiler. The context (including stack and memory) -must be swapped in and out of the calling functions context. +must be swapped in and out of the calling functions context. A desired feature is having *pure* functions, which do not modify the state of memory, and realising +them through `JUMP` requires a bigger effort from the compiler as opposed to being able to use `CALL`s. Using call-to-self provides the guarentee that when making an internal call the function can rely on a clear reset state of memory or context, benefiting both contract writers and contract consumers against potentially undetetected edge cases were memory could poison the context of the internal function. From 2cb56fd2b8fcfd691562c4c1ccd4e49fe3f53397 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 4 Sep 2018 18:33:05 +0100 Subject: [PATCH 4/5] Add EIP number and discussion URL --- EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md index c4718617c9f902..87a29aadeda43a 100644 --- a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md +++ b/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md @@ -1,8 +1,8 @@ --- -eip: +eip: 1380 title: Reduced gas cost for call to self author: Alex Beregszaszi (@axic), Jacques Wagener (@jacqueswww) -discussions-to: +discussions-to: https://ethereum-magicians.org/t/eip-1380-reduced-gas-cost-for-call-to-self/1242 status: Draft type: Standards Track category: Core From dd14b46fb8044b96ab687f3f4fb1e4e5e6db59c2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 4 Sep 2018 18:45:24 +0100 Subject: [PATCH 5/5] Rename to eip-1380.md --- ...eip-draft_reduced_gas_cost_for_call_to_self.md => eip-1380.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename EIPS/{eip-draft_reduced_gas_cost_for_call_to_self.md => eip-1380.md} (100%) diff --git a/EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md b/EIPS/eip-1380.md similarity index 100% rename from EIPS/eip-draft_reduced_gas_cost_for_call_to_self.md rename to EIPS/eip-1380.md