Skip to content

Test Jumpf Stack

Documentation for tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_stack.py.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_stack.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/eip6206_jumpf/test_jumpf_stack.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

EOF JUMPF tests covering stack validation rules.

test_jumpf_stack_non_returning_rules(eof_state_test, target_inputs, stack_height)

Tests for JUMPF validation stack rules. Non-returning section cases. Valid cases are executed.

Source code in tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_stack.py
19
20
21
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
@pytest.mark.parametrize(
    "target_inputs",
    [0, 2, 4],
    ids=lambda x: "ti-%d" % x,
)
@pytest.mark.parametrize(
    "stack_height",
    [0, 2, 4],
    ids=lambda x: "h-%d" % x,
)
def test_jumpf_stack_non_returning_rules(
    eof_state_test: EOFStateTestFiller,
    target_inputs: int,
    stack_height: int,
):
    """
    Tests for JUMPF validation stack rules.  Non-returning section cases.
    Valid cases are executed.
    """
    container = Container(
        name="stack-non-retuning_h-%d_ti-%d" % (stack_height, target_inputs),
        sections=[
            Section.Code(
                code=Op.JUMPF[1],
            ),
            Section.Code(
                code=Op.PUSH0 * stack_height + Op.JUMPF[2],
                max_stack_height=stack_height,
            ),
            Section.Code(
                code=Op.POP * target_inputs
                + Op.SSTORE(slot_code_worked, value_code_worked)
                + Op.STOP,
                code_inputs=target_inputs,
                max_stack_height=max(2, target_inputs),
            ),
        ],
    )

    if stack_height < target_inputs:
        container.validity_error = EOFException.STACK_UNDERFLOW

    eof_state_test(
        data=container,
        container_post=Account(storage={slot_code_worked: value_code_worked}),
        tx_data=b"\1",
    )

test_jumpf_stack_returning_rules(eof_state_test, source_outputs, target_outputs, target_inputs, stack_diff)

Tests for JUMPF validation stack rules. Returning section cases. Valid cases are executed.

Source code in tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_stack.py
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@pytest.mark.parametrize(
    "source_outputs",
    [0, 2, 4],
    ids=lambda x: "so-%d" % x,
)
@pytest.mark.parametrize(
    "target_outputs",
    [0, 2, 4],
    ids=lambda x: "to-%d" % x,
)
@pytest.mark.parametrize(
    "target_inputs",
    [0, 2, 4],
    ids=lambda x: "to-%d" % x,
)
@pytest.mark.parametrize("stack_diff", [-1, 0, 1], ids=["less-stack", "same-stack", "more-stack"])
def test_jumpf_stack_returning_rules(
    eof_state_test: EOFStateTestFiller,
    source_outputs: int,
    target_outputs: int,
    target_inputs: int,
    stack_diff: int,
):
    """
    Tests for JUMPF validation stack rules.  Returning section cases.
    Valid cases are executed.
    """
    if target_outputs > source_outputs:
        # These create invalid containers without JUMPF validation, Don't test.
        return
    if target_inputs == 0 and stack_diff < 0:
        # Code generation is impossible for this configuration.  Don't test.
        return

    target_delta = target_outputs - target_inputs
    container = Container(
        name="stack-retuning_co-%d_to-%d_ti-%d_diff-%d"
        % (source_outputs, target_outputs, target_inputs, stack_diff),
        sections=[
            Section.Code(
                code=Op.CALLF[1] + Op.SSTORE(slot_code_worked, value_code_worked) + Op.STOP,
                max_stack_height=2 + source_outputs,
            ),
            Section.Code(
                code=Op.PUSH0 * max(0, target_inputs + stack_diff) + Op.JUMPF[2],
                code_outputs=source_outputs,
                max_stack_height=target_inputs,
            ),
            Section.Code(
                code=(Op.POP * -target_delta if target_delta < 0 else Op.PUSH0 * target_delta)
                + Op.RETF,
                code_inputs=target_inputs,
                code_outputs=target_outputs,
                max_stack_height=max(target_inputs, target_outputs),
            ),
        ],
    )

    if stack_diff < source_outputs - target_outputs:
        container.validity_error = EOFException.STACK_UNDERFLOW
    elif stack_diff > source_outputs - target_outputs:
        container.validity_error = EOFException.STACK_HIGHER_THAN_OUTPUTS

    eof_state_test(
        data=container,
        container_post=Account(storage={slot_code_worked: value_code_worked}),
        tx_data=b"\1",
    )