Skip to content

test_call_value_to_existing()

Documentation for tests/benchmark/stateful/bloatnet/test_call.py::test_call_value_to_existing@5fa5938b.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/stateful/bloatnet/test_call.py::test_call_value_to_existing --gas-benchmark-values 1

Benchmark CALL with value transfer to cold existing contracts.

Source code in tests/benchmark/stateful/bloatnet/test_call.py
 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
 66
 67
 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
@pytest.mark.stub_parametrize("factory_stub", "bloatnet_factory_")
def test_call_value_to_existing(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_benchmark_value: int,
    tx_gas_limit: int,
    factory_stub: str,
) -> None:
    """Benchmark CALL with value transfer to cold existing contracts."""
    factory_address = pre.deploy_contract(
        code=Bytecode(),
        stub=factory_stub,
    )

    # Contract Construction
    setup = Bytecode()

    setup += Conditional(
        condition=Op.STATICCALL(
            gas=Op.GAS,
            address=factory_address,
            args_offset=0,
            args_size=0,
            ret_offset=96,
            ret_size=64,
            # gas accounting
            address_warm=False,
            old_memory_size=0,
            new_memory_size=160,
        ),
        if_false=Op.INVALID,
    )

    create2_preimage = Create2PreimageLayout(
        factory_address=factory_address,
        salt=Op.CALLDATALOAD(32),
        init_code_hash=Op.MLOAD(128),
        old_memory_size=160,
    )

    setup += create2_preimage
    setup += Op.CALLDATALOAD(0)  # [num_contract]

    # CALL with value=1 to factory contracts.
    # The address is computed inline via SHA3, avoiding DUP depth issues.
    # gas=1: subcall gets 1 + 2300 stipend, still not enough for 24KB
    # bytecode → subcall fails, but cold + value gas costs are charged.
    call_value_op = Op.POP(
        Op.CALL(
            gas=1,
            address=create2_preimage.address_op(),
            value=1,
            args_offset=0,
            args_size=0,
            ret_offset=0,
            ret_size=0,
            # gas accounting
            value_transfer=True,
        )
    )

    loop = While(
        body=(call_value_op + create2_preimage.increment_salt_op()),
        condition=DECREMENT_COUNTER_CONDITION,
    )

    # Contract Deployment
    code = setup + loop
    attack_contract_address = pre.deploy_contract(code=code)

    # Gas Accounting
    txs, total_gas_consumed = build_benchmark_txs(
        pre=pre,
        fork=fork,
        gas_benchmark_value=gas_benchmark_value,
        tx_gas_limit=tx_gas_limit,
        attack_contract_address=attack_contract_address,
        setup_cost=setup.gas_cost(fork),
        iteration_cost=loop.gas_cost(fork),
    )

    benchmark_test(
        pre=pre,
        blocks=[Block(txs=txs)],
        expected_benchmark_gas_used=total_gas_consumed,
        skip_gas_used_validation=True,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 3 forks.