Skip to content

test_valid_tx_invalid_chain_id()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_valid_tx_invalid_chain_id@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

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

Test sending a transaction where the chain id field does not match the current chain's id.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
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
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
@pytest.mark.parametrize(
    "invalid_chain_id_case",
    [
        pytest.param(InvalidChainID.MAX_AUTH_CHAIN_ID, id="auth_chain_id=2**256-1"),
        pytest.param(
            InvalidChainID.CORRECT_CHAIN_ID_PLUS_ONE, id="auth_chain_id=correct_chain_id+1"
        ),
        pytest.param(
            InvalidChainID.CORRECT_CHAIN_ID_MINUS_ONE, id="auth_chain_id=correct_chain_id-1"
        ),
    ],
)
def test_valid_tx_invalid_chain_id(
    state_test: StateTestFiller,
    pre: Alloc,
    chain_config: ChainConfig,
    invalid_chain_id_case: InvalidChainID,
) -> None:
    """
    Test sending a transaction where the chain id field does not match the
    current chain's id.
    """
    auth_signer = pre.fund_eoa(auth_account_start_balance)

    success_slot = 1
    return_slot = 2

    set_code = Op.RETURN(0, 1)
    set_code_to_address = pre.deploy_contract(set_code)

    if invalid_chain_id_case == InvalidChainID.MAX_AUTH_CHAIN_ID:
        auth_chain_id = Spec.MAX_AUTH_CHAIN_ID
    elif invalid_chain_id_case == InvalidChainID.CORRECT_CHAIN_ID_PLUS_ONE:
        auth_chain_id = chain_config.chain_id + 1
    elif invalid_chain_id_case == InvalidChainID.CORRECT_CHAIN_ID_MINUS_ONE:
        auth_chain_id = chain_config.chain_id - 1
        if auth_chain_id == 0:
            pytest.skip("Cannot use correct_chain_id-1 as invalid chain ID")
    else:
        raise ValueError(f"Invalid chain ID case: {invalid_chain_id_case}")

    authorization = AuthorizationTuple(
        address=set_code_to_address,
        nonce=0,
        chain_id=auth_chain_id,
        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],
        error=None,
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account.NONEXISTENT,
            entry_address: Account(
                storage={
                    success_slot: 1,
                    return_slot: 0,
                },
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) invalid_chain_id_case
...fork_Prague-state_test-auth_chain_id=2**256-1 2**256-1
...fork_Prague-state_test-auth_chain_id=correct_chain_id+1 correct_chain_id+1
...fork_Prague-state_test-auth_chain_id=correct_chain_id-1 correct_chain_id-1
...fork_Prague-blockchain_test_from_state_test-auth_chain_id=2**256-1 2**256-1
...fork_Prague-blockchain_test_from_state_test-auth_chain_id=correct_chain_id+1 correct_chain_id+1
...fork_Prague-blockchain_test_from_state_test-auth_chain_id=correct_chain_id-1 correct_chain_id-1
...fork_Osaka-state_test-auth_chain_id=2**256-1 2**256-1
...fork_Osaka-state_test-auth_chain_id=correct_chain_id+1 correct_chain_id+1
...fork_Osaka-state_test-auth_chain_id=correct_chain_id-1 correct_chain_id-1
...fork_Osaka-blockchain_test_from_state_test-auth_chain_id=2**256-1 2**256-1
...fork_Osaka-blockchain_test_from_state_test-auth_chain_id=correct_chain_id+1 correct_chain_id+1
...fork_Osaka-blockchain_test_from_state_test-auth_chain_id=correct_chain_id-1 correct_chain_id-1