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@636b5f17.

Generate fixtures for these test cases for Bogota 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 Bogota

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

A REVERT after the collision returns the parent's own leftover gas but cannot un-burn the forwarded grant, so the block still bills it in the execution dimension. The collision target already exists, so no state charge is taken in either ending.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
@pytest.mark.pre_alloc_mutable
@pytest.mark.parametrize(
    "parent_ending",
    [
        pytest.param("stop", id="parent_succeeds"),
        pytest.param("revert", id="parent_reverts"),
    ],
)
@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,
    parent_ending: str,
) -> None:
    """
    Verify gas burned by a CREATE/CREATE2 address collision counts
    toward block execution gas used in the header.

    A REVERT after the collision returns the parent's own leftover gas
    but cannot un-burn the forwarded grant, so the block still bills it
    in the execution dimension. The collision target already exists, so
    no state charge is taken in either ending.
    """
    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 if parent_ending == "stop" else Op.REVERT(0, 0)
    )
    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 4 parametrized test cases across 2 forks.