You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: EIPS/eip-2315.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ This proposal introduces three opcodes to support subroutines: `BEGINSUB`, `JUM
17
17
18
18
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.
19
19
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.
21
21
22
22
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.
23
23
@@ -49,7 +49,7 @@ offset step opcode stack stack
49
49
0 0 PUSH1 3 [] []
50
50
1 1 JUMPSUB [3] [1]
51
51
2 4 STOP [] [1]
52
-
3 2 JUMPDEST [] [1]
52
+
3 2 BEGINSUB [] [1]
53
53
4 3 RETURNSUB [] []
54
54
```
55
55
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.
58
58
offset step opcode stack stack
59
59
0 0 PUSH1 2 [] []
60
60
1 1 JUMPSUB [2] [1]
61
-
2 2 JUMPDEST [] [1]
61
+
2 2 BEGINSUB [] [1]
62
62
3 3 RETURNSUB [] []
63
63
```
64
64
The above code should terminate after 4 steps with an empty stack.
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
118
118
```
119
119
## Security Considerations
120
120
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`.
0 commit comments