This commit is contained in:
vub 2015-11-21 05:32:19 -05:00
commit 0fb4588dce
3 changed files with 47 additions and 6 deletions

View File

@ -1,6 +1,46 @@
<pre>
EIP: 3
Title: Addition of CALLDEPTH opcode
Author: Martin Holst Swende <martin@swende.se>
Status: Draft
Type: Standards Track
Created: 2015-11-19
</pre>
# Add a new opcode, <code>DELEGATE_CALL</code> at 0xf4, which is te same as <code>CALLCODE</code> except it propagates the sender and value from the parent scope to the child scope.
==Abstract==
Propagating the sender and value from the parent scope to the child scope makes it much easier for a contract to store another address as a mutable source of code and ''pass through'' calls to it, as the child code would execute in essentially the same environment (except for reduced gas and increased callstack depth) as the parent.
This is a proposal to add a new opcode, <code>CALLDEPTH</code>. The <code>CALLDEPTH</code> opcode would return the remaining available call stack depth.
# https://github.com/ethereum/pyethereum/blob/develop/ethereum/vm.py#L551
==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:
# 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:
# 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''.
[2] https://github.com/pipermerriam/ethereum-stack-depth-lib
==Specification==
The opcode <code>CALLDEPTH</code> should return the remaining call stack depth. A value of <code>0</code> 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==
Not implemented.

View File

@ -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 |

View File

@ -1,5 +1,5 @@
<pre>
BIP: <EIP number>
EIP: <EIP number>
Title: <EIP title>
Author: <list of authors' real names and optionally, email addrs>
Discussions-To: <email address>