Skip to content

test_auth_state_gas_scales_with_cpsb()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_auth_state_gas_scales_with_cpsb@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_auth_state_gas_scales_with_cpsb --fork Amsterdam

Test SetCode authorization top-frame state gas scales with cpsb.

Under EIP-2780 an authorization's state-dependent cost is charged at the top frame, not the intrinsic. An existing authority gaining a fresh delegation pays AUTH_BASE (= STATE_BYTES_PER_AUTH_BASE * cost_per_state_byte) of state gas there. The tx gas is sized so the charge draws from the reservoir when block_gas_limit is large and spills into gas_left when it is small; the delegated call must succeed in every regime.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
@pytest.mark.parametrize("block_gas_limit", BLOCK_GAS_LIMITS)
@pytest.mark.valid_from("EIP8037")
def test_auth_state_gas_scales_with_cpsb(
    state_test: StateTestFiller,
    pre: Alloc,
    block_gas_limit: int,
    fork: Fork,
) -> None:
    """
    Test SetCode authorization top-frame state gas scales with cpsb.

    Under EIP-2780 an authorization's state-dependent cost is charged at
    the top frame, not the intrinsic. An existing authority gaining a
    fresh delegation pays ``AUTH_BASE`` (= STATE_BYTES_PER_AUTH_BASE *
    cost_per_state_byte) of state gas there. The tx gas is sized so the
    charge draws from the reservoir when block_gas_limit is large and
    spills into gas_left when it is small; the delegated call must succeed
    in every regime.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    env = Environment(gas_limit=block_gas_limit)

    # A cheap STOP delegate: the delegated call only needs to resolve and
    # succeed to prove the delegation applied; the state gas under test is
    # the top-frame AUTH_BASE, not the delegate's own work.
    delegate = pre.deploy_contract(code=Op.STOP)
    signer = pre.fund_eoa()

    authorization_list = [
        AuthorizationTuple(
            address=delegate,
            nonce=0,
            signer=signer,
            creates_account=False,
            writes_delegation=True,
        ),
    ]
    # Top-frame state gas for the existing authority's fresh delegation
    # (AUTH_BASE = STATE_BYTES_PER_AUTH_BASE * cpsb).
    auth_state_gas = fork.transaction_top_frame_state_gas(
        authorizations=authorization_list,
    )

    storage = Storage()
    target = pre.deploy_contract(
        code=Op.SSTORE(
            storage.store_next(1, "delegated_call_success"),
            Op.CALL(gas=100_000, address=signer),
        ),
    )

    tx_gas = min(gas_limit_cap + auth_state_gas, block_gas_limit)
    tx = Transaction(
        ty=4,
        to=target,
        gas_limit=tx_gas,
        sender=pre.fund_eoa(),
        authorization_list=authorization_list,
    )

    post = {target: Account(storage=storage)}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 10 parametrized test cases across 1 fork.