Skip to content

Commit

Permalink
Update EIP-6206: rename JUMPF's argument to target_section_index
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
gumb0 authored Dec 7, 2023
1 parent 1571eaf commit d4deb4d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions EIPS/eip-6206.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ The first code section MUST have 0 inputs and be non-returning.

A new instruction, `JUMPF (0xe5)`, is introduced.

1. `JUMPF` has one immediate argument, `code_section_index`, encoded as a 16-bit unsigned big-endian value.
2. If the operand stack size exceeds `1024 - type[code_section_index].max_stack_height` (i.e. if the called function may exceed the global stack height limit), execution results in an exceptional halt. This guarantees that the target function does not exceed global stack height limit.
3. `JUMPF` sets `current_section_index` to `code_section_index` and `PC` to `0`, but does not change the return stack. Execution continues in the target section.
1. `JUMPF` has one immediate argument, `target_section_index`, encoded as a 16-bit unsigned big-endian value.
2. If the operand stack size exceeds `1024 - type[target_section_index].max_stack_height` (i.e. if the called function may exceed the global stack height limit), execution results in an exceptional halt. This guarantees that the target function does not exceed global stack height limit.
3. `JUMPF` sets `current_section_index` to `target_section_index` and `PC` to `0`, but does not change the return stack. Execution continues in the target section.
4. `JUMPF` costs 5 gas.
5. `JUMPF` neither pops nor pushes anything to the operand stack.

Expand All @@ -49,17 +49,17 @@ Let the definition of `type[i]` be inherited from [EIP-4750](./eip-4750.md) and

* The immediate argument of `JUMPF` MUST be less than the total number of code sections.
* For each `JUMPF` instruction:
* either `type[current_section_index].outputs` MUST be greater or equal `type[code_section_index].outputs`,
* or `type[code_section_index].outputs` MUST be `0x80`
* either `type[current_section_index].outputs` MUST be greater or equal `type[target_section_index].outputs`,
* or `type[target_section_index].outputs` MUST be `0x80`
* The stack height validation at `JUMPF` depends on whether the target section is non-returning:
* `JUMPF` into returning section (`type[code_section_index].outputs` does not equal `0x80`): stack height MUST be equal to `type[current_section_index].outputs + type[code_section_index].inputs - type[code_section_index].outputs`. This means that target section can output less stack elements than the original code section called by the top element on the return stack, if the current code section leaves the delta `type[current_section_index].outputs - type[code_section_index].outputs` element(s) on the stack.
* `JUMPF` into non-returning section (`type[code_section_index].outputs` equals `0x80`): stack height must be greater or equal than `type[code_section_index].inputs`.
* `JUMPF` into returning section (`type[target_section_index].outputs` does not equal `0x80`): stack height MUST be equal to `type[current_section_index].outputs + type[target_section_index].inputs - type[target_section_index].outputs`. This means that target section can output less stack elements than the original code section called by the top element on the return stack, if the current code section leaves the delta `type[current_section_index].outputs - type[target_section_index].outputs` element(s) on the stack.
* `JUMPF` into non-returning section (`type[target_section_index].outputs` equals `0x80`): stack height must be greater or equal than `type[target_section_index].inputs`.
* `JUMPF` is considered terminating instruction, i.e. does not have successor instructions in code validation and MAY be final instruction in the section.
* The code validation defined in [EIP-4200](./eip-4200.md) also fails if any `RJUMP*` offset points to one of the two bytes directly following a `JUMPF` instruction.

`CALLF` instruction validation is extended to include the rule:

* Code section is invalid in case an immediate argument `code_section_index` of any `CALLF` targets a non-returning section, i.e. `type[code_section_index` equals `0x80`.
* Code section is invalid in case an immediate argument `target_section_index` of any `CALLF` targets a non-returning section, i.e. `type[target_section_index` equals `0x80`.

#### Non-returning status validation

Expand All @@ -70,7 +70,7 @@ Section type MUST be non-returning in case the section contains no `RETF` instru

### Allowing `JUMPF` to section with less outputs

As long as `JUMPF` prepares the delta `type[current_section_index].outputs - type[code_section_index].outputs` stack elements before changing code sections, it is possible to jump to a section with less outputs than was originally entered via `CALLF`. This will reduce duplicated code as it will allow compilers more flexibility during code generation such that certain helpers can be used generically by functions, regardless of their output values.
As long as `JUMPF` prepares the delta `type[current_section_index].outputs - type[target_section_index].outputs` stack elements before changing code sections, it is possible to jump to a section with less outputs than was originally entered via `CALLF`. This will reduce duplicated code as it will allow compilers more flexibility during code generation such that certain helpers can be used generically by functions, regardless of their output values.

## Backwards Compatibility

Expand Down

0 comments on commit d4deb4d

Please sign in to comment.