diff --git a/EIPS/eip-2315.md b/EIPS/eip-2315.md index 2013b93d..262f5639 100644 --- a/EIPS/eip-2315.md +++ b/EIPS/eip-2315.md @@ -17,7 +17,7 @@ This proposal introduces three opcodes to support subroutines: `BEGINSUB`, `JUM 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. -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. +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. 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. @@ -49,7 +49,7 @@ offset step opcode stack stack 0 0 PUSH1 3 [] [] 1 1 JUMPSUB [3] [1] 2 4 STOP [] [1] -3 2 JUMPDEST [] [1] +3 2 BEGINSUB [] [1] 4 3 RETURNSUB [] [] ``` 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. offset step opcode stack stack 0 0 PUSH1 2 [] [] 1 1 JUMPSUB [2] [1] -2 2 JUMPDEST [] [1] +2 2 BEGINSUB [] [1] 3 3 RETURNSUB [] [] ``` The above code should terminate after 4 steps with an empty stack. @@ -68,11 +68,11 @@ offset step opcode stack stack 0 0 PUSH1 3 [] [] 1 1 JUMPSUB [3] [1] 2 8 STOP [] [] -3 2 JUMPDEST [] [1] +3 2 BEGINSUB [] [1] 4 3 PUSH1 7 [] [1] 5 4 JUMPSUB [7] [1,5] 6 7 RETURNSUB [] [1] -7 5 JUMPDEST [] [1] +7 5 BEGINSUB [] [1] 8 6 RETURNSUB [] [1] ``` 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 ``` ## 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` - which 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` - which will cause a jump to a destination which is a `BEGINSUB`, not a `JUMPDEST`. ## Appendix: Comparative costs.