Skip to content

test_reverted_dispatch_state_gas_counts_toward_block_limit()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_reverted_dispatch_state_gas_counts_toward_block_limit@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_reverted_dispatch_state_gas_counts_toward_block_limit --fork Amsterdam

The state gas persisted by a reverted transaction's authorization counts against the block's state dimension when including later transactions.

The first transaction applies an account-creating authorization and its dispatched call reverts: the delegation, and the state gas that paid for it, persist. The last transaction is then sized to the remaining state capacity exactly (exact_fit: the inclusion check is strictly greater-than, so the block is valid) or one gas beyond it (exceeded: the per-transaction state check fires and the block is correctly rejected).

The execution dimension is asserted to have room either way, pinning the rejection to the state dimension. An implementation that drops a reverted transaction's persisting state gas from the block's state total would accept the exceeded block and fork.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "delta",
    [
        pytest.param(0, id="exact_fit"),
        pytest.param(1, id="exceeded", marks=pytest.mark.exception_test),
    ],
)
def test_reverted_dispatch_state_gas_counts_toward_block_limit(
    fork: Fork,
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    delta: int,
) -> None:
    """
    The state gas persisted by a reverted transaction's authorization
    counts against the block's state dimension when including later
    transactions.

    The first transaction applies an account-creating authorization and
    its dispatched call reverts: the delegation, and the state gas that
    paid for it, persist. The last transaction is then sized to the
    remaining state capacity exactly (``exact_fit``: the inclusion
    check is strictly greater-than, so the block is valid) or one gas
    beyond it (``exceeded``: the per-transaction state check fires and
    the block is correctly rejected).

    The execution dimension is asserted to have room either way, pinning
    the rejection to the state dimension. An implementation that drops
    a reverted transaction's persisting state gas from the block's
    state total would accept the ``exceeded`` block and fork.
    """
    cap = fork.transaction_gas_limit_cap()
    assert cap is not None, "EIP-7825 cap expected on this fork"

    block_gas_limit = 100_000_000

    revert_code = Op.REVERT(0, 0)
    recipient = pre.deploy_contract(code=revert_code)

    auth = build_authorization(pre, AuthorizationAction.CREATES_ACCOUNT)
    authorization_list = [auth.authorization]

    intrinsic_execution = _intrinsic_execution(
        fork, authorization_list, recipient_type=RecipientType.CONTRACT
    )
    auth_execution = fork.transaction_top_frame_gas_calculator()(
        recipient_type=RecipientType.CONTRACT,
        authorizations=authorization_list,
    )
    auth_state = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.CONTRACT,
        authorizations=authorization_list,
    )
    revert_exec_gas = revert_code.gas_cost(fork)

    first_tx_execution = intrinsic_execution + auth_execution + revert_exec_gas
    first_tx = Transaction(
        sender=pre.fund_eoa(),
        to=recipient,
        value=0,
        authorization_list=authorization_list,
        gas_limit=first_tx_execution + auth_state,
    )

    # The last transaction's worst-case state contribution is its full
    # ``tx.gas`` (the strict EIP-8037 inclusion rule), charged against
    # a state dimension that already carries the reverted first
    # transaction's persisting authorization state gas.
    state_available = block_gas_limit - auth_state
    last_tx_gas = state_available + delta

    # Pin the rejection (when delta > 0) to the state check: the
    # execution check must not fire.
    execution_available = block_gas_limit - first_tx_execution
    assert min(cap, last_tx_gas) < execution_available, (
        "the last tx would fail the execution check instead of the state check"
    )

    last_tx_error = (
        TransactionException.GAS_ALLOWANCE_EXCEEDED if delta > 0 else None
    )
    last_tx = Transaction(
        sender=pre.fund_eoa(),
        to=pre.deploy_contract(code=Op.STOP),
        value=0,
        gas_limit=last_tx_gas,
        error=last_tx_error,
    )

    # On rejection nothing in the block applies; on the exact fit the
    # reverted first transaction still leaves its delegation behind.
    post = {} if delta > 0 else {auth.authority: auth.applied_account}

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=[first_tx, last_tx],
                gas_limit=block_gas_limit,
                exception=last_tx_error,
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.