Skip to content

test_same_authority_increasing_nonce_net_once()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_same_authority_increasing_nonce_net_once@622620d8.

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

Verify the per-authority once invariant across valid auths.

The same fresh authority is delegated by three authorizations with increasing nonces in one transaction. The account leaf is created and first written once (NEW_ACCOUNT + ACCOUNT_WRITE on the first authorization) and a net-new delegation indicator is written once (AUTH_BASE on the first). The later authorizations re-point an already-written, already-delegated authority, so they add nothing beyond the intrinsic base. The authority ends delegated to the last target with nonce 3.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
@pytest.mark.valid_from("EIP8037")
def test_same_authority_increasing_nonce_net_once(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify the per-authority once invariant across valid auths.

    The same fresh authority is delegated by three authorizations with
    increasing nonces in one transaction. The account leaf is created and
    first written once (``NEW_ACCOUNT`` + ``ACCOUNT_WRITE`` on the first
    authorization) and a net-new delegation indicator is written once
    (``AUTH_BASE`` on the first). The later authorizations re-point an
    already-written, already-delegated authority, so they add nothing
    beyond the intrinsic base. The authority ends delegated to the last
    target with nonce 3.
    """
    num_auths = 3
    targets = [pre.deploy_contract(code=Op.STOP) for _ in range(num_auths)]
    call_target = pre.deploy_contract(code=Op.STOP)

    signer = pre.fund_eoa(amount=0)
    authorization_list = [
        AuthorizationTuple(
            address=targets[i],
            nonce=i,
            signer=signer,
            creates_account=(i == 0),
            writes_delegation=(i == 0),
            first_write=(i == 0),
        )
        for i in range(num_auths)
    ]

    intrinsic_execution, top_frame_execution, top_frame_state = _auth_gas(
        fork, authorization_list
    )
    cumulative_gas_used, header_gas_used = _receipt_and_header(
        intrinsic_execution, top_frame_execution, top_frame_state
    )

    tx = Transaction(
        to=call_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=num_auths,
                balance=0,
                code=Spec7702.delegation_designation(targets[-1]),
            ),
        },
        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.