Skip to content

test_existing_auth_refund_survives_top_level_revert()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_existing_auth_refund_survives_top_level_revert@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_auth_refund_survives_top_level_revert --fork Amsterdam

Verify the existing-authority auth refund still flows through state_refund when execution REVERTs at the top level.

set_delegation runs before EVM execution and accumulates the refund into MessageCallOutput.state_refund. A subsequent top-level REVERT discards the SSTORE state changes (and resets state_gas_used to 0), but it does not unwind the auth refund — process_transaction still subtracts the refund from tx_state_gas. The header gas_used therefore reflects:

max(intrinsic_regular + execution_regular, intrinsic_state - auth_refund)

with execution_state netting to 0 because of the revert.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
@pytest.mark.valid_from("EIP8037")
def test_existing_auth_refund_survives_top_level_revert(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify the existing-authority auth refund still flows through
    `state_refund` when execution REVERTs at the top level.

    `set_delegation` runs before EVM execution and accumulates the
    refund into `MessageCallOutput.state_refund`. A subsequent
    top-level REVERT discards the SSTORE state changes (and resets
    `state_gas_used` to 0), but it does not unwind the auth refund —
    `process_transaction` still subtracts the refund from
    `tx_state_gas`. The header gas_used therefore reflects:

    `max(intrinsic_regular + execution_regular,
         intrinsic_state - auth_refund)`

    with `execution_state` netting to 0 because of the revert.
    """
    intrinsic_state_gas = fork.transaction_intrinsic_state_gas(
        authorization_count=1,
    )
    total_intrinsic = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=1,
    )
    intrinsic_regular = total_intrinsic - intrinsic_state_gas
    auth_refund = fork.gas_costs().REFUND_AUTH_PER_EXISTING_ACCOUNT

    sstore_op = Op.SSTORE(
        key=0,
        value=1,
        key_warm=False,
        original_value=0,
        new_value=1,
    )
    code = sstore_op + Op.REVERT(0, 0)
    contract = pre.deploy_contract(code=code)

    # bytecode.gas_cost(fork) returns the combined (regular + state)
    # cost; subtract the SSTORE state portion to isolate the regular
    # gas burned before REVERT.
    execution_regular = code.gas_cost(fork) - Op.SSTORE(
        new_value=1
    ).state_cost(fork)

    signer = pre.fund_eoa()
    authorization_list = [
        AuthorizationTuple(address=contract, nonce=0, signer=signer),
    ]

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

    expected_gas_used = max(
        intrinsic_regular + execution_regular,
        intrinsic_state_gas - auth_refund,
    )

    state_test(
        pre=pre,
        post={contract: Account(storage={})},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.