Skip to content

test_cumulative_block_state_gas_boundary()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_cumulative_block_state_gas_boundary@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_cumulative_block_state_gas_boundary --fork Amsterdam

Probe the block state-gas inclusion gate with spill-funded usage.

tx1 gets no state-gas reservoir (small gas_limit), so its SSTORE-set state gas reaches block_state_gas_used only via spillover, and its gas_limit exactly fills the block. tx2's gas_limit is the remaining state budget plus delta, below both the per-tx cap and the remaining regular budget, so only the state gate can reject it: delta=0 must be accepted (strict >) and delta=1 rejected. test_block_state_gas_limit_boundary covers this gate with a reservoir-funded tx1 and an above-cap tx2.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
@pytest.mark.parametrize(
    "delta",
    [
        pytest.param(0, id="exact_fit"),
        pytest.param(1, id="exceeded", marks=pytest.mark.exception_test),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_cumulative_block_state_gas_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    delta: int,
) -> None:
    """
    Probe the block state-gas inclusion gate with spill-funded usage.

    tx1 gets no state-gas reservoir (small gas_limit), so its SSTORE-set
    state gas reaches block_state_gas_used only via spillover, and its
    gas_limit exactly fills the block. tx2's gas_limit is the remaining
    state budget plus delta, below both the per-tx cap and the remaining
    regular budget, so only the state gate can reject it: delta=0 must
    be accepted (strict >) and delta=1 rejected.
    test_block_state_gas_limit_boundary covers this gate with a
    reservoir-funded tx1 and an above-cap tx2.
    """
    n = 6
    intrinsic = fork.transaction_intrinsic_cost_calculator()()
    sstore_code = (
        sum((Op.SSTORE(i, 1) for i in range(n)), Bytecode()) + Op.STOP
    )
    tx1_regular = intrinsic + sstore_code.regular_cost(fork)
    tx1_state = sstore_code.state_cost(fork)
    # tx1 exactly fills the block; the leftover state budget is tx1_regular.
    block_gas_limit = tx1_regular + tx1_state
    # tx2 stays within the remaining regular budget, so only the state
    # dimension can reject it.
    assert tx1_regular + 1 <= block_gas_limit - tx1_regular

    sstore_contract = pre.deploy_contract(code=sstore_code)
    stop_contract = pre.deploy_contract(code=Op.STOP)

    error = TransactionException.GAS_ALLOWANCE_EXCEEDED if delta else None
    tx1 = Transaction(
        to=sstore_contract, gas_limit=block_gas_limit, sender=pre.fund_eoa()
    )
    tx2 = Transaction(
        to=stop_contract,
        gas_limit=tx1_regular + delta,
        sender=pre.fund_eoa(),
        error=error,
    )

    post: dict = {}
    header_verify: Header | None = None
    if not delta:
        post = {sstore_contract: Account(storage=dict.fromkeys(range(n), 1))}
        header_verify = Header(
            gas_used=max(tx1_regular + intrinsic, tx1_state)
        )

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=[tx1, tx2],
                exception=error,
                header_verify=header_verify,
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.