Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enter only via jumpsub #2646

Merged
merged 1 commit into from May 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions EIPS/eip-2315.md
Expand Up @@ -27,7 +27,7 @@ We introduce one more stack into the EVM, called `return_stack`. The `return_sta

##### `BEGINSUB`

Marks the entry point to a subroutine.
Marks the entry point to a subroutine. Subroutines can only be entered via `JUMPSUB`. Execution of BEGINSUB causes an exception (OOG: all gas consumed) and terminates execution.

pops: `0`
pushes: `0`
Expand All @@ -38,15 +38,13 @@ pushes: `0`
- 1.1 If the opcode at `location` is not a `BEGINSUB`, abort with error.
2. Pushes the current `pc+1` to the `return_stack`. (See Note 1 below)
- 2.1 If the `return_stack` already has `1023` items, abort with error.
3. Sets the `pc` to `location`.
3. Sets the `pc` to `location + 1`.

**Note 1:** If the resulting `pc` is beyond the last instruction then the opcode is implicitly a `STOP`, which is not an error.

pops: `1`
pushes: `0` (`return_stack` pushes: `1`)

**Note 1:** The description above lays out the _semantics_ of the `JUMPSUB`. It's up to node implementations to decide the internal representation. For example, a node may decide
to place `PC` on the `return_stack` at `JUMPSUB`, as long as the `RETURNSUB` correctly returns to the `PC+1` location. The internals of the `return_stack` is not one of the
"observable"/consensus-critical parts of the EVM.

##### `RETURNSUB`

1. Pops `1` value form the `return_stack`.
Expand All @@ -59,6 +57,8 @@ pushes: `0`
**Note 2:** Values popped from `return_stack` do not need to be validated, since they cannot be set arbitrarily from code, only implicitly by the evm.
**Note 3:** A value popped from `return_stack` _may_ be outside of the code length, if the last `JUMPSUB` was the last byte of the `code`. In this case the next opcode is implicitly a `STOP`, which is not an error.

**Note 4:** The description above lays out the _semantics_ of this feature in terms of a `return_stack`. It's up to node implementations to decide the internal representation. For example, a node may decide to place `PC` on the `return_stack` at `JUMPSUB`, as long as the `RETURNSUB` correctly returns to the `PC+1` location. The internals of the `return_stack` is not one of the "observable"/consensus-critical parts of the EVM.

## Rationale

This is the smallest possible change that provides native subroutines without breaking backwards compatibility.
Expand Down Expand Up @@ -259,4 +259,4 @@ MULTIPLY:
returnsub
```

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