Skip to content

test_call_to_delegated_target_double_access()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_to_delegated_target_double_access@343274cc.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_to_delegated_target_double_access --fork Amsterdam

Measure a call to a 7702-delegated target: 2x2 double access.

The spec applies the delegation surcharge to every call opcode (CALL/CALLCODE/DELEGATECALL/STATICCALL), so each reads two account leaves: the target's leaf and the delegation's leaf. Each is charged independently as WARM_ACCESS or COLD_ACCOUNT_ACCESS by warmth. DELEGATECALL and STATICCALL carry no value but still pay the delegation surcharge.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.with_all_call_opcodes()
@pytest.mark.parametrize(
    "target_warm", [False, True], ids=["target_cold", "target_warm"]
)
@pytest.mark.parametrize(
    "delegate_warm", [False, True], ids=["delegate_cold", "delegate_warm"]
)
def test_call_to_delegated_target_double_access(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    fork: Fork,
    call_opcode: Op,
    target_warm: bool,
    delegate_warm: bool,
) -> None:
    """
    Measure a call to a 7702-delegated target: 2x2 double access.

    The spec applies the delegation surcharge to every call opcode
    (``CALL``/``CALLCODE``/``DELEGATECALL``/``STATICCALL``), so each
    reads two account leaves: the target's leaf and the delegation's
    leaf. Each is charged independently as ``WARM_ACCESS`` or
    ``COLD_ACCOUNT_ACCESS`` by warmth. ``DELEGATECALL`` and
    ``STATICCALL`` carry no value but still pay the delegation
    surcharge.
    """
    # Final code-bearing account that the delegation points at.
    delegate = pre.deploy_contract(Op.STOP)
    # EOA delegated (EIP-7702) to `delegate`.
    target = pre.fund_eoa(amount=0, delegation=delegate)

    measured_code = call_opcode(gas=0, address=target)
    cost_metadata = call_opcode(
        address_warm=target_warm,
        delegated_address=True,
        delegated_address_warm=delegate_warm,
    )
    measure_address = _measure_call(
        pre, fork, measured_code, call_opcode(address_warm=False)
    )

    # The opcode's own cost folds the target and delegate accesses.
    expected_gas = cost_metadata.gas_cost(fork)

    # Warm the target and/or the delegate leaf via the access list.
    access_entries = []
    if target_warm:
        access_entries.append(AccessList(address=target, storage_keys=[]))
    if delegate_warm:
        access_entries.append(AccessList(address=delegate, storage_keys=[]))
    access_list = access_entries or None

    tx = Transaction(
        to=measure_address,
        sender=pre.fund_eoa(),
        access_list=access_list,
    )

    post = {measure_address: Account(storage={0: expected_gas})}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 16 parametrized test cases across 1 fork.