From 7d305e1d2eebb27503e48d1dd07bddc61665fe4d Mon Sep 17 00:00:00 2001 From: mattdf Date: Thu, 19 Jul 2018 01:12:17 +0200 Subject: [PATCH 1/4] add eip-1231 --- EIPS/eip-1231.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 EIPS/eip-1231.md diff --git a/EIPS/eip-1231.md b/EIPS/eip-1231.md new file mode 100644 index 00000000000000..2be71e8f7ecc46 --- /dev/null +++ b/EIPS/eip-1231.md @@ -0,0 +1,33 @@ +--- +eip: 1231 +title: Reduce cost of CALLs to precompiles +author: Matthew Di Ferrante (@mattdf) +status: Draft +type: Standards Track +category: Core +created: 2018-07-19 +requires: 150, 158 +--- + +## Short Description + +The Spurious Dragon hard fork increased the cost of CALLs to mitigate protocol DoS attacks that involved reads, but it failed to distinguish between CALLs to precompiles and CALLs to deployed contracts. This is an oversight that should be corrected. + +## Motivation + +There are useful precompiles such as a ECADD, SHA256, RIPEMD and the identity precompile (useful for memcpy) which have a gas cost that is far below or approximately equal to the cost of a CALL, which restricts their use cases in certain situations if they need to be called many times in a loop as they can become 2x to 10x more expensive due to the CALL cost overhead, particularly with SHA256 and ECADD which often require tight loops to certain cryptographic protocols. + +In the Spurious Dragon hard fork, the cost of CALLs across the board was raised to 700 gas to mitigate DoS from state reads, without making a distinction between precompiles and deployed contracts. It does not make sense that precompiles should also suffer from the DoS mitigation penalty, since the precompiles are part of the core node code and hence never need to be fetched from disk. The CALL cost for precompiles should be reverted back to pre-EIP150, to 40 gas per call. + +## Specification + +Following is a table with the current gas cost and new gas cost: + +| Contract | Opcode | Current Gas Cost | Updated Gas Cost | +| ------------------------------ | --------- | ----------------------------- | ------------------- | +| `CALL` (to precompiles) | `0xf1` | 700[1] | 40 | +| `CALL` (to contracts) | `0xf1` | 700[1] | 700 (unchanged) | + + +[1]- Per EIP-150 + From 5a2ebe359410846b5c5dbe807c713fadb7ebd027 Mon Sep 17 00:00:00 2001 From: Matthew Di Ferrante Date: Thu, 19 Jul 2018 01:29:32 +0200 Subject: [PATCH 2/4] add all call types --- EIPS/eip-1231.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-1231.md b/EIPS/eip-1231.md index 2be71e8f7ecc46..ac4875a73cabab 100644 --- a/EIPS/eip-1231.md +++ b/EIPS/eip-1231.md @@ -23,10 +23,16 @@ In the Spurious Dragon hard fork, the cost of CALLs across the board was raised Following is a table with the current gas cost and new gas cost: -| Contract | Opcode | Current Gas Cost | Updated Gas Cost | +| Opcode name | Opcodes | Current Gas Cost | Updated Gas Cost | | ------------------------------ | --------- | ----------------------------- | ------------------- | | `CALL` (to precompiles) | `0xf1` | 700[1] | 40 | +| `CALLCODE` (to precompiles) | `0xf2` | 700[1] | 40 | +| `DELEGATECALL` (to precompiles)| `0xf3` | 700[1] | 40 | +| `STATICCALL` (to precompiles) | `0xf4` | 700[1] | 40 | | `CALL` (to contracts) | `0xf1` | 700[1] | 700 (unchanged) | +| `CALLCODE` (to contracts) | `0xf2` | 700[1] | 700 (unchanged) | +| `DELEGATECALL` (to contracts) | `0xf3` | 700[1] | 700 (unchanged) | +| `STATICCALL` (to contracts) | `0xf4` | 700[1] | 700 (unchanged) | [1]- Per EIP-150 From 51bf660fdc69b34731c10bfaa33dd3553629737a Mon Sep 17 00:00:00 2001 From: Matthew Di Ferrante Date: Thu, 19 Jul 2018 01:32:01 +0200 Subject: [PATCH 3/4] fix for grammar, clarity --- EIPS/eip-1231.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-1231.md b/EIPS/eip-1231.md index ac4875a73cabab..a9062a0af8ff36 100644 --- a/EIPS/eip-1231.md +++ b/EIPS/eip-1231.md @@ -15,9 +15,9 @@ The Spurious Dragon hard fork increased the cost of CALLs to mitigate protocol D ## Motivation -There are useful precompiles such as a ECADD, SHA256, RIPEMD and the identity precompile (useful for memcpy) which have a gas cost that is far below or approximately equal to the cost of a CALL, which restricts their use cases in certain situations if they need to be called many times in a loop as they can become 2x to 10x more expensive due to the CALL cost overhead, particularly with SHA256 and ECADD which often require tight loops to certain cryptographic protocols. +There are useful precompiles such as a ECADD, SHA256, RIPEMD and the identity precompile (useful for memcpy) which have a gas cost that is far below or approximately equal to the cost of a CALL, which restricts their usefulness if they need to be called many times in a loop. The overhead can cause 2x to 10x increase in gas cost due to the CALL cost overhead, particularly with SHA256 and ECADD which often require tight loops for certain cryptographic protocols. -In the Spurious Dragon hard fork, the cost of CALLs across the board was raised to 700 gas to mitigate DoS from state reads, without making a distinction between precompiles and deployed contracts. It does not make sense that precompiles should also suffer from the DoS mitigation penalty, since the precompiles are part of the core node code and hence never need to be fetched from disk. The CALL cost for precompiles should be reverted back to pre-EIP150, to 40 gas per call. +In the Spurious Dragon hard fork, the cost of CALLs across the board was raised to 700 gas to mitigate DoS from state reads, without making a distinction between precompiles and deployed contracts. It does not make sense that precompiles should also suffer from the DoS mitigation penalty, since the precompiles are part of the core node code and hence never need to be fetched from disk. The CALL cost for precompiles should be reverted back to pre-EIP150 values, to 40 gas per call. ## Specification From b1382bf4f6462a1234a0cf06347437c1008b0338 Mon Sep 17 00:00:00 2001 From: Matthew Di Ferrante Date: Thu, 19 Jul 2018 01:33:26 +0200 Subject: [PATCH 4/4] fix wording --- EIPS/eip-1231.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-1231.md b/EIPS/eip-1231.md index a9062a0af8ff36..09782b1725fd7f 100644 --- a/EIPS/eip-1231.md +++ b/EIPS/eip-1231.md @@ -15,7 +15,7 @@ The Spurious Dragon hard fork increased the cost of CALLs to mitigate protocol D ## Motivation -There are useful precompiles such as a ECADD, SHA256, RIPEMD and the identity precompile (useful for memcpy) which have a gas cost that is far below or approximately equal to the cost of a CALL, which restricts their usefulness if they need to be called many times in a loop. The overhead can cause 2x to 10x increase in gas cost due to the CALL cost overhead, particularly with SHA256 and ECADD which often require tight loops for certain cryptographic protocols. +There are useful precompiles such as a ECADD, SHA256, RIPEMD and the identity precompile (useful for memcpy) which have a gas cost that is far below or approximately equal to the cost of a CALL, which restricts their usefulness if they need to be called many times in a loop. This can cause a 2x to 10x increase in gas cost due to the CALL cost overhead, particularly with SHA256 and ECADD which often require tight loops for certain cryptographic protocols. In the Spurious Dragon hard fork, the cost of CALLs across the board was raised to 700 gas to mitigate DoS from state reads, without making a distinction between precompiles and deployed contracts. It does not make sense that precompiles should also suffer from the DoS mitigation penalty, since the precompiles are part of the core node code and hence never need to be fetched from disk. The CALL cost for precompiles should be reverted back to pre-EIP150 values, to 40 gas per call.