Skip to content

test_multi_tx_block_auth_and_sstore()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_multi_tx_block_auth_and_sstore@26332146.

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

Test a multi-transaction block combining a top-frame auth and an SSTORE.

Two transactions share one block:

  1. a SetCode tx delegating an existing authority (top-frame AUTH_BASE, no refund); and
  2. a normal tx performing a zero-to-nonzero SSTORE (execution
  3. state gas).

The per-transaction receipt cumulative_gas_used accumulates across the block, so tx1's receipt is its own cost and tx2's is the running total. Verifies block-level accounting handles the two side by side.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
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
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
@pytest.mark.valid_from("EIP8037")
def test_multi_tx_block_auth_and_sstore(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test a multi-transaction block combining a top-frame auth and an
    SSTORE.

    Two transactions share one block:

    1. a SetCode tx delegating an existing authority (top-frame
       ``AUTH_BASE``, no refund); and
    2. a normal tx performing a zero-to-nonzero SSTORE (execution
       + state gas).

    The per-transaction receipt ``cumulative_gas_used`` accumulates across
    the block, so tx1's receipt is its own cost and tx2's is the running
    total. Verifies block-level accounting handles the two side by side.
    """
    contract = pre.deploy_contract(code=Op.STOP)

    # TX 1: delegate an existing authority.
    signer = pre.fund_eoa()
    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=signer,
            creates_account=False,
            writes_delegation=True,
        ),
    ]
    intrinsic_execution_1, top_frame_execution_1, top_frame_state_1 = (
        _auth_gas(fork, authorization_list)
    )
    tx1_gas, _ = _receipt_and_header(
        intrinsic_execution_1, top_frame_execution_1, top_frame_state_1
    )
    tx_1 = Transaction(
        to=contract,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=tx1_gas),
    )

    # TX 2: a plain zero-to-nonzero SSTORE.
    storage = Storage()
    sstore_code = Op.SSTORE(storage.store_next(1), 1)
    sstore_contract = pre.deploy_contract(code=sstore_code)
    intrinsic_execution_2 = fork.transaction_intrinsic_cost_calculator()(
        recipient_type=RecipientType.CONTRACT,
        return_cost_deducted_prior_execution=True,
    )
    tx2_gas = (
        intrinsic_execution_2
        + sstore_code.execution_cost(fork)
        + sstore_code.state_cost(fork)
    )
    tx_2 = Transaction(
        to=sstore_contract,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=tx1_gas + tx2_gas,
        ),
    )

    post = {
        signer: Account(code=Spec7702.delegation_designation(contract)),
        sstore_contract: Account(storage=storage),
    }
    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx_1, tx_2])],
        post=post,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.