Skip to content

test_tx_gas_above_cap_at_transition()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py::test_tx_gas_above_cap_at_transition@ffe48572.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py::test_tx_gas_above_cap_at_transition --fork Amsterdam

Test transaction and block gas constraints at the EIP-8037 transition.

Before EIP-8037, EIP-7825 rejects any tx with gas > TX_MAX_GAS_LIMIT. After EIP-8037 that gas limit is allowed — the excess feeds the state gas reservoir — but the replacement constraint still rejects a transaction whose intrinsic execution gas exceeds the cap. The scenarios pin acceptance at the cap, the old-rule rejection/new-rule acceptance flip at cap + 1, and rejection by the new transaction rule.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py
@pytest.mark.parametrize(
    "scenario",
    [
        pytest.param(
            "at_cap",
            id="at_cap",
            marks=[
                EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.AcceptedBeforeFork(),
                EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.AcceptedAfterFork(),
            ],
        ),
        pytest.param(
            "gas_limit_above_cap",
            id="gas_limit_above_cap",
            marks=[
                pytest.mark.exception_test,
                EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedBeforeFork(),
                EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.AcceptedAfterFork(),
            ],
        ),
        pytest.param(
            "intrinsic_above_cap",
            id="intrinsic_above_cap",
            marks=[
                pytest.mark.exception_test,
                EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedBeforeFork(),
                EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedAfterFork(),
            ],
        ),
    ],
)
def test_tx_gas_above_cap_at_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    scenario: str,
    fork: Fork,
) -> None:
    """
    Test transaction and block gas constraints at the EIP-8037 transition.

    Before EIP-8037, EIP-7825 rejects any tx with gas > TX_MAX_GAS_LIMIT.
    After EIP-8037 that gas limit is allowed — the excess feeds the state
    gas reservoir — but the replacement constraint still rejects a
    transaction whose intrinsic execution gas exceeds the cap. The scenarios
    pin acceptance at the cap, the old-rule rejection/new-rule acceptance flip
    at ``cap + 1``, and rejection by the new transaction rule.
    """
    after_fork = fork.fork_at(timestamp=15_000)
    gas_limit_cap = after_fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    storage_before = Storage()
    contract_before = pre.deploy_contract(
        code=(Op.SSTORE(storage_before.store_next(1), 1)),
    )

    storage_after = Storage()
    contract_after = pre.deploy_contract(
        code=(Op.SSTORE(storage_after.store_next(1), 1)),
    )

    tx_kwargs: dict = {}
    after_error = None
    if scenario == "at_cap":
        gas_limit = gas_limit_cap
        before_error = None
    elif scenario == "gas_limit_above_cap":
        gas_limit = gas_limit_cap + 1
        before_error = TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM
    else:
        access_list, execution_intrinsic = _access_list_over_execution_cap(
            after_fork, gas_limit_cap
        )
        gas_limit = execution_intrinsic + 1_000_000
        before_error = TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM
        after_error = TransactionException.INTRINSIC_GAS_TOO_LOW
        tx_kwargs = {"ty": 1, "access_list": access_list}

    blocks = [
        Block(
            timestamp=14_999,
            txs=[
                Transaction(
                    to=contract_before,
                    gas_limit=gas_limit,
                    sender=pre.fund_eoa(),
                    error=before_error,
                    **tx_kwargs,
                ),
            ],
            exception=before_error,
        ),
        # After fork: above-cap tx is now valid (excess feeds reservoir)
        Block(
            timestamp=15_000,
            txs=[
                Transaction(
                    to=contract_after,
                    gas_limit=gas_limit,
                    sender=pre.fund_eoa(),
                    error=after_error,
                    **tx_kwargs,
                ),
            ],
            exception=after_error,
        ),
    ]

    post = {
        contract_before: Account(
            storage=storage_before if before_error is None else {0: 0},
        ),
        contract_after: Account(
            storage=storage_after if after_error is None else {0: 0},
        ),
    }

    blockchain_test(pre=pre, blocks=blocks, post=post)

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.