Skip to content

test_call_to_double_delegated_target_single_hop()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_to_double_delegated_target_single_hop@2867859a.

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

Verify delegation resolution is single-hop: A -> B -> C charges two.

target (A) is an EOA delegated to mid (B), which is itself an EOA delegated to final (C), a code-bearing account. A cold CALL to target reads exactly two account leaves -- the target's and its delegation's -- and is charged 2 * COLD_ACCOUNT_ACCESS. The chain is not followed a second hop, so final's leaf is not charged. Both the framework opcode model and a runtime CodeGasMeasure confirm the value.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
def test_call_to_double_delegated_target_single_hop(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify delegation resolution is single-hop: A -> B -> C charges two.

    ``target`` (A) is an EOA delegated to ``mid`` (B), which is itself
    an EOA delegated to ``final`` (C), a code-bearing account. A cold
    ``CALL`` to ``target`` reads exactly two account leaves -- the
    target's and its delegation's -- and is charged
    ``2 * COLD_ACCOUNT_ACCESS``. The chain is not followed a
    second hop, so ``final``'s leaf is not charged. Both the framework
    opcode model and a runtime ``CodeGasMeasure`` confirm the value.
    """
    # A -> B -> C delegation chain. `mid` is an EOA whose code is the
    # 7702 delegation designator pointing at `final`; `target` delegates
    # to `mid` in turn.
    final = pre.deploy_contract(Op.STOP)
    mid = pre.fund_eoa(amount=0, delegation=final)
    target = pre.fund_eoa(amount=0, delegation=mid)

    # Framework model: cold target leaf + cold delegation leaf, no third
    # access for the second hop.
    cost_metadata = Op.CALL(
        address_warm=False,
        delegated_address=True,
        delegated_address_warm=False,
    )
    # Cold target leaf plus cold delegation leaf; no state gas.
    expected_gas = cost_metadata.gas_cost(fork)
    assert cost_metadata.state_cost(fork) == 0

    measured_code = Op.CALL(gas=0, address=target)
    measure_address = _measure_call(
        pre, fork, measured_code, Op.CALL(address_warm=False)
    )

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.