Skip to content

Commit 4a7d2ae

Browse files
committed
[WIP] Implement subroutine opcodes
1 parent 16bfead commit 4a7d2ae

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

eth/vm/forks/berlin/opcodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
opcode_values.JUMPSUB: as_opcode(
2323
logic_fn = flow.jumpsub,
2424
mnemonic = mnemonics.JUMPSUB,
25-
gas_cost = constants.GAS_MID,
25+
gas_cost = constants.GAS_HIGH,
2626
),
2727
opcode_values.RETURNSUB: as_opcode(
2828
logic_fn = flow.returnsub,
2929
mnemonic = mnemonics.RETURNSUB,
30-
gas_cost = constants.GAS_VERYLOW,
30+
gas_cost = constants.GAS_LOW,
3131
),
3232
}
3333

eth/vm/logic/flow.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,19 @@ def jumpsub(computation: BaseComputation) -> None:
7171

7272
if computation.code.is_valid_opcode(sub_loc):
7373

74-
sub_op = computation.code.is_valid_opcode(sub_loc)
74+
sub_op = computation.code[sub_loc]
7575

7676
if sub_op == BEGINSUB:
7777
temp = computation.code.program_counter
7878
computation.code.program_counter = sub_loc + 1
79-
computation.rstack_push_int(temp + 1)
79+
computation.rstack_push_int(temp)
8080

8181

8282
def returnsub(computation: BaseComputation) -> None:
83-
8483
try:
8584
ret_loc = computation.rstack_pop1_int()
8685
except InsufficientStack:
87-
pass
86+
raise InsufficientStack("Error: at pc={}, op=RETURNSUB: invalid retsub".format(computation.code.program_counter))
8887

8988

9089
computation.code.program_counter = ret_loc

eth/vm/opcode_values.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@
9191
MSIZE = 0x59
9292
GAS = 0x5a
9393
JUMPDEST = 0x5b
94+
95+
9496
#
9597
# Subroutines
9698
#
9799
BEGINSUB = 0x5c
98100
RETURNSUB = 0x5d
99101
JUMPSUB = 0x5e
100102

103+
101104
#
102105
# Push Operations
103106
#

eth/vm/rstack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self) -> None:
3636
self._pop_typed = values.pop
3737
self.__len__ = values.__len__
3838

39-
def push_int(self) -> int:
39+
def push_int(self, value) -> int:
4040
if len(self.values) > 1023:
4141
raise FullStack('Stack limit reached')
4242

0 commit comments

Comments
 (0)