Skip to content

test_create_collision_burned_gas_counted_in_block_execution()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_collision_burned_gas_counted_in_block_execution@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_collision_burned_gas_counted_in_block_execution --fork Amsterdam

Verify gas burned by a CREATE/CREATE2 address collision counts toward block execution gas used in the header.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
@pytest.mark.pre_alloc_mutable
@pytest.mark.with_all_create_opcodes()
@pytest.mark.valid_from("EIP8037")
def test_create_collision_burned_gas_counted_in_block_execution(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
) -> None:
    """
    Verify gas burned by a CREATE/CREATE2 address collision counts
    toward block execution gas used in the header.
    """
    init_code = Op.STOP
    mstore_value, size = init_code_at_high_bytes(init_code)
    factory_create_code = Op.MSTORE(
        0, mstore_value, new_memory_size=32
    ) + create_opcode(value=0, offset=0, size=size, account_new=False)
    factory_post_create_code = Op.POP + Op.STOP
    factory_code = factory_create_code + factory_post_create_code
    factory = pre.deploy_contract(code=factory_code)

    collision_target = compute_create_address(
        address=factory,
        nonce=1,
        salt=0,
        initcode=bytes(init_code),
        opcode=create_opcode,
    )
    pre.deploy_contract(code=Op.STOP, address=collision_target)

    # CPSB-agnostic baseline: block_state_gas is zero for this tx (the
    # existent collision target is not charged), so header.gas_used
    # equals the execution-gas total. Decompose the parent + inner frame
    # accounting from fork APIs so the baseline tracks future cost
    # changes automatically.
    gas_used_until_collision = (
        fork.transaction_intrinsic_cost_calculator()()
        + factory_create_code.gas_cost(fork)
    )
    # Fixed-size budget so the forwarded create_message_gas is
    # deterministic and the baseline below is reproducible.
    gas_limit = gas_used_until_collision * 2
    # Remaining gas can be derived due to the fixed gas limit
    gas_at_create = gas_limit - gas_used_until_collision
    # Inner burns 63/64 of the available gas on collision; the parent
    # retains 1/64. Post-CREATE consumes from the retained pool. A
    # mutation that drops the burned forwarded gas from execution
    # accounting would reduce this baseline.
    retained = gas_at_create // 64
    gas_post_create = factory_post_create_code.gas_cost(fork)
    assert retained >= gas_post_create
    baseline_gas_used = gas_limit - retained + gas_post_create

    tx = Transaction(
        to=factory,
        gas_limit=gas_limit,
        sender=pre.fund_eoa(),
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=baseline_gas_used),
            ),
        ],
        post={},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.