Skip to content

test_delegation_pointer_new_account_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_delegation_pointer_new_account_state_gas@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_delegation_pointer_new_account_state_gas --fork Amsterdam

Test delegation pointer CALL to empty account charges new-account gas.

A contract CALLs with value to a non-existent address. When executed via a delegation pointer, the new-account state gas is charged identically to a direct call.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@pytest.mark.valid_from("EIP8037")
def test_delegation_pointer_new_account_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test delegation pointer CALL to empty account charges new-account gas.

    A contract CALLs with value to a non-existent address. When executed
    via a delegation pointer, the new-account state gas
    is charged identically to a direct call.
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    target = pre.nonexistent_account()

    parent_storage = Storage()
    contract = pre.deploy_contract(
        code=(
            Op.SSTORE(
                parent_storage.store_next(1),
                Op.CALL(gas=100_000, address=target, value=1),
            )
        ),
        balance=1,
    )

    # EOA delegates to the contract
    delegator = pre.fund_eoa(delegation=contract, amount=1)

    # The authorization re-targets an already-delegated authority whose
    # nonce (1, from the delegation setup) no longer matches nonce=0, so
    # it is invalid and charges no top-frame state gas.
    authorization = AuthorizationTuple(
        address=contract,
        nonce=0,
        signer=delegator,
        creates_account=False,
        writes_delegation=False,
        first_write=False,
    )
    auth_state_gas = fork.transaction_top_frame_state_gas(
        authorizations=[authorization]
    )

    sender = pre.fund_eoa()
    tx = Transaction(
        to=delegator,
        state_gas_reservoir=auth_state_gas + new_account_state_gas,
        authorization_list=[authorization],
        sender=sender,
    )

    # CALL success stored in delegator's storage context
    post = {delegator: Account(storage=parent_storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.