Skip to content

test_jumpf_stack_overflow()

Documentation for tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py::test_jumpf_stack_overflow@83970623.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py::test_jumpf_stack_overflow --fork Osaka

Test rule #2 in execution semantics, where we make sure we have enough stack to guarantee safe execution (the "reserved stack rule") max possible stack will not exceed 1024. But some executions may not overflow the stack, so we need to ensure the rule is checked.

no_overflow - the stack does not overflow at JUMPF call, executes to end rule_overflow - reserved stack rule triggers, but execution would not overflow if allowed execution_overflow - execution would overflow (but still blocked by reserved stack rule)

Source code in tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
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
464
465
466
467
468
469
470
471
@pytest.mark.parametrize(
    ("stack_height", "failure"),
    (
        pytest.param(1021, False, id="no_overflow"),
        pytest.param(1022, True, id="rule_overflow"),
        pytest.param(1023, True, id="execution_overflow"),
    ),
)
def test_jumpf_stack_overflow(
    stack_height: int,
    failure: bool,
    eof_state_test: EOFStateTestFiller,
):
    """
    Test rule #2 in execution semantics, where we make sure we have enough stack to guarantee
    safe execution (the "reserved stack rule") max possible stack will not exceed 1024. But some
    executions may not overflow the stack, so we need to ensure the rule is checked.

    `no_overflow` - the stack does not overflow at JUMPF call, executes to end
    `rule_overflow` - reserved stack rule triggers, but execution would not overflow if allowed
    `execution_overflow` - execution would overflow (but still blocked by reserved stack rule)
    """
    eof_state_test(
        container=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH0 * stack_height
                    + Op.CALLF[1]
                    + Op.POP * stack_height
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.RETURN(0, 0),
                    max_stack_height=stack_height,
                ),
                Section.Code(
                    # Stack has stack_height items
                    Op.JUMPF[2],
                    code_inputs=0,
                    code_outputs=0,
                    max_stack_height=0,
                ),
                Section.Code(
                    Op.CALLDATALOAD(0)
                    + Op.ISZERO
                    + Op.RJUMPI[6]
                    + Op.PUSH0 * 3
                    + Op.POP * 3
                    + Op.SSTORE(slot_stack_canary, value_canary_written)
                    + Op.RETF,
                    code_inputs=0,
                    code_outputs=0,
                    max_stack_height=3,
                ),
            ],
        ),
        container_post=Account(
            storage={
                slot_code_worked: 0 if failure else value_code_worked,
                slot_stack_canary: 0 if failure else value_canary_written,
            }
        ),
    )

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated) stack_height failure
...fork_Osaka-eof_test-no_overflow 1021 False
...fork_Osaka-eof_test-rule_overflow 1022 True
...fork_Osaka-eof_test-execution_overflow 1023 True
...fork_Osaka-state_test-no_overflow 1021 False
...fork_Osaka-state_test-rule_overflow 1022 True
...fork_Osaka-state_test-execution_overflow 1023 True
...fork_Osaka-blockchain_test-no_overflow 1021 False
...fork_Osaka-blockchain_test-rule_overflow 1022 True
...fork_Osaka-blockchain_test-execution_overflow 1023 True