Skip to content

test_access_list_data_cost_with_execution()

Documentation for tests/amsterdam/eip7981_increase_access_list_cost/test_access_list_cost.py::test_access_list_data_cost_with_execution@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7981_increase_access_list_cost/test_access_list_cost.py::test_access_list_data_cost_with_execution --fork Amsterdam

Test that the access list data cost is charged when execution gas dominates.

EIP-7981 charges the access list data cost as a flat surcharge on both sides of the gas-used max, so it is paid in full even when the intrinsic-plus-execution side exceeds the floor. An implementation that only counts access list bytes toward the floor undercharges exactly the surcharge here, failing the receipt pin.

Source code in tests/amsterdam/eip7981_increase_access_list_cost/test_access_list_cost.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.with_all_tx_types(selector=lambda tx_type: tx_type in (1, 2))
@pytest.mark.parametrize(
    "access_list",
    [
        pytest.param(
            [
                AccessList(
                    address=Address(1),
                    storage_keys=[Hash(0), Hash(1)],
                )
            ],
            id="single_address_two_keys",
        ),
    ],
)
def test_access_list_data_cost_with_execution(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    tx_type: int,
    access_list: list,
) -> None:
    """
    Test that the access list data cost is charged when execution gas
    dominates.

    EIP-7981 charges the access list data cost as a flat surcharge on
    both sides of the gas-used max, so it is paid in full even when the
    intrinsic-plus-execution side exceeds the floor. An implementation
    that only counts access list bytes toward the floor undercharges
    exactly the surcharge here, failing the receipt pin.
    """
    gas_costs = fork.gas_costs()
    surcharge = (
        calculate_access_list_floor_tokens(access_list)
        * gas_costs.TX_DATA_TOKEN_FLOOR
    )
    # One gas per JUMPDEST, sized so the execution gas strictly exceeds
    # the surcharge under test.
    code = Op.JUMPDEST * (surcharge + 1) + Op.STOP
    contract = pre.deploy_contract(code)
    execution_gas = code.gas_cost(fork)
    assert execution_gas > surcharge

    intrinsic_cost_calculator = fork.transaction_intrinsic_cost_calculator()
    intrinsic_gas = intrinsic_cost_calculator(
        access_list=access_list,
        return_cost_deducted_prior_execution=True,
    )
    # The surcharge must be an explicit term of the intrinsic cost, on
    # top of the per-entry access charges of the same transaction
    # without an access list.
    entry_charges = (
        gas_costs.TX_ACCESS_LIST_ADDRESS
        + 2 * gas_costs.TX_ACCESS_LIST_STORAGE_KEY
    )
    intrinsic_gas_no_access_list = intrinsic_cost_calculator(
        return_cost_deducted_prior_execution=True,
    )
    assert (
        intrinsic_gas
        == intrinsic_gas_no_access_list + entry_charges + surcharge
    )

    # The execution side must win the max against the floor.
    expected_gas_used = intrinsic_gas + execution_gas
    floor_gas = fork.transaction_data_floor_cost_calculator()(
        data=b"", access_list=access_list
    )
    assert expected_gas_used > floor_gas

    tx = Transaction(
        ty=tx_type,
        sender=pre.fund_eoa(),
        to=contract,
        access_list=access_list,
        gas_limit=expected_gas_used,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_gas_used
        ),
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.