From 911804384db7a9d0edd8eb4549e3f10de8ad1e03 Mon Sep 17 00:00:00 2001 From: ethers Date: Thu, 19 Nov 2015 02:02:53 +0100 Subject: [PATCH 1/6] EIP ! --- eip-X.mediawiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eip-X.mediawiki b/eip-X.mediawiki index 5ec07142..43d6ab37 100644 --- a/eip-X.mediawiki +++ b/eip-X.mediawiki @@ -1,5 +1,5 @@
-  BIP: 
+  EIP: 
   Title: 
   Author: 
   Discussions-To: 

From e2ddda55f3627c72fee61b393e118a16934d0763 Mon Sep 17 00:00:00 2001
From: Martin Holst Swende 
Date: Thu, 19 Nov 2015 21:01:14 +0100
Subject: [PATCH 2/6] Initial commit of EIP 3

---
 EIPS/eip-3.mediawiki | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 EIPS/eip-3.mediawiki

diff --git a/EIPS/eip-3.mediawiki b/EIPS/eip-3.mediawiki
new file mode 100644
index 00000000..3ec961b4
--- /dev/null
+++ b/EIPS/eip-3.mediawiki
@@ -0,0 +1,44 @@
+
+  EIP: 3
+  Title: Addition of CALLDEPTH opcode
+  Author: Martin Holst Swende 
+  Status: Draft
+  Type: Standards Track
+  Created: 2015-11-19
+
+ +==Abstract== + +This is a proposal to add a new opcode, `CALLDEPTH`. The `CALLDEPTH` opcode would return the remaining available call stack depth. + +==Motivation== + +There is a limit specifying how deep contracts can call other contracts; the call stack. The limit is currently `256`. If a contract invokes another contract (either via `CALL` or `CALLCODE`), the operation will fail if the call stack depth limit has been reached. + +This behaviour makes it possible to subject a contract to a "call stack attack" [1]. In such an attack, an attacker first creates a suitable depth of the stack, e.g. by recursive calls. After this step, the attacker invokes the targeted contract. If the targeted calls another contract, that call will fail. If the return value is not properly checked to see if the call was successfull, the consequences could be damaging. + +Example: + +1. Contract `A` want's to be invoked regularly, and pays Ether to the invoker in every block. +2. When contract `A` is invoked, it calls contracts `B` and `C`, which consumes a lot of gas. After invocation, contract `A` pays Ether to the caller. +3. Malicious user `X` ensures that the stack depth is shallow before invoking A. Both calls to `B` and `C` fail, but `X` can still collect the reward. + +It is possible to defend against this in two ways: + +1. Check return value after invocation. +2. Check call stack depth experimentally. A library [2] by Piper Merriam exists for this purpose. This method is quite costly in gas. + + +[1] a.k.a "shallow stack attack" and "stack attack". However, to be precise, the word `stack` has a different meaning within the EVM, and is not to be confused with the _call stack_. +[2] https://github.com/pipermerriam/ethereum-stack-depth-lib + +==Specification== + +The opcode `CALLDEPTH` should return the remaining call stack depth. A value of `0` means that the call stack is exhausted, and no further calls can be made. + +==Rationale== + +The actual call stack depth, as well as the call stack depth limit, are present in the EVM during execution, but just not available within the EVM. The implementation should be fairly simple and would provide a cheap and way to protect against call stack attacks. + +==Implementation== + From 2bf1177f1a8f7e1214a0efd8d15eeb14e799d4f3 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 19 Nov 2015 21:06:06 +0100 Subject: [PATCH 3/6] Formatting --- EIPS/eip-3.mediawiki | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/EIPS/eip-3.mediawiki b/EIPS/eip-3.mediawiki index 3ec961b4..6e5c28ba 100644 --- a/EIPS/eip-3.mediawiki +++ b/EIPS/eip-3.mediawiki @@ -9,7 +9,7 @@ ==Abstract== -This is a proposal to add a new opcode, `CALLDEPTH`. The `CALLDEPTH` opcode would return the remaining available call stack depth. +This is a proposal to add a new opcode, CALLDEPTH. The CALLDEPTH opcode would return the remaining available call stack depth. ==Motivation== @@ -19,14 +19,14 @@ This behaviour makes it possible to subject a contract to a "call stack attack" Example: -1. Contract `A` want's to be invoked regularly, and pays Ether to the invoker in every block. -2. When contract `A` is invoked, it calls contracts `B` and `C`, which consumes a lot of gas. After invocation, contract `A` pays Ether to the caller. -3. Malicious user `X` ensures that the stack depth is shallow before invoking A. Both calls to `B` and `C` fail, but `X` can still collect the reward. +# Contract `A` want's to be invoked regularly, and pays Ether to the invoker in every block. +# When contract `A` is invoked, it calls contracts `B` and `C`, which consumes a lot of gas. After invocation, contract `A` pays Ether to the caller. +# Malicious user `X` ensures that the stack depth is shallow before invoking A. Both calls to `B` and `C` fail, but `X` can still collect the reward. It is possible to defend against this in two ways: -1. Check return value after invocation. -2. Check call stack depth experimentally. A library [2] by Piper Merriam exists for this purpose. This method is quite costly in gas. +# Check return value after invocation. +# Check call stack depth experimentally. A library [2] by Piper Merriam exists for this purpose. This method is quite costly in gas. [1] a.k.a "shallow stack attack" and "stack attack". However, to be precise, the word `stack` has a different meaning within the EVM, and is not to be confused with the _call stack_. @@ -34,7 +34,7 @@ It is possible to defend against this in two ways: ==Specification== -The opcode `CALLDEPTH` should return the remaining call stack depth. A value of `0` means that the call stack is exhausted, and no further calls can be made. +The opcode CALLDEPTH should return the remaining call stack depth. A value of `0` means that the call stack is exhausted, and no further calls can be made. ==Rationale== From 370a062b61694e33cea0e140e47ab5c588b8b147 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 19 Nov 2015 21:08:00 +0100 Subject: [PATCH 4/6] Formatting --- EIPS/eip-3.mediawiki | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-3.mediawiki b/EIPS/eip-3.mediawiki index 6e5c28ba..07326f4d 100644 --- a/EIPS/eip-3.mediawiki +++ b/EIPS/eip-3.mediawiki @@ -30,6 +30,7 @@ It is possible to defend against this in two ways: [1] a.k.a "shallow stack attack" and "stack attack". However, to be precise, the word `stack` has a different meaning within the EVM, and is not to be confused with the _call stack_. + [2] https://github.com/pipermerriam/ethereum-stack-depth-lib ==Specification== @@ -38,7 +39,8 @@ The opcode CALLDEPTH should return the remaining call stack depth. ==Rationale== -The actual call stack depth, as well as the call stack depth limit, are present in the EVM during execution, but just not available within the EVM. The implementation should be fairly simple and would provide a cheap and way to protect against call stack attacks. +The actual call stack depth, as well as the call stack depth limit, are present in the EVM during execution, but just not available within the EVM. The implementation should be fairly simple and would provide a cheap and way to protect against call stack attacks. ==Implementation== +Not implemented. \ No newline at end of file From 7e154679a62b6b34fff69764d4d5346889c447e2 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 19 Nov 2015 21:09:58 +0100 Subject: [PATCH 5/6] Formatting --- EIPS/eip-3.mediawiki | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-3.mediawiki b/EIPS/eip-3.mediawiki index 07326f4d..eb1bfde1 100644 --- a/EIPS/eip-3.mediawiki +++ b/EIPS/eip-3.mediawiki @@ -29,13 +29,13 @@ It is possible to defend against this in two ways: # Check call stack depth experimentally. A library [2] by Piper Merriam exists for this purpose. This method is quite costly in gas. -[1] a.k.a "shallow stack attack" and "stack attack". However, to be precise, the word `stack` has a different meaning within the EVM, and is not to be confused with the _call stack_. +[1] a.k.a "shallow stack attack" and "stack attack". However, to be precise, the word ''stack'' has a different meaning within the EVM, and is not to be confused with the ''call stack''. [2] https://github.com/pipermerriam/ethereum-stack-depth-lib ==Specification== -The opcode CALLDEPTH should return the remaining call stack depth. A value of `0` means that the call stack is exhausted, and no further calls can be made. +The opcode CALLDEPTH should return the remaining call stack depth. A value of 0 means that the call stack is exhausted, and no further calls can be made. ==Rationale== From d02f2b26438d97e215c6efaf5427b2469633551a Mon Sep 17 00:00:00 2001 From: wanderer Date: Thu, 19 Nov 2015 22:11:12 +0000 Subject: [PATCH 6/6] Update Index --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b43b8776..8626d157 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,6 @@ First review [EIP-1](EIPS/eip-1.mediawiki). Then clone the repository and add yo # Current EIPS | Number | Title | Author | Type | Status | | ------------- |---------------| ----- | -------| ------- | -| [1](EIPS/eip-1.mediawiki) | EIP Purpose and Guidelines | Martin Becze | Meta | Draft | -| [2](EIPS/eip-2.mediawiki) | Homestead Hard-fork Changes | Vitalik Buterin | Standard | Active | +| [1](EIPS/eip-1.mediawiki) | EIP Purpose and Guidelines | Martin Becze | Meta | Active | +| [2](EIPS/eip-2.mediawiki) | Homestead Hard-fork Changes | Vitalik Buterin | Standard | Draft | +| [3](EIPS/eip-3.mediawiki) | Addition of CALLDEPTH opcode | Martin Holst Swende | Standard | Draft |