Skip to content

test_create_tx_collision_refunds_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_tx_collision_refunds_reservoir@622620d8.

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_tx_collision_refunds_reservoir --fork Amsterdam

Verify the state-gas reservoir is refunded on a depth-0 CREATE-tx address collision when gas_limit > TX_MAX_GAS_LIMIT.

EIP-8037 splits gas_limit into the capped execution budget and a state-gas reservoir. On collision the inner execution gas is burnt and intrinsic_state_gas is refunded; the reservoir must also be refunded to the sender. header.gas_used is fixed at the execution cap regardless of reservoir handling, so the sender's post-balance is the primary discriminating assertion.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
@pytest.mark.pre_alloc_mutable()
@pytest.mark.execute(pytest.mark.skip(reason="Requires specific gas price"))
@pytest.mark.valid_from("EIP8037")
def test_create_tx_collision_refunds_reservoir(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify the state-gas reservoir is refunded on a depth-0 CREATE-tx
    address collision when `gas_limit > TX_MAX_GAS_LIMIT`.

    EIP-8037 splits `gas_limit` into the capped execution budget and a
    state-gas reservoir. On collision the inner execution gas is burnt
    and `intrinsic_state_gas` is refunded; the reservoir must also
    be refunded to the sender. `header.gas_used` is fixed at the
    execution cap regardless of reservoir handling, so the sender's
    post-balance is the primary discriminating assertion.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    init_code = Op.STOP
    # +1 above intrinsic_state_gas (= create_state_gas(code_size=0)
    # for empty-code CREATE-tx) makes message.state_gas_reservoir > 0.
    reservoir = fork.create_state_gas(code_size=0) + 1
    initial_fund = 10**18

    sender = pre.fund_eoa(initial_fund)
    collision_target = compute_create_address(address=sender, nonce=0)
    pre[collision_target] = Account(nonce=1)

    tx_gas_price = 7
    tx = Transaction(
        to=None,
        data=init_code,
        state_gas_reservoir=reservoir,
        sender=sender,
        gas_price=tx_gas_price,
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=gas_limit_cap),
            ),
        ],
        post={
            sender: Account(
                balance=initial_fund - gas_limit_cap * tx_gas_price,
                nonce=1,
            ),
            collision_target: Account(nonce=1, code=b"", storage={}),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.