Skip to content

Test Rjumpv

Documentation for tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py --fork=Prague --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Prague:
fill -v tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

EOF JUMPF tests covering stack and code validation rules.

test_rjumpv_condition(eof_state_test, calldata, table_size)

Test RJUMPV contract switching based on external input

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@pytest.mark.parametrize(
    "calldata",
    [
        pytest.param(0, id="c0"),
        pytest.param(1, id="c1"),
        pytest.param(3, id="c3"),
        pytest.param(255, id="c255"),
        pytest.param(256, id="c256"),
        pytest.param(2**256 - 1, id="c2^256-1"),
    ],
)
@pytest.mark.parametrize(
    "table_size",
    [
        pytest.param(1, id="t1"),
        pytest.param(3, id="t3"),
        pytest.param(256, id="t256"),
    ],
)
def test_rjumpv_condition(
    eof_state_test: EOFStateTestFiller,
    calldata: int,
    table_size: int,
):
    """Test RJUMPV contract switching based on external input"""
    value_fall_through = 0xFFFF
    value_base = 0x1000  # Force a `PUSH2` instruction to be used on all targets
    target_length = 7
    jump_table = [(i + 1) * target_length for i in range(table_size)]

    jump_targets = sum(
        (Op.SSTORE(slot_conditional_result, i + value_base) + Op.STOP) for i in range(table_size)
    )

    fall_through_case = Op.SSTORE(slot_conditional_result, value_fall_through) + Op.STOP

    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH0
                    + Op.CALLDATALOAD
                    + Op.RJUMPV[jump_table]
                    + fall_through_case
                    + jump_targets,
                )
            ]
        ),
        tx_data=calldata.to_bytes(32, "big"),
        container_post=Account(
            storage={
                slot_conditional_result: calldata + value_base
                if calldata < table_size
                else value_fall_through,
            }
        ),
    )

test_rjumpv_forwards(eof_state_test)

EOF1V4200_0008 (Valid) EOF with RJUMPV table size 1 (Positive)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def test_rjumpv_forwards(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0008 (Valid) EOF with RJUMPV table size 1 (Positive)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0)
                    + Op.RJUMPV[3]
                    + Op.NOOP
                    + Op.NOOP
                    + Op.STOP
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_backwards(eof_state_test)

EOF1V4200_0009 (Valid) EOF with RJUMPV table size 1 (Negative)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def test_rjumpv_backwards(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0009 (Valid) EOF with RJUMPV table size 1 (Negative)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0)
                    + Op.RJUMPI[7]
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP
                    + Op.PUSH1(0)
                    + Op.RJUMPV[-13]
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_zero(eof_state_test)

EOF1V4200_0010 (Valid) EOF with RJUMPV table size 1 (Zero)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def test_rjumpv_zero(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0010 (Valid) EOF with RJUMPV table size 1 (Zero)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0)
                    + Op.RJUMPV[0]
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_size_3(eof_state_test)

EOF1V4200_0011 (Valid) EOF with RJUMPV table size 3

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def test_rjumpv_size_3(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0011 (Valid) EOF with RJUMPV table size 3"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0)
                    + Op.RJUMPV[3, 0, -10]
                    + Op.NOOP
                    + Op.NOOP
                    + Op.STOP
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_full_table(eof_state_test)

EOF1V4200_0012 (Valid) EOF with RJUMPV table size 256 (Target 0)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def test_rjumpv_full_table(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0012 (Valid) EOF with RJUMPV table size 256 (Target 0)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0)
                    + Op.RJUMPV[range(256)]
                    + Op.NOOP * 256
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_full_table_mid(eof_state_test)

EOF1V4200_0013 (Valid) EOF with RJUMPV table size 256 (Target 100)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def test_rjumpv_full_table_mid(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0013 (Valid) EOF with RJUMPV table size 256 (Target 100)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(100)
                    + Op.RJUMPV[range(256)]
                    + Op.NOOP * 256
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_full_table_end(eof_state_test)

EOF1V4200_0014 (Valid) EOF with RJUMPV table size 256 (Target 254)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def test_rjumpv_full_table_end(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0014 (Valid) EOF with RJUMPV table size 256 (Target 254)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(254)
                    + Op.RJUMPV[range(256)]
                    + Op.NOOP * 256
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_full_table_last(eof_state_test)

EOF1V4200_0015 (Valid) EOF with RJUMPV table size 256 (Target 256)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
def test_rjumpv_full_table_last(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0015 (Valid) EOF with RJUMPV table size 256 (Target 256)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH2(256)
                    + Op.RJUMPV[range(256)]
                    + Op.NOOP * 256
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_max_forwards(eof_state_test)

EOF1V4200_0016 (Valid) EOF with RJUMPV containing the maximum offset (32767)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def test_rjumpv_max_forwards(
    eof_state_test: EOFStateTestFiller,
):
    """EOF1V4200_0016 (Valid) EOF with RJUMPV containing the maximum offset (32767)"""
    eof_state_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1)
                    + Op.RJUMPV[32767]
                    + Op.NOOP * 32768
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                )
            ],
        ),
        container_post=Account(storage={slot_code_worked: value_code_worked}),
    )

test_rjumpv_truncated_empty(eof_test)

EOF1I4200_0027 (Invalid) EOF code containing RJUMPV with max_index 0 but no immediates

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def test_rjumpv_truncated_empty(
    eof_test: EOFTestFiller,
):
    """EOF1I4200_0027 (Invalid) EOF code containing RJUMPV with max_index 0 but no immediates"""
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV,
                )
            ],
        ),
        expect_exception=EOFException.TRUNCATED_INSTRUCTION,
    )

test_rjumpv_truncated(eof_test, branches, byte_count_last_branch)

EOF1I4200_0028/29/30/31 (Invalid) EOF code containing truncated RJUMPV

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
@pytest.mark.parametrize(
    "branches",
    [1, 2, 256],
)
@pytest.mark.parametrize(
    "byte_count_last_branch",
    [0, 1],
)
def test_rjumpv_truncated(
    eof_test: EOFTestFiller,
    branches: int,
    byte_count_last_branch: int,
):
    """EOF1I4200_0028/29/30/31 (Invalid) EOF code containing truncated RJUMPV"""
    rjumpv_bytes = int.to_bytes(branches - 1, 1, "big")
    rjumpv_bytes += b"\0" * ((2 * (branches - 1)) + byte_count_last_branch)

    eof_test(
        data=Container.Code(code=Op.PUSH1(1) + Op.RJUMPV[rjumpv_bytes]),
        expect_exception=EOFException.TRUNCATED_INSTRUCTION,
    )

test_rjumpv_into_header(eof_test, table_size, invalid_index)

EOF1I4200_0031 (Invalid) EOF code containing RJUMPV with target outside code bounds (Jumping into header)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_header(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """
    EOF1I4200_0031 (Invalid) EOF code containing RJUMPV with target outside code bounds
    (Jumping into header)
    """
    invalid_destination = -5 - (2 * table_size)
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_before_container(eof_test, table_size, invalid_index)

EOF1I4200_0032 (Invalid) EOF code containing RJUMPV with target outside code bounds (Jumping to before code begin)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_before_container(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """
    EOF1I4200_0032 (Invalid) EOF code containing RJUMPV with target outside code bounds
    (Jumping to before code begin)
    """
    invalid_destination = -13 - (2 * table_size)
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_data(eof_test, table_size, invalid_index)

EOF1I4200_0033 (Invalid) EOF code containing RJUMPV with target outside code bounds (Jumping into data section)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_data(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """
    EOF1I4200_0033 (Invalid) EOF code containing RJUMPV with target outside code bounds
    (Jumping into data section)
    """
    invalid_destination = 2
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                ),
                Section.Data(data=b"\xaa\xbb\xcc"),
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_after_container(eof_test, table_size, invalid_index)

EOF1I4200_0034 (Invalid) EOF code containing RJUMPV with target outside code bounds (Jumping to after code end)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_after_container(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """
    EOF1I4200_0034 (Invalid) EOF code containing RJUMPV with target outside code bounds
    (Jumping to after code end)
    """
    invalid_destination = 2
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_at_end(eof_test, table_size, invalid_index)

EOF1I4200_0035 (Invalid) EOF code containing RJUMPV with target outside code bounds (Jumping to code end)

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_at_end(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """
    EOF1I4200_0035 (Invalid) EOF code containing RJUMPV with target outside code bounds
    (Jumping to code end)
    """
    invalid_destination = 1
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_self_data_portion(eof_test, table_size, invalid_index, data_portion_end)

EOF1I4200_0036 (Invalid) EOF code containing RJUMPV with target same RJUMPV immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
@pytest.mark.parametrize(
    "data_portion_end",
    [True, False],
    ids=["data_portion_end", "data_portion_start"],
)
def test_rjumpv_into_self_data_portion(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
    data_portion_end: bool,
):
    """EOF1I4200_0036 (Invalid) EOF code containing RJUMPV with target same RJUMPV immediate"""
    invalid_destination = -1 if data_portion_end else -(2 * table_size) - 1
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_self(eof_test, table_size, invalid_index)

EOF code containing RJUMPV with target same RJUMPV immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_self(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMPV with target same RJUMPV immediate"""
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = -len(Op.RJUMPV[jump_table])

    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.STACK_HEIGHT_MISMATCH,
    )

test_rjumpv_into_stack_height_diff(eof_test, table_size, invalid_index)

EOF code containing RJUMPV with target instruction that causes stack height difference

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_stack_height_diff(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMPV with target instruction that causes stack height difference"""
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = -(len(Op.RJUMPV[jump_table]) + len(Op.PUSH1(0)) + len(Op.PUSH1(0)))

    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0) + Op.PUSH1(0) + Op.RJUMPV[jump_table] + Op.STOP,
                ),
            ],
        ),
        expect_exception=EOFException.STACK_HEIGHT_MISMATCH,
    )

test_rjumpv_into_stack_underflow(eof_test, table_size, invalid_index)

EOF code containing RJUMPV with target instruction that cause stack underflow

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_stack_underflow(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMPV with target instruction that cause stack underflow"""
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = 1
    eof_test(
        data=Container(
            sections=[
                Section.Code(code=Op.ORIGIN + Op.RJUMPV[jump_table] + Op.STOP + Op.POP + Op.STOP),
            ],
        ),
        expect_exception=EOFException.STACK_UNDERFLOW,
    )

test_rjumpv_skips_stack_underflow(eof_test, table_size)

EOF code containing RJUMPV where the default path produces a stack underflow

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
@pytest.mark.parametrize(
    "table_size",
    [
        pytest.param(1, id="t1"),
        pytest.param(256, id="t256"),
    ],
)
def test_rjumpv_skips_stack_underflow(
    eof_test: EOFTestFiller,
    table_size: int,
):
    """EOF code containing RJUMPV where the default path produces a stack underflow"""
    jump_table = [1 for _ in range(table_size)]
    eof_test(
        data=Container(
            sections=[
                Section.Code(code=Op.ORIGIN + Op.RJUMPV[jump_table] + Op.POP + Op.STOP),
            ],
        ),
        expect_exception=EOFException.STACK_UNDERFLOW,
    )

test_rjumpv_into_rjump(eof_test, table_size, invalid_index, data_portion_end)

EOF1I4200_0037 (Invalid) EOF code containing RJUMPV with target RJUMP immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
@pytest.mark.parametrize(
    "data_portion_end",
    [True, False],
    ids=["data_portion_end", "data_portion_start"],
)
def test_rjumpv_into_rjump(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
    data_portion_end: bool,
):
    """EOF1I4200_0037 (Invalid) EOF code containing RJUMPV with target RJUMP immediate"""
    invalid_destination = 3 if data_portion_end else 2
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    if table_size > 1:
        valid_index = 0
        if valid_index == invalid_index:
            valid_index += 1
        jump_table[valid_index] = 1
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP + Op.RJUMP[0] + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_rjumpi(eof_test, table_size, invalid_index, data_portion_end)

EOF1I4200_0038 (Invalid) EOF code containing RJUMPV with target RJUMPI immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
@pytest.mark.parametrize(
    "data_portion_end",
    [True, False],
    ids=["data_portion_end", "data_portion_start"],
)
def test_rjumpv_into_rjumpi(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
    data_portion_end: bool,
):
    """EOF1I4200_0038 (Invalid) EOF code containing RJUMPV with target RJUMPI immediate"""
    invalid_destination = 5 if data_portion_end else 4
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    if table_size > 1:
        valid_index = 0
        if valid_index == invalid_index:
            valid_index += 1
        jump_table[valid_index] = 1
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1)
                    + Op.RJUMPV[jump_table]
                    + Op.STOP
                    + Op.PUSH1(1)
                    + Op.RJUMPI[0]
                    + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_push_1(eof_test, jump, table_size, invalid_index)

EOF1I4200_0039 (Invalid) EOF code containing RJUMPV with target PUSH1 immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
@pytest.mark.parametrize("jump", [JumpDirection.FORWARD, JumpDirection.BACKWARD])
def test_rjumpv_into_push_1(
    eof_test: EOFTestFiller,
    jump: JumpDirection,
    table_size: int,
    invalid_index: int,
):
    """EOF1I4200_0039 (Invalid) EOF code containing RJUMPV with target PUSH1 immediate"""
    if jump == JumpDirection.FORWARD:
        invalid_destination = 2
        jump_table = [0 for _ in range(table_size)]
        jump_table[invalid_index] = invalid_destination
        code = (
            Op.PUSH1(1)
            + Op.RJUMPV[jump_table]
            + Op.STOP
            + Op.PUSH1(1)
            + Op.PUSH1(1)
            + Op.SSTORE
            + Op.STOP
        )
    else:
        invalid_destination = -(2 * table_size) - 3
        jump_table = [0 for _ in range(table_size)]
        jump_table[invalid_index] = invalid_destination
        code = Op.PUSH1(1) + Op.RJUMPV[jump_table] + Op.STOP
    eof_test(
        data=Container(
            sections=[Section.Code(code=code)],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_push_n(eof_test, opcode, jump, table_size, invalid_index, data_portion_end)

EOF1I4200_0039 (Invalid) EOF code containing RJUMPV with target PUSH1 immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
@pytest.mark.parametrize(
    "opcode",
    [
        Op.PUSH2,
        Op.PUSH3,
        Op.PUSH4,
        Op.PUSH5,
        Op.PUSH6,
        Op.PUSH7,
        Op.PUSH8,
        Op.PUSH9,
        Op.PUSH10,
        Op.PUSH11,
        Op.PUSH12,
        Op.PUSH13,
        Op.PUSH14,
        Op.PUSH15,
        Op.PUSH16,
        Op.PUSH17,
        Op.PUSH18,
        Op.PUSH19,
        Op.PUSH20,
        Op.PUSH21,
        Op.PUSH22,
        Op.PUSH23,
        Op.PUSH24,
        Op.PUSH25,
        Op.PUSH26,
        Op.PUSH27,
        Op.PUSH28,
        Op.PUSH29,
        Op.PUSH30,
        Op.PUSH31,
        Op.PUSH32,
    ],
)
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
@pytest.mark.parametrize(
    "data_portion_end",
    [True, False],
    ids=["data_portion_end", "data_portion_start"],
)
@pytest.mark.parametrize("jump", [JumpDirection.FORWARD, JumpDirection.BACKWARD])
def test_rjumpv_into_push_n(
    eof_test: EOFTestFiller,
    opcode: Op,
    jump: JumpDirection,
    table_size: int,
    invalid_index: int,
    data_portion_end: bool,
):
    """EOF1I4200_0039 (Invalid) EOF code containing RJUMPV with target PUSH1 immediate"""
    data_portion_length = int.from_bytes(opcode, byteorder="big") - 0x5F
    if jump == JumpDirection.FORWARD:
        invalid_destination = data_portion_length + 1 if data_portion_end else 2
        jump_table = [0 for _ in range(table_size)]
        jump_table[invalid_index] = invalid_destination
        code = (
            Op.PUSH1(1)
            + Op.RJUMPV[jump_table]
            + Op.STOP
            + opcode[1]
            + Op.PUSH1(1)
            + Op.SSTORE
            + Op.STOP
        )
    else:
        invalid_destination = (
            -(2 * table_size) - 3
            if data_portion_end
            else -(2 * table_size) - 2 - data_portion_length
        )
        jump_table = [0 for _ in range(table_size)]
        jump_table[invalid_index] = invalid_destination
        code = opcode[1] + Op.RJUMPV[jump_table] + Op.STOP
    eof_test(
        data=Container(
            sections=[Section.Code(code=code)],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_rjumpv(eof_test, source_table_size, target_table_size, invalid_index, data_portion_end)

EOF1I4200_0040 (Invalid) EOF code containing RJUMPV with target other RJUMPV immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
@pytest.mark.parametrize(
    "source_table_size,invalid_index",
    [
        pytest.param(1, 0, id="s1i0"),
        pytest.param(256, 0, id="s256i0"),
        pytest.param(256, 255, id="s256i255"),
    ],
)
@pytest.mark.parametrize("target_table_size", [1, 256], ids=["t1", "t256"])
@pytest.mark.parametrize(
    "data_portion_end",
    [True, False],
    ids=["data_portion_end", "data_portion_start"],
)
def test_rjumpv_into_rjumpv(
    eof_test: EOFTestFiller,
    source_table_size: int,
    target_table_size: int,
    invalid_index: int,
    data_portion_end: bool,
):
    """EOF1I4200_0040 (Invalid) EOF code containing RJUMPV with target other RJUMPV immediate"""
    invalid_destination = 4 + (2 * target_table_size) if data_portion_end else 4
    source_jump_table = [0 for _ in range(source_table_size)]
    source_jump_table[invalid_index] = invalid_destination
    target_jump_table = [0 for _ in range(target_table_size)]
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1)
                    + Op.RJUMPV[source_jump_table]
                    + Op.STOP
                    + Op.PUSH1(1)
                    + Op.RJUMPV[target_jump_table]
                    + Op.STOP,
                )
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_callf(eof_test, table_size, invalid_index, data_portion_end)

EOF1I4200_0041 (Invalid) EOF code containing RJUMPV with target CALLF immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
@pytest.mark.parametrize(
    "data_portion_end",
    [True, False],
    ids=["data_portion_end", "data_portion_start"],
)
def test_rjumpv_into_callf(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
    data_portion_end: bool,
):
    """EOF1I4200_0041 (Invalid) EOF code containing RJUMPV with target CALLF immediate"""
    invalid_destination = 2 if data_portion_end else 1
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0) + Op.RJUMPV[jump_table] + Op.CALLF[1] + Op.STOP,
                ),
                Section.Code(
                    code=Op.SSTORE(1, 1) + Op.RETF,
                    code_outputs=0,
                ),
            ]
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_dupn(eof_test, table_size, invalid_index)

EOF code containing RJUMP with target DUPN immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_dupn(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMP with target DUPN immediate"""
    invalid_destination = 1
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1)
                    + Op.PUSH1(1)
                    + Op.PUSH1(0)
                    + Op.RJUMPV[jump_table]
                    + Op.DUPN[1]
                    + Op.SSTORE
                    + Op.STOP,
                ),
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_swapn(eof_test, table_size, invalid_index)

EOF code containing RJUMP with target SWAPN immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_swapn(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMP with target SWAPN immediate"""
    invalid_destination = 1
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1)
                    + Op.PUSH1(1)
                    + Op.PUSH1(0)
                    + Op.RJUMPV[jump_table]
                    + Op.SWAPN[1]
                    + Op.SSTORE
                    + Op.STOP,
                ),
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjump_into_exchange(eof_test, table_size, invalid_index)

EOF code containing RJUMP with target EXCHANGE immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjump_into_exchange(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMP with target EXCHANGE immediate"""
    invalid_destination = 1
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(1)
                    + Op.PUSH1(2)
                    + Op.PUSH1(3)
                    + Op.PUSH1(0)
                    + Op.RJUMPV[1]
                    + Op.EXCHANGE[0x00]
                    + Op.SSTORE
                    + Op.STOP,
                ),
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_eofcreate(eof_test, table_size, invalid_index)

EOF code containing RJUMP with target EOFCREATE immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_eofcreate(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMP with target EOFCREATE immediate"""
    invalid_destination = 9
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH1(0)
                    + Op.RJUMPV[jump_table]
                    + Op.EOFCREATE[0](0, 0, 0, 0)
                    + Op.STOP,
                ),
                Section.Container(
                    container=Container(
                        sections=[
                            Section.Code(
                                code=Op.RETURNCONTRACT[0](0, 0),
                            ),
                            Section.Container(
                                container=Container(
                                    sections=[
                                        Section.Code(code=Op.STOP),
                                    ]
                                )
                            ),
                        ]
                    )
                ),
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_into_returncontract(eof_test, table_size, invalid_index)

EOF code containing RJUMP with target RETURNCONTRACT immediate

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
@pytest.mark.parametrize(
    "table_size,invalid_index",
    [
        pytest.param(1, 0, id="t1i0"),
        pytest.param(256, 0, id="t256i0"),
        pytest.param(256, 255, id="t256i255"),
    ],
)
def test_rjumpv_into_returncontract(
    eof_test: EOFTestFiller,
    table_size: int,
    invalid_index: int,
):
    """EOF code containing RJUMP with target RETURNCONTRACT immediate"""
    invalid_destination = 5
    jump_table = [0 for _ in range(table_size)]
    jump_table[invalid_index] = invalid_destination
    eof_test(
        data=Container(
            sections=[
                Section.Code(
                    code=Op.EOFCREATE[0](0, 0, 0, 0) + Op.STOP,
                ),
                Section.Container(
                    container=Container(
                        sections=[
                            Section.Code(
                                code=Op.PUSH1(0)
                                + Op.RJUMPV[jump_table]
                                + Op.RETURNCONTRACT[0](0, 0),
                            ),
                            Section.Container(
                                container=Container(
                                    sections=[
                                        Section.Code(code=Op.STOP),
                                    ]
                                )
                            ),
                        ]
                    )
                ),
            ],
        ),
        expect_exception=EOFException.INVALID_RJUMP_DESTINATION,
    )

test_rjumpv_backwards_reference_only(eof_test)

EOF code containing instructions only reachable by backwards RJUMPV

Source code in tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
def test_rjumpv_backwards_reference_only(
    eof_test: EOFTestFiller,
):
    """
    EOF code containing instructions only reachable by backwards RJUMPV
    """
    RJUMPV_LEN = len(Op.RJUMPV[0])
    container = Container.Code(
        code=(
            Op.RJUMP[RJUMP_LEN]
            + Op.RJUMP[RJUMPV_LEN + len(Op.ORIGIN)]
            + Op.ORIGIN
            + Op.RJUMPV[-(RJUMP_LEN + RJUMPV_LEN + len(Op.ORIGIN))]
            + Op.STOP
        )
    )
    eof_test(
        data=container,
        expect_exception=EOFException.UNREACHABLE_INSTRUCTIONS,
    )