Skip to content

test_nonce_validity()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_nonce_validity@v5.1.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_nonce_validity --fork Osaka

Test sending a transaction where the nonce field of an authorization almost overflows the maximum value.

Also test calling the account of the authorization signer in order to verify that the account is not warm.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
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
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
@pytest.mark.parametrize(
    "account_nonce,authorization_nonce",
    [
        pytest.param(
            Spec.MAX_NONCE,
            Spec.MAX_NONCE,
            id="nonce=2**64-1",
            marks=pytest.mark.execute(pytest.mark.skip(reason="Impossible account nonce")),
        ),
        pytest.param(
            Spec.MAX_NONCE - 1,
            Spec.MAX_NONCE - 1,
            id="nonce=2**64-2",
            marks=pytest.mark.execute(pytest.mark.skip(reason="Impossible account nonce")),
        ),
        pytest.param(
            0,
            1,
            id="nonce=1,account_nonce=0",
        ),
        pytest.param(
            1,
            0,
            id="nonce=0,account_nonce=1",
        ),
    ],
)
@pytest.mark.execute(pytest.mark.skip(reason="Non-zero nonce not supported"))
def test_nonce_validity(
    state_test: StateTestFiller,
    pre: Alloc,
    account_nonce: int,
    authorization_nonce: int,
):
    """
    Test sending a transaction where the nonce field of an authorization almost overflows the
    maximum value.

    Also test calling the account of the authorization signer in order to verify that the account
    is not warm.
    """
    auth_signer = pre.fund_eoa(auth_account_start_balance, nonce=account_nonce)

    success_slot = 1
    return_slot = 2

    valid_authorization = authorization_nonce < 2**64 - 1 and account_nonce == authorization_nonce
    set_code = Op.RETURN(0, 1)
    set_code_to_address = pre.deploy_contract(set_code)

    authorization = AuthorizationTuple(
        address=set_code_to_address,
        nonce=authorization_nonce,
        signer=auth_signer,
    )

    entry_code = (
        Op.SSTORE(success_slot, 1)
        + Op.CALL(address=auth_signer)
        + Op.SSTORE(return_slot, Op.RETURNDATASIZE)
    )
    entry_address = pre.deploy_contract(entry_code)

    tx = Transaction(
        gas_limit=100_000,
        to=entry_address,
        value=0,
        authorization_list=[authorization],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                nonce=(account_nonce + 1) if valid_authorization else account_nonce,
                code=Spec.delegation_designation(set_code_to_address)
                if valid_authorization
                else b"",
            )
            if authorization_nonce < 2**64 and account_nonce > 0
            else Account.NONEXISTENT,
            entry_address: Account(
                storage={
                    success_slot: 1,
                    return_slot: 1 if valid_authorization else 0,
                },
            ),
        },
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) account_nonce authorization_nonce
...fork_Prague-state_test-nonce=2**64-1 18446744073709551615 18446744073709551615
...fork_Prague-state_test-nonce=2**64-2 18446744073709551614 18446744073709551614
...fork_Prague-state_test-nonce=1,account_nonce=0 0 1
...fork_Prague-state_test-nonce=0,account_nonce=1 1 0
...fork_Prague-blockchain_test_from_state_test-nonce=2**64-1 18446744073709551615 18446744073709551615
...fork_Prague-blockchain_test_from_state_test-nonce=2**64-2 18446744073709551614 18446744073709551614
...fork_Prague-blockchain_test_from_state_test-nonce=1,account_nonce=0 0 1
...fork_Prague-blockchain_test_from_state_test-nonce=0,account_nonce=1 1 0
...fork_Osaka-state_test-nonce=2**64-1 18446744073709551615 18446744073709551615
...fork_Osaka-state_test-nonce=2**64-2 18446744073709551614 18446744073709551614
...fork_Osaka-state_test-nonce=1,account_nonce=0 0 1
...fork_Osaka-state_test-nonce=0,account_nonce=1 1 0
...fork_Osaka-blockchain_test_from_state_test-nonce=2**64-1 18446744073709551615 18446744073709551615
...fork_Osaka-blockchain_test_from_state_test-nonce=2**64-2 18446744073709551614 18446744073709551614
...fork_Osaka-blockchain_test_from_state_test-nonce=1,account_nonce=0 0 1
...fork_Osaka-blockchain_test_from_state_test-nonce=0,account_nonce=1 1 0