Skip to content

test_same_tx_clear_then_reset_pre_delegated()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_same_tx_clear_then_reset_pre_delegated@2119b382.

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

Verify a clear-then-reset of a pre-delegated authority in one tx.

An authority delegated before the transaction is cleared by the first authorization then re-delegated to a new target by the second. Because the authority was already delegated before the transaction, neither authorization writes a net-new delegation indicator: no AUTH_BASE is charged and, as the leaf already exists, no NEW_ACCOUNT either. The clear is the transaction's first write to the leaf, so one ACCOUNT_WRITE is paid on top of the intrinsic per-authorization bases. The authority ends delegated to the new target with nonce 3.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
@pytest.mark.valid_from("EIP8037")
def test_same_tx_clear_then_reset_pre_delegated(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify a clear-then-reset of a pre-delegated authority in one tx.

    An authority delegated before the transaction is cleared by the first
    authorization then re-delegated to a new target by the second. Because
    the authority was already delegated before the transaction, neither
    authorization writes a net-new delegation indicator: no ``AUTH_BASE``
    is charged and, as the leaf already exists, no ``NEW_ACCOUNT``
    either. The clear is the transaction's first write to the leaf, so
    one ``ACCOUNT_WRITE`` is paid on top of the intrinsic
    per-authorization bases. The authority ends delegated to the new
    target with nonce 3.
    """
    contract_a = pre.deploy_contract(code=Op.STOP)
    contract_b = pre.deploy_contract(code=Op.STOP)
    target = pre.deploy_contract(code=Op.STOP)

    signer = pre.fund_eoa(delegation=contract_a)
    authorization_list = [
        AuthorizationTuple(
            address=Spec7702.RESET_DELEGATION_ADDRESS,
            nonce=1,
            signer=signer,
            creates_account=False,
            writes_delegation=False,
        ),
        AuthorizationTuple(
            address=contract_b,
            nonce=2,
            signer=signer,
            creates_account=False,
            writes_delegation=False,
            first_write=False,
        ),
    ]

    intrinsic_regular, top_frame_regular, top_frame_state = _auth_gas(
        fork, authorization_list
    )
    assert top_frame_regular == fork.gas_costs().ACCOUNT_WRITE
    assert top_frame_state == 0
    cumulative_gas_used, header_gas_used = _receipt_and_header(
        intrinsic_regular, top_frame_regular, top_frame_state
    )

    tx = Transaction(
        to=target,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=cumulative_gas_used,
        ),
    )

    state_test(
        pre=pre,
        post={
            signer: Account(
                nonce=3,
                code=Spec7702.delegation_designation(contract_b),
            ),
        },
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=header_gas_used),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.