Skip to content

test_block_2d_inclusion_execution_gate_full_gas_reservation()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_2d_inclusion_execution_gate_full_gas_reservation@26332146.

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

Pin the flat execution-gas inclusion gate on a contract creation.

EIP-8037 measures min(TX_MAX_GAS_LIMIT, tx.gas) against execution_gas_available in full, with no credit for the NEW_ACCOUNT state gas the creation charges at its top frame. Filler STOP txs spend execution gas only, so the state budget stays full and only the execution gate can reject the creation.

Its gas_limit is the leftover execution budget plus over_by, where None means the state charge itself. A client crediting that charge would accept over_by=1 with slack and over_by=None exactly under strict >; the flat gate rejects both. over_by=0 is the control, valid either way.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "over_by",
    [
        pytest.param(0, id="exact_fit"),
        pytest.param(1, id="one_above", marks=pytest.mark.exception_test),
        pytest.param(
            None,
            id="state_charge_above",
            marks=pytest.mark.exception_test,
        ),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_block_2d_inclusion_execution_gate_full_gas_reservation(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    over_by: int | None,
) -> None:
    """
    Pin the flat execution-gas inclusion gate on a contract creation.

    EIP-8037 measures ``min(TX_MAX_GAS_LIMIT, tx.gas)`` against
    ``execution_gas_available`` in full, with no credit for the
    ``NEW_ACCOUNT`` state gas the creation charges at its top frame.
    Filler STOP txs spend execution gas only, so the state budget
    stays full and only the execution gate can reject the creation.

    Its ``gas_limit`` is the leftover execution budget plus
    ``over_by``, where ``None`` means the state charge itself. A
    client crediting that charge would accept ``over_by=1`` with
    slack and ``over_by=None`` exactly under strict ``>``; the flat
    gate rejects both. ``over_by=0`` is the control, valid either way.
    """
    init_code = bytes(Op.STOP)
    intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
    intrinsic_gas = intrinsic_calc()

    create_execution = intrinsic_calc(
        calldata=init_code,
        contract_creation=True,
    )
    create_state_charge = fork.transaction_top_frame_state_gas(
        contract_creation=True
    )

    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    delta = create_state_charge if over_by is None else over_by

    # The CREATE tx draws its state charge from gas_left, so it needs
    # both dimensions' gas within the leftover execution budget.
    create_gas = create_execution + create_state_charge
    num_fillers = create_state_charge // intrinsic_gas + 1
    filler_execution = num_fillers * intrinsic_gas
    block_gas_limit = max(
        filler_execution + create_gas,
        fork.minimum_block_gas_limit(),
    )
    execution_available = block_gas_limit - filler_execution
    tx_gas_limit = execution_available + delta

    assert execution_available >= create_gas
    assert tx_gas_limit <= gas_limit_cap and tx_gas_limit <= block_gas_limit

    assert tx_gas_limit - create_state_charge <= execution_available
    assert (tx_gas_limit > execution_available) == (delta > 0)

    error = TransactionException.GAS_ALLOWANCE_EXCEEDED if delta else None
    create_sender = pre.fund_eoa()
    create_tx = Transaction(
        to=None,
        data=init_code,
        gas_limit=tx_gas_limit,
        sender=create_sender,
        error=error,
    )

    post: dict = {}
    header_verify: Header | None = None
    if not delta:
        post = {
            compute_create_address(address=create_sender, nonce=0): Account(
                nonce=1
            ),
        }
        header_verify = Header(
            gas_used=max(
                filler_execution + create_execution,
                create_state_charge,
            ),
        )

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=stop_txs(pre, fork, num_fillers) + [create_tx],
                gas_limit=block_gas_limit,
                exception=error,
                header_verify=header_verify,
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.