Skip to content

test_existing_account_auth_header_gas_used_reflects_refund()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_existing_account_auth_header_gas_used_reflects_refund@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_existing_account_auth_header_gas_used_reflects_refund --fork Amsterdam

Verify the block header gas_used reflects the existing-authority auth refund (deducted from tx_state_gas) when every authority is an existing account.

set_delegation credits state_gas_reservoir and accumulates state_refund, which process_transaction subtracts from tx_state_gas before adding it to block_state_gas_used. With STOP execution there is no extra regular or state gas used, so header gas_used equals max(intrinsic_regular, intrinsic_state - N * auth_refund).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
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
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
@pytest.mark.parametrize(
    "num_auths",
    [
        pytest.param(1, id="one_auth"),
        pytest.param(3, id="three_auths"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_existing_account_auth_header_gas_used_reflects_refund(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    num_auths: int,
) -> None:
    """
    Verify the block header gas_used reflects the existing-authority
    auth refund (deducted from `tx_state_gas`) when every authority
    is an existing account.

    `set_delegation` credits `state_gas_reservoir` and accumulates
    `state_refund`, which `process_transaction` subtracts from
    `tx_state_gas` before adding it to `block_state_gas_used`. With
    STOP execution there is no extra regular or state gas used, so
    header gas_used equals
    `max(intrinsic_regular, intrinsic_state - N * auth_refund)`.
    """
    intrinsic_state_gas = fork.transaction_intrinsic_state_gas(
        authorization_count=num_auths,
    )
    total_intrinsic = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=num_auths,
    )
    intrinsic_regular = total_intrinsic - intrinsic_state_gas
    auth_refund = fork.gas_costs().REFUND_AUTH_PER_EXISTING_ACCOUNT * num_auths

    contract = pre.deploy_contract(code=Op.STOP)

    authorization_list = [
        AuthorizationTuple(address=contract, nonce=0, signer=pre.fund_eoa())
        for _ in range(num_auths)
    ]

    tx = Transaction(
        to=contract,
        state_gas_reservoir=intrinsic_state_gas,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
    )

    expected_gas_used = max(
        intrinsic_regular,
        intrinsic_state_gas - auth_refund,
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.