Skip to content

Commit 42eb4bb

Browse files
authored
Automatically merged updates to draft EIP(s) 2315 (#2524)
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
1 parent f26f240 commit 42eb4bb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

EIPS/eip-2315.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This proposal introduces three opcodes to support subroutines: `BEGINSUB`, `JUM
1717

1818
The EVM does not provide subroutines as a primitive. Instead, calls can be synthesized by fetching and pushing the current program counter on the data stack and jumping to the subroutine address; returns can be synthesized by contriving to get the return address back to the top of stack and jumping back to it. Complex calling conventions are then needed to use the same stack for computation and control flow. Code becomes harder to read and write, and tools may need to pattern-match the conventions to identify the use of subroutines. Complex calling conventions like these can be avoided using memory, but regardless, it costs a lot of gas.
1919

20-
Having opcodes to directly support subroutines can eliminate this complexity and cost, just as for other machines and interpreters going back at least 60 years.
20+
Having opcodes to directly support subroutines can eliminate this complexity and cost, just as for other physical and virtual machines going back at least 50 years.
2121

2222
In the Appendix we show example solc output for a simple program that uses over three times as much gas just calling and returning from subroutines as comparable code using these opcodes.
2323

@@ -49,7 +49,7 @@ offset step opcode stack stack
4949
0 0 PUSH1 3 [] []
5050
1 1 JUMPSUB [3] [1]
5151
2 4 STOP [] [1]
52-
3 2 JUMPDEST [] [1]
52+
3 2 BEGINSUB [] [1]
5353
4 3 RETURNSUB [] []
5454
```
5555
The above code should terminate after 4 steps with an empty stack.
@@ -58,7 +58,7 @@ The above code should terminate after 4 steps with an empty stack.
5858
offset step opcode stack stack
5959
0 0 PUSH1 2 [] []
6060
1 1 JUMPSUB [2] [1]
61-
2 2 JUMPDEST [] [1]
61+
2 2 BEGINSUB [] [1]
6262
3 3 RETURNSUB [] []
6363
```
6464
The above code should terminate after 4 steps with an empty stack.
@@ -68,11 +68,11 @@ offset step opcode stack stack
6868
0 0 PUSH1 3 [] []
6969
1 1 JUMPSUB [3] [1]
7070
2 8 STOP [] []
71-
3 2 JUMPDEST [] [1]
71+
3 2 BEGINSUB [] [1]
7272
4 3 PUSH1 7 [] [1]
7373
5 4 JUMPSUB [7] [1,5]
7474
6 7 RETURNSUB [] [1]
75-
7 5 JUMPDEST [] [1]
75+
7 5 BEGINSUB [] [1]
7676
8 6 RETURNSUB [] [1]
7777
```
7878
The above code should terminate after 8 steps with an empty stack. The above code should terminate after 8 steps with an empty stack.
@@ -118,7 +118,7 @@ We suggest that the cost of `BEGINSUB` be _base_, `JUMPSUB` be _low_, and `RETUR
118118
```
119119
## Security Considerations
120120

121-
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`.
121+
Program flow analysis frameworks will need to be updated to allow for a new type of branch - `JUMPSUB` - which will cause a jump to a destination which is a `BEGINSUB`, not a `JUMPDEST`.
122122

123123
## Appendix: Comparative costs.
124124

0 commit comments

Comments
 (0)