Skip to content

test_existing_account_refund_enables_sstore()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_existing_account_refund_enables_sstore@c74f1a67.

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

Test auth refund to reservoir enables subsequent state ops.

When an authorization targets an existing account, the new-account state gas refund goes to state_gas_reservoir. This refunded gas should then be available for SSTORE state gas in the execution phase.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
@pytest.mark.valid_from("EIP8037")
def test_existing_account_refund_enables_sstore(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test auth refund to reservoir enables subsequent state ops.

    When an authorization targets an existing account, the
    new-account state gas refund goes to state_gas_reservoir.
    This refunded gas should then be available for SSTORE state
    gas in the execution phase.
    """
    auth_state_gas = fork.transaction_intrinsic_state_gas(
        authorization_count=1,
    )
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    storage = Storage()
    contract = pre.deploy_contract(
        code=Op.SSTORE(storage.store_next(1), 1),
    )

    # Existing signer — gets new-account state gas refunded to reservoir
    signer = pre.fund_eoa()
    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=signer,
        ),
    ]

    # Provide enough for auth intrinsic state gas, but rely on the
    # existing-account refund to cover the SSTORE state gas
    sender = pre.fund_eoa()
    tx = Transaction(
        to=contract,
        state_gas_reservoir=auth_state_gas + sstore_state_gas,
        authorization_list=authorization_list,
        sender=sender,
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.