Skip to content

test_calldatacopy_from_origin()

Documentation for tests/benchmark/compute/instruction/test_call_context.py::test_calldatacopy_from_origin@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_call_context.py::test_calldatacopy_from_origin --gas-benchmark-values 1

Benchmark CALLDATACOPY instruction.

Source code in tests/benchmark/compute/instruction/test_call_context.py
142
143
144
145
146
147
148
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
188
189
190
191
192
193
194
195
@pytest.mark.repricing(fixed_src_dst=True)
@pytest.mark.parametrize(
    "mem_size",
    [0, 32, 256, 1024, 10 * 1024, 1024 * 1024],
)
@pytest.mark.parametrize(
    "fixed_src_dst",
    [
        True,
        False,
    ],
)
@pytest.mark.parametrize(
    "calldata_size",
    [0, 32, 256, 1024],
)
def test_calldatacopy_from_origin(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    mem_size: int,
    fixed_src_dst: bool,
    calldata_size: int,
    tx_gas_limit: int,
) -> None:
    """Benchmark CALLDATACOPY instruction."""
    # Generate calldata of the specified size with deterministic data.
    data = Bytes([i % 256 for i in range(calldata_size)])

    intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
    min_gas = intrinsic_gas_calculator(calldata=data)
    if min_gas > tx_gas_limit:
        pytest.skip(
            f"Minimum gas required for calldata ({min_gas}) is greater "
            "than the gas limit"
        )

    # Setup pushes the memory size to copy onto the stack.
    # The attack block uses DUP1 to reuse this value for the copy length.
    setup = Op.PUSH3(mem_size) if mem_size > 0 else Op.PUSH0
    src_dst = 0 if fixed_src_dst else Op.AND(Op.GAS, 7)
    attack_block = Op.CALLDATACOPY(
        src_dst,
        src_dst,
        Op.CALLDATASIZE,
    )

    benchmark_test(
        target_opcode=Op.CALLDATACOPY,
        code_generator=JumpLoopGenerator(
            setup=setup,
            attack_block=attack_block,
            tx_kwargs={"data": data},
        ),
    )

Parametrized Test Cases

This test generates 48 parametrized test cases across 3 forks.