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@622620d8.

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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
@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.
    """
    target = pre.nonexistent_account()

    parent_storage = Storage()

    call = Op.CALL(
        gas=0,
        address=target,
        value=1,
        value_transfer=True,
        account_new=True,
    )
    contract_code = Op.SSTORE(parent_storage.store_next(1), call)
    contract = pre.deploy_contract(code=contract_code, 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,
    )
    intrinsic_execution = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=[authorization],
        recipient_type=RecipientType.DELEGATION_7702,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_execution = fork.transaction_top_frame_execution_gas(
        recipient_type=RecipientType.DELEGATION_7702,
        delegation_warm=False,
        authorizations=[authorization],
    )
    auth_state_gas = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.DELEGATION_7702,
        authorizations=[authorization],
    )
    assert auth_state_gas == 0

    # The callee leaves the value-transfer stipend unused, so it returns
    # to this frame instead of being spent.
    block_execution = (
        intrinsic_execution
        + top_frame_execution
        + contract_code.execution_cost(fork)
        - fork.gas_costs().CALL_STIPEND
    )
    block_state = auth_state_gas + contract_code.state_cost(fork)
    assert block_state > block_execution

    sender = pre.fund_eoa()
    tx = Transaction(
        to=delegator,
        state_gas_reservoir=block_state,
        authorization_list=[authorization],
        sender=sender,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=block_execution + block_state,
        ),
    )

    # CALL success stored in delegator's storage context
    post = {
        delegator: Account(storage=parent_storage, balance=0),
        target: Account(balance=1),
    }

    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(
            gas_used=max(block_execution, block_state)
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.