-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
## Preamble | ||
|
||
EIP: <to be assigned> | ||
Title: Unlimited SWAP and DUP instructions | ||
Author: Alex Beregszaszi | ||
Type: Standard Track | ||
Category: Core | ||
Status: Draft | ||
Created: 2017-07-03 | ||
|
||
|
||
## Abstract | ||
|
||
`SWAP` and `DUP` instructions are limited to a stack depth of 16. Introduce two new instructions, `SWAPn` and `DUPn`, which lift this limitation and allow accessing the stack up to its full depth of 1024 items. | ||
|
||
## Motivation | ||
|
||
Implementing higher level constructs, such as functions, on top of EVM will result in a list of input and output parameters as well as an instruction offset to return to. | ||
|
||
The number of these arguments (or stack items) can easily exceed 16 and thus will require extra care from a compiler to lay them out in a way that all of them are still accessible. | ||
|
||
Introducing `SWAPn` and `DUPn` will provide an option to compilers to simplify accessing deep stack items at the price of possibly increased gas costs. | ||
|
||
## Specification | ||
|
||
Instructions `DUPn` (`0xb0`) and `SWAPn` (`0xb1`) are introduced, which take the top item from stack (referred to as `n`). | ||
|
||
If `n` exceeds 1024 or the current stack depth is less than `n`, then a stack underflow exception is issued. If the current stack depth is at the limit, a stack overflow exception is issued. | ||
|
||
Otherwise | ||
- for `DUPn` the stack item at depth `n` is duplicated at the top of the stack | ||
- for `SWAPn` the top stack item is swapped with the item at depth `n` | ||
|
||
The gas cost for both instructions is set at 3. In reality the cost for such an operation is 6 including the required `PUSH`. | ||
|
||
Since both of these instructions require the top stack item to contain the position, it is still only possible to reach more than 16 stack items if there is at least one free stack slot. | ||
|
||
## Rationale | ||
|
||
TBA | ||
|
||
## Backwards Compatibility | ||
|
||
This has no effect on backwards compatibility. | ||
|
||
## Test Cases | ||
|
||
- executing `602a600160026003600460056006600760086009600a600b600c600d600e600f60106011b0` should have `0x42` as the top stack item | ||
- executing `602a600160026003600460056006600760086009600a600b600c600d600e600f60106011b1` should have `0x42` as the top stack item | ||
|
||
## Implementation | ||
|
||
TBA | ||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |