Skip to content

Commit 87d097d

Browse files
committed
[WIP] Implement subroutine opcodes
1 parent 37baa93 commit 87d097d

File tree

5 files changed

+19
-35
lines changed

5 files changed

+19
-35
lines changed

eth/vm/forks/berlin/opcodes.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
1-
import copy
2-
3-
from eth_utils.toolz import merge
4-
5-
61
from eth.vm.forks.muir_glacier.opcodes import (
72
MUIR_GLACIER_OPCODES,
83
)
9-
10-
11-
UPDATED_OPCODES = {
12-
# New opcodes
13-
}
14-
15-
BERLIN_OPCODES = merge(
16-
copy.deepcopy(MUIR_GLACIER_OPCODES),
17-
UPDATED_OPCODES,
18-
)
194
import copy
205

216
from eth_utils.toolz import merge
@@ -26,29 +11,28 @@
2611
opcode_values,
2712
)
2813
from eth.vm.opcode import as_opcode
29-
from eth.vm.forks.istanbul.opcodes import ISTANBUL_OPCODES
30-
14+
from eth.vm.logic import flow
3115

3216
UPDATED_OPCODES = {
3317
opcode_values.BEGINSUB: as_opcode(
34-
logic_fn = ...,
18+
logic_fn = flow.beginsub,
3519
mnemonic = mnemonics.BEGINSUB,
3620
gas_cost = constants.GAS_BASE,
3721
),
3822
opcode_values.JUMPSUB: as_opcode(
39-
logic_fn = ...,
23+
logic_fn = flow.jumpsub,
4024
mnemonic = mnemonics.JUMPSUB,
4125
gas_cost = constants.GAS_MID,
4226
),
43-
opcode_values.ENDSUB: as_opcode(
44-
logic_fn = ...,
45-
mnemonic = mnemonics.ENDSUB,
27+
opcode_values.RETURNSUB: as_opcode(
28+
logic_fn = flow.returnsub,
29+
mnemonic = mnemonics.RETURNSUB,
4630
gas_cost = constants.GAS_VERYLOW,
4731
),
4832
}
4933

5034

5135
BERLIN_OPCODES = merge(
52-
copy.deepcopy(ISTANBUL_OPCODES),
36+
copy.deepcopy(MUIR_GLACIER_OPCODES),
5337
UPDATED_OPCODES,
5438
)

eth/vm/logic/flow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
InvalidInstruction,
44
OutOfGas,
55
Halt,
6+
InsufficientStack,
67
)
78

89
from eth.vm.computation import BaseComputation
@@ -69,8 +70,8 @@ def jumpsub(computation: BaseComputation) -> None:
6970
sub_loc = computation.stack_pop1_int()
7071

7172
if computation.code.is_valid_opcode(sub_loc):
72-
73-
sub_op = computation.code(sub_loc)
73+
74+
sub_op = computation.code.is_valid_opcode(sub_loc)
7475

7576
if sub_op == BEGINSUB:
7677
temp = computation.code.program_counter

eth/vm/mnemonics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
#
167167
BEGINSUB = 'BEGINSUB'
168168
JUMPSUB = 'JUMPSUB'
169-
ENDSUB = 'ENDSUB'
169+
RETURNSUB = 'RETURNSUB'
170170
#
171171
# System
172172
#

eth/vm/opcode_values.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@
9191
MSIZE = 0x59
9292
GAS = 0x5a
9393
JUMPDEST = 0x5b
94-
94+
#
95+
# Subroutines
96+
#
97+
BEGINSUB = 0x5c
98+
RETURNSUB = 0x5d
99+
JUMPSUB = 0x5e
95100

96101
#
97102
# Push Operations
@@ -182,14 +187,6 @@
182187
LOG4 = 0xa4
183188

184189

185-
#
186-
# Subroutines
187-
#
188-
BEGINSUB = 0xb2
189-
JUMPSUB = 0xb3
190-
ENDSUB = 0xb7
191-
192-
193190
#
194191
# System
195192
#

tests/core/opcodes/test_opcodes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,3 +1172,5 @@ def test_jumpsub(vm_class, code, expect_gas_used):
11721172
)
11731173
assert comp.is_success
11741174
assert comp.get_gas_used() == expect_gas_used
1175+
1176+
test_jumpsub(BerlinVM, '0x60045e005c5d', 18)

0 commit comments

Comments
 (0)