Skip to content

test_worst_returndatasize_nonzero()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_returndatasize_nonzero@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_returndatasize_nonzero -m benchmark

Test running a block which execute as many RETURNDATASIZE opcodes which return a non-zero buffer as possible.

The returned_size parameter indicates the size of the returned data buffer. The return_data_style indicates how returned data is produced for the opcode caller.

Source code in tests/benchmark/test_worst_compute.py
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
188
189
190
191
192
193
194
195
@pytest.mark.parametrize(
    "return_data_style",
    [
        ReturnDataStyle.RETURN,
        ReturnDataStyle.REVERT,
        ReturnDataStyle.IDENTITY,
    ],
)
@pytest.mark.parametrize("returned_size", [1, 0])
def test_worst_returndatasize_nonzero(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    returned_size: int,
    return_data_style: ReturnDataStyle,
) -> None:
    """
    Test running a block which execute as many RETURNDATASIZE opcodes which
    return a non-zero buffer as possible.

    The `returned_size` parameter indicates the size of the returned data
    buffer. The `return_data_style` indicates how returned data is produced for
    the opcode caller.
    """
    setup = Bytecode()
    if return_data_style != ReturnDataStyle.IDENTITY:
        setup += Op.STATICCALL(
            address=pre.deploy_contract(
                code=Op.REVERT(0, returned_size)
                if return_data_style == ReturnDataStyle.REVERT
                else Op.RETURN(0, returned_size)
            )
        )
    else:
        setup += Op.MSTORE8(0, 1) + Op.STATICCALL(
            address=0x04,  # Identity precompile
            args_size=returned_size,
        )

    benchmark_test(
        code_generator=JumpLoopGenerator(setup=setup, attack_block=Op.POP(Op.RETURNDATASIZE)),
    )

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated) returned_size return_data_style
...fork_Prague-blockchain_test-returned_size_1-return_data_style_ReturnDataStyle.RETURN 1 ReturnDataStyle.RETURN
...fork_Prague-blockchain_test-returned_size_1-return_data_style_ReturnDataStyle.REVERT 1 ReturnDataStyle.REVERT
...fork_Prague-blockchain_test-returned_size_1-return_data_style_ReturnDataStyle.IDENTITY 1 ReturnDataStyle.IDENTITY
...fork_Prague-blockchain_test-returned_size_0-return_data_style_ReturnDataStyle.RETURN 0 ReturnDataStyle.RETURN
...fork_Prague-blockchain_test-returned_size_0-return_data_style_ReturnDataStyle.REVERT 0 ReturnDataStyle.REVERT
...fork_Prague-blockchain_test-returned_size_0-return_data_style_ReturnDataStyle.IDENTITY 0 ReturnDataStyle.IDENTITY
...fork_Osaka-blockchain_test-returned_size_1-return_data_style_ReturnDataStyle.RETURN 1 ReturnDataStyle.RETURN
...fork_Osaka-blockchain_test-returned_size_1-return_data_style_ReturnDataStyle.REVERT 1 ReturnDataStyle.REVERT
...fork_Osaka-blockchain_test-returned_size_1-return_data_style_ReturnDataStyle.IDENTITY 1 ReturnDataStyle.IDENTITY
...fork_Osaka-blockchain_test-returned_size_0-return_data_style_ReturnDataStyle.RETURN 0 ReturnDataStyle.RETURN
...fork_Osaka-blockchain_test-returned_size_0-return_data_style_ReturnDataStyle.REVERT 0 ReturnDataStyle.REVERT
...fork_Osaka-blockchain_test-returned_size_0-return_data_style_ReturnDataStyle.IDENTITY 0 ReturnDataStyle.IDENTITY