Skip to content

test_delegation_pointer_to_delegated_account()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_delegation_pointer_to_delegated_account@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_to_delegated_account --fork Amsterdam

Test a pointer aimed at an already-delegated account.

Delegation resolves only once, so the frame executes the designator bytes (0xef0100 || writer) as code. Since 0xef is undefined, execution halts before reaching writer's SSTORE. The reservoir stays untouched and is refunded, so the bill equals the cap, not the full gas limit.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@pytest.mark.valid_from("EIP8037")
def test_delegation_pointer_to_delegated_account(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test a pointer aimed at an already-delegated account.

    Delegation resolves only once,
    so the frame executes the designator bytes (0xef0100 || writer) as code.
    Since 0xef is undefined, execution halts before reaching writer's SSTORE.
    The reservoir stays untouched and is refunded, so the bill equals the cap,
    not the full gas limit.
    """
    writer = pre.deploy_contract(code=Op.SSTORE(0, 1))
    inner = pre.fund_eoa(delegation=writer)
    outer = pre.fund_eoa(delegation=inner)

    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    tx = Transaction(
        to=outer,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=gas_limit_cap),
    )

    state_test(
        pre=pre,
        post={
            outer: Account(storage={}),
            inner: Account(storage={}),
            writer: Account(storage={}),
        },
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=gas_limit_cap),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.