Skip to content

Commit 952f876

Browse files
committed
new(tests): extend RJUMP* to self tests with variadic stack
Extend the existing RJUMP/RJUMPI/RJUMPV to self with variadic stack height by parametrized spread. This finishes conversion of jump to self from ethereum/tests.
1 parent 13aeeed commit 952f876

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

Diff for: converted-ethereum-tests.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ EOFTests/efStack/forwards_rjumpv_variable_stack_.json
4747
EOFTests/efStack/underflow_.json
4848
EOFTests/efStack/underflow_variable_stack_.json
4949
EOFTests/efStack/unreachable_instructions_.json
50+
EOFTests/efStack/self_referencing_jumps_.json
51+
EOFTests/efStack/self_referencing_jumps_variable_stack_.json
5052
EOFTests/efValidation/callf_into_nonreturning_.json
5153
EOFTests/efValidation/dataloadn_.json
5254
EOFTests/efValidation/EOF1_embedded_container_.json
5355
EOFTests/efValidation/EOF1_eofcreate_valid_.json
5456
EOFTests/efValidation/EOF1_callf_truncated_.json
5557
EOFTests/efValidation/EOF1_code_section_missing_.json
5658
EOFTests/efValidation/EOF1_dataloadn_truncated_.json
57-
EOFTests/efValidation/EOF1_eofcreate_invalid_.py
58-
EOFTests/efValidation/EOF1_multiple_type_sections_.py
59+
EOFTests/efValidation/EOF1_eofcreate_invalid_.json
60+
EOFTests/efValidation/EOF1_multiple_type_sections_.json
5961
EOFTests/efValidation/EOF1_no_type_section_.json
6062
EOFTests/efValidation/EOF1_valid_rjump_.json
6163
EOFTests/efValidation/EOF1_valid_rjumpi_.json

Diff for: tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjump.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ethereum_test_tools.vm.opcode import Opcodes as Op
77
from ethereum_test_types.eof.v1 import Container, Section
88
from ethereum_test_types.eof.v1.constants import MAX_BYTECODE_SIZE
9+
from ethereum_test_vm import Bytecode
910

1011
from .. import EOF_FORK_NAME
1112
from .helpers import JumpDirection, slot_code_worked, value_code_worked
@@ -249,12 +250,19 @@ def test_rjump_into_self_remaining_code(
249250
)
250251

251252

253+
@pytest.mark.parametrize("stack_height_spread", [-1, 0, 1, 2])
252254
def test_rjump_into_self(
253255
eof_test: EOFTestFiller,
256+
stack_height_spread: int,
254257
):
255258
"""EOF code containing RJUMP with target self RJUMP."""
259+
# Create variadic stack height by the parametrized spread.
260+
stack_spread_code = Bytecode()
261+
if stack_height_spread >= 0:
262+
stack_spread_code = Op.RJUMPI[stack_height_spread](0) + Op.PUSH0 * stack_height_spread
263+
256264
eof_test(
257-
container=Container.Code(Op.RJUMP[-len(Op.RJUMP[0])]),
265+
container=Container.Code(stack_spread_code + Op.RJUMP[-len(Op.RJUMP[0])]),
258266
)
259267

260268

Diff for: tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ethereum_test_tools.vm.opcode import Opcodes as Op
1616
from ethereum_test_types.eof.v1 import Container, Section
1717
from ethereum_test_types.eof.v1.constants import MAX_BYTECODE_SIZE
18+
from ethereum_test_vm import Bytecode
1819

1920
from .. import EOF_FORK_NAME
2021
from .helpers import (
@@ -1069,15 +1070,25 @@ def test_rjumpi_into_self_data_portion(
10691070
)
10701071

10711072

1073+
@pytest.mark.parametrize("stack_height_spread", [-1, 0, 1, 2])
10721074
def test_rjumpi_into_self(
10731075
eof_test: EOFTestFiller,
1076+
stack_height_spread: int,
10741077
):
1075-
"""EOF1I4200_0021 (Invalid) EOF code containing RJUMPI with target same RJUMPI immediate."""
1078+
"""
1079+
EOF code containing RJUMPI targeting itself (-3).
1080+
This can never be valid because this is backward jump and RJUMPI consumes one stack item.
1081+
"""
1082+
# Create variadic stack height by the parametrized spread.
1083+
stack_spread_code = Bytecode()
1084+
if stack_height_spread >= 0:
1085+
stack_spread_code = Op.RJUMPI[stack_height_spread](0) + Op.PUSH0 * stack_height_spread
1086+
10761087
eof_test(
10771088
container=Container(
10781089
sections=[
10791090
Section.Code(
1080-
code=Op.PUSH1(1) + Op.RJUMPI[-len(Op.RJUMPI[0])] + Op.STOP,
1091+
code=stack_spread_code + Op.RJUMPI[-len(Op.RJUMPI[0])](0) + Op.STOP,
10811092
)
10821093
],
10831094
),

Diff for: tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ethereum_test_tools import Account, EOFException, EOFStateTestFiller, EOFTestFiller
66
from ethereum_test_tools.vm.opcode import Opcodes as Op
77
from ethereum_test_types.eof.v1 import Container, Section
8+
from ethereum_test_vm import Bytecode
89

910
from .. import EOF_FORK_NAME
1011
from .helpers import JumpDirection, slot_code_worked, slot_conditional_result, value_code_worked
@@ -481,20 +482,31 @@ def test_rjumpv_into_self_data_portion(
481482
pytest.param(256, 255, id="t256i255"),
482483
],
483484
)
485+
@pytest.mark.parametrize("stack_height_spread", [-1, 0, 1, 2])
484486
def test_rjumpv_into_self(
485487
eof_test: EOFTestFiller,
486488
table_size: int,
487489
invalid_index: int,
490+
stack_height_spread: int,
488491
):
489-
"""EOF code containing RJUMPV with target same RJUMPV immediate."""
492+
"""
493+
EOF code containing RJUMPV targeting itself.
494+
This can never be valid because this is backward jump and RJUMPV consumes one stack item.
495+
"""
496+
# Create variadic stack height by the parametrized spread.
497+
stack_spread_code = Bytecode()
498+
if stack_height_spread >= 0:
499+
stack_spread_code = Op.RJUMPI[stack_height_spread](0) + Op.PUSH0 * stack_height_spread
500+
490501
jump_table = [0 for _ in range(table_size)]
491502
jump_table[invalid_index] = -len(Op.RJUMPV[jump_table])
492503

493504
eof_test(
494505
container=Container(
495506
sections=[
496507
Section.Code(
497-
code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
508+
code=stack_spread_code + Op.RJUMPV[jump_table](0) + Op.STOP,
509+
# max stack increase is computed correctly
498510
)
499511
],
500512
),
@@ -517,13 +529,13 @@ def test_rjumpv_into_stack_height_diff(
517529
):
518530
"""EOF code containing RJUMPV with target instruction that causes stack height difference."""
519531
jump_table = [0 for _ in range(table_size)]
520-
jump_table[invalid_index] = -(len(Op.RJUMPV[jump_table]) + len(Op.PUSH1(0)) + len(Op.PUSH1(0)))
532+
jump_table[invalid_index] = -(len(Op.RJUMPV[jump_table]) + len(Op.PUSH1[0]) + len(Op.PUSH1[0]))
521533

522534
eof_test(
523535
container=Container(
524536
sections=[
525537
Section.Code(
526-
code=Op.PUSH1(0) + Op.PUSH1(0) + Op.RJUMPV[jump_table] + Op.STOP,
538+
code=Op.PUSH1[0] + Op.PUSH1[0] + Op.RJUMPV[jump_table] + Op.STOP,
527539
),
528540
],
529541
),

Diff for: tests/osaka/eip7692_eof_v1/eof_tracker.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
- [x] Valid RJUMP forwards from different stack in variable stack segment ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjump.py::test_rjump_valid_forward`](./eip4200_relative_jumps/test_rjump/test_rjump_valid_forward.md)
184184
- [ ] Valid empty infinite loop with RJUMP (ethereum/tests: src/EOFTestsFiller/EIP5450/validInvalidFiller.yml)
185185
- [ ] Valid balanced infinite loop (ethereum/tests: src/EOFTestsFiller/EIP5450/validInvalidFiller.yml)
186+
- [x] RJUMP to self (including variadic stack height) ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjump.py::test_rjump_into_self`](./eip4200_relative_jumps/test_rjump/test_rjump_into_self.md))
186187

187188
##### RJUMPI
188189

@@ -203,6 +204,7 @@
203204
- [x] If-then-else with equal stack height in branches, variable stack segment ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py::test_rjumpi_valid_forward`](./eip4200_relative_jumps/test_rjumpi/test_rjumpi_valid_forward.md)
204205
- [x] If-then-else with different stack height in branches ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py::test_rjumpi_valid_forward`](./eip4200_relative_jumps/test_rjumpi/test_rjumpi_valid_forward.md)
205206
- [x] If-then-else with different stack height in branches, variable stack segment ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py::test_rjumpi_valid_forward`](./eip4200_relative_jumps/test_rjumpi/test_rjumpi_valid_forward.md)
207+
- [x] RJUMPI to self (including variadic stack height) ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py::test_rjumpi_into_self`](./eip4200_relative_jumps/test_rjumpi/test_rjumpi_into_self.md))
206208

207209
##### RJUMPV
208210

@@ -219,6 +221,7 @@
219221
- [x] Switch with equal stack height in branches, variable stack segment ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py::test_rjumpv_valid_forward`](./eip4200_relative_jumps/test_rjumpv/test_rjumpv_valid_forward.md)
220222
- [x] Switch with different stack height in branches ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py::test_rjumpv_valid_forward`](./eip4200_relative_jumps/test_rjumpv/test_rjumpv_valid_forward.md)
221223
- [x] Switch with different stack height in branches, variable stack segment ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py::test_rjumpv_valid_forward`](./eip4200_relative_jumps/test_rjumpv/test_rjumpv_valid_forward.md)
224+
- [x] RJUMPV to self (including variadic stack height) ([`tests/osaka/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py::test_rjumpv_into_self`](./eip4200_relative_jumps/test_rjumpv/test_rjumpv_into_self.md))
222225

223226
##### Combinations
224227

@@ -232,9 +235,6 @@
232235
- [ ] RJUMP and RJUMPV with the same target and different stack height in a variable stack segment (ethereum/tests: src/EOFTestsFiller/efStack/forwards_rjumpv_variable_stack_Copier.json)
233236
- [ ] RJUMPI and RJUMPV with the same target
234237

235-
- [ ] RJUMP* to self (ethereum/tests: src/EOFTestsFiller/efStack/self_referencing_jumps_Copier.json)
236-
- [ ] RJUMP* to self in a variable stack segment (ethereum/tests: src/EOFTestsFiller/efStack/self_referencing_jumps_variable_stack_Copier.json)
237-
238238
#### Stack underflow
239239

240240
- [x] Stack underflows ([`tests/osaka/eip7692_eof_v1/eip5450_stack/test_code_validation.py::test_all_opcodes_stack_underflow`](./eip5450_stack/test_code_validation/test_all_opcodes_stack_underflow.md))

0 commit comments

Comments
 (0)