test_returndatasize_nonzero()
Documentation for tests/benchmark/compute/instruction/test_call_context.py::test_returndatasize_nonzero@892e6d1e.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/benchmark/compute/instruction/test_call_context.py::test_returndatasize_nonzero --gas-benchmark-values 1
Benchmark RETURNDATASIZE instruction with non-zero buffer.
- returned_size: the size of the returned data buffer.
- return_data_style: how returned data is produced for the opcode caller.
Source code in tests/benchmark/compute/instruction/test_call_context.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312 | @pytest.mark.repricing(
return_data_style=ReturnDataStyle.IDENTITY,
)
@pytest.mark.parametrize(
"return_data_style",
[
ReturnDataStyle.RETURN,
ReturnDataStyle.REVERT,
ReturnDataStyle.IDENTITY,
],
)
@pytest.mark.parametrize("returned_size", [0, 32, 256, 1024])
def test_returndatasize_nonzero(
benchmark_test: BenchmarkTestFiller,
pre: Alloc,
returned_size: int,
return_data_style: ReturnDataStyle,
) -> None:
"""
Benchmark RETURNDATASIZE instruction with non-zero buffer.
- returned_size: the size of the returned data buffer.
- return_data_style: 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(
target_opcode=Op.RETURNDATASIZE,
code_generator=JumpLoopGenerator(
setup=setup, attack_block=Op.POP(Op.RETURNDATASIZE)
),
)
|
Parametrized Test Cases
This test generates 12 parametrized test cases across 3 forks.