Skip to content

Commit

Permalink
EIP-2315: update jumpsub gascost and add back testcases (ethereum#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored and pizzarob committed Jun 12, 2020
1 parent 06fd98d commit b70b13b
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions EIPS/eip-2315.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Bytecode: `0x6004b300b2b7`
| Pc | Op | Cost | Stack | RStack |
|-------|-------------|------|-----------|-----------|
| 0 | PUSH1 | 3 | [] | [] |
| 2 | JUMPSUB | 5 | [4] | [] |
| 2 | JUMPSUB | 8 | [4] | [] |
| 5 | RETURNSUB | 2 | [] | [ 2] |
| 3 | STOP | 0 | [] | [] |

Expand All @@ -92,9 +92,9 @@ Bytecode: `0x6800000000000000000cb300b26011b3b7b2b7`
| Pc | Op | Cost | Stack | RStack |
|-------|-------------|------|-----------|-----------|
| 0 | PUSH9 | 3 | [] | [] |
| 10 | JUMPSUB | 5 | [12] | [] |
| 10 | JUMPSUB | 8 | [12] | [] |
| 13 | PUSH1 | 3 | [] | [10] |
| 15 | JUMPSUB | 5 | [17] | [10] |
| 15 | JUMPSUB | 8 | [17] | [10] |
| 18 | RETURNSUB | 2 | [] | [10,15] |
| 16 | RETURNSUB | 2 | [] | [10] |
| 11 | STOP | 0 | [] | [] |
Expand All @@ -110,7 +110,7 @@ Bytecode: `0x6801000000000000000cb300b26011b3b7b2b7 `
| Pc | Op | Cost | Stack | RStack |
|-------|-------------|------|-----------|-----------|
| 0 | PUSH9 | 3 | [] | [] |
| 10 | JUMPSUB | 5 |[18446744073709551628] | [] |
| 10 | JUMPSUB | 8 |[18446744073709551628] | [] |

```
Error: at pc=10, op=JUMPSUB: evm: invalid jump destination
Expand Down Expand Up @@ -143,12 +143,25 @@ Bytecode: `0x600556b2b75b6003b3`
| 2 | JUMP | 8 | [5] | [] |
| 5 | JUMPDEST | 1 | [] | [] |
| 6 | PUSH1 | 3 | [] | [] |
| 8 | JUMPSUB | 5 | [3] | [] |
| 3 | BEGINSUB | 1 | [] | [ 8] |
| 8 | JUMPSUB | 8 | [3] | [] |
| 4 | RETURNSUB | 2 | [] | [ 8] |
| 9 | STOP | 0 | [] | [] |

Consumed gas: `26`
Consumed gas: `25`

### Error on "walk-into-subroutine"

In this example, the code 'walks' into a subroutine, which is not allowed, and causes an error

| Pc | Op | Cost | Stack | RStack |
|-------|-------------|------|-----------|-----------|
| 0 | BEGINSUB | 1 | [] | [] |


```
Error: at pc=0, op=BEGINSUB: invalid subroutine entry
```
**Note 5**: The content of the error message, (`invalid subroutine entry`) is implementation-specific.

## Implementations

Expand All @@ -162,7 +175,7 @@ The changes for the current version are trivial.

### Costs and Codes

We suggest that the cost of `JUMPSUB` be _low_, and `RETURNSUB` be _verylow_.
We suggest that the cost of `BEGINSUB` be _base_, `JUMPSUB` be _mid_, and `RETURNSUB` be _verylow_.
Measurement will tell. We suggest the following opcodes:

```
Expand All @@ -171,6 +184,8 @@ We suggest that the cost of `JUMPSUB` be _low_, and `RETURNSUB` be _verylow_.
0xb7 RETURNSUB
```

**Note 6**: Although specified at _base_, the cost of `BEGINSUB` does not matter in practice, since `BEGINSUB` never executes without error.

## Security Considerations

These changes do introduce new flow control instructions, so any software which does static/dynamic analysis of evm-code
Expand Down

0 comments on commit b70b13b

Please sign in to comment.