Skip to content

test_push_truncated_data()

Documentation for tests/benchmark/compute/instruction/test_stack.py::test_push_truncated_data@c17999c0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_stack.py::test_push_truncated_data --gas-benchmark-values 1

Benchmark a PUSH whose data portion runs past the end of the code.

Source code in tests/benchmark/compute/instruction/test_stack.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@pytest.mark.parametrize(
    "opcode,present_data_bytes",
    [
        pytest.param(Op.PUSH1, 0, id="PUSH1 with no data"),
        pytest.param(Op.PUSH2, 0, id="PUSH2 with no data"),
        pytest.param(Op.PUSH2, 1, id="PUSH2 with half its data"),
        pytest.param(Op.PUSH32, 0, id="PUSH32 with no data"),
        pytest.param(Op.PUSH32, 16, id="PUSH32 with half its data"),
        pytest.param(Op.PUSH32, 31, id="PUSH32 one byte short"),
    ],
)
def test_push_truncated_data(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    opcode: Op,
    present_data_bytes: int,
) -> None:
    """
    Benchmark a PUSH whose data portion runs past the end of the code.
    """
    target_contract = pre.deploy_contract(
        code=bytes([opcode.int()]) + bytes(present_data_bytes)
    )

    benchmark_test(
        target_opcode=OpcodeTarget(f"{opcode} truncated", Op.STATICCALL),
        code_generator=JumpLoopGenerator(
            attack_block=Op.POP(
                Op.STATICCALL(
                    gas=Op.GAS,
                    address=target_contract,
                    args_offset=Op.PUSH0,
                    args_size=Op.PUSH0,
                    ret_offset=Op.PUSH0,
                    ret_size=Op.PUSH0,
                )
            )
        ),
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 3 forks.