Skip to content

test_nonce_validity()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_nonce_validity@21fb11c8.

Generate fixtures for these test cases for Prague with:

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

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
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
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
@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",
        ),
    ],
)
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