Skip to content

Commit

Permalink
Automatically merged updates to draft EIP(s) 2315 (ethereum#2504)
Browse files Browse the repository at this point in the history
Hi, I'm a bot! This change was automatically merged because:

 - It only modifies existing Draft or Last Call EIP(s)
 - The PR was approved or written by at least one author of each modified EIP
 - The build is passing
  • Loading branch information
gcolvin authored and Arachnid committed Mar 6, 2021
1 parent 3b4b943 commit 4fb883d
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions EIPS/eip-2315.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The EVM does not provide subroutines as a primitive. Instead, calls must be syn
Jumps to the address on top of the stack, which must be the offset of a `JUMPDEST`.

##### `RETURNSUB`
Returns to the most recently executed `JUMPSUB` and executes the following instruction.
Returns to the most recently executed `JUMPSUB` and advances to the following instruction.

A program may `JUMPSUB` at most 1023 times without an intervening `RETURNSUB`. A program which executes `RETURNSUB` without no prior `BEGINSUB` will `STOP`.

Expand All @@ -37,34 +37,55 @@ These changes do not affect the semantics of existing EVM code.

## Test Cases
```
step op stack
0 PUSH1 3 []
1 JUMPSUB [3]
4 STOP []
2 JUMPDEST []
3 RETURNSUB []
offset step op stack
0 0 PUSH1 3 []
1 1 JUMPSUB [3]
2 4 STOP []
3 2 JUMPDEST []
4 3 RETURNSUB []
```
This code should terminate after 4 steps with an empty stack.
```
offset step op stack
0 0 PUSH1 2 []
1 1 JUMPSUB [2]
2 2 JUMPDEST []
3 3 RETURNSUB []
```
This code should terminate after 4 steps with an empty stack.
```
offset step op stack
0 0 PUSH1 2 []
1 1 JUMPSUB [3]
2 8 STOP []
3 2 JUMPDEST []
4 3 PUSH1 7 []
5 4 JUMPSUB [7]
6 7 RETURNSUB []
7 5 JUMPDEST []
8 6 RETURNSUB []
```
This code should terminate after 8 steps with an empty stack.

## Implementations

No clients have implemented this proposal as of yet.

The new operators proposed here are implemented by the following pseudocode, which adds cases for `JUMPSUB` and `RETURNSUB` to a simple loop-and-switch interpreter.
The new operators proposed here are implemented by the following pseudocode, which in eight lines adds a return stack and cases for `JUMPSUB` and `RETURNSUB` to a simple loop-and-switch interpreter.
```
bytecode[code_size]
data_stack[1024]
return_stack[1024]
push(return_stack, code_size)
PC = 0
push(return_stack, PC)
loop: while PC < code_size {
while PC < code_size {
opcode = bytecode[PC]
switch opcode {
...
case JUMPSUB:
push(return_stack, PC)
PC = pop(data_stack)
continue loop
continue
case RETURNSUB:
PC = pop(return_stack)
}
Expand All @@ -83,7 +104,6 @@ We suggest the cost of `JUMPSUB` should be _low_, and `RETURNSUB` should be _ver
```
## Security Considerations

Program flow analysis frameworks will need to be updated to allow for a new type of branch -`JUMPSUB` - and new type of branching - `RETURNSUB` will cause a jump to a destination which is
a `JUMPSUB`, not a `JUMPDEST`.
Program flow analysis frameworks will need to be updated to allow for a new type of branch -`JUMPSUB` - and new type of branching - `RETURNSUB` - which will cause a jump to a destination which is a `JUMPSUB`, not a `JUMPDEST`.

**Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).**

0 comments on commit 4fb883d

Please sign in to comment.