Skip to content

Commit 13eaf46

Browse files
committed
✨ feat(tests): test_bal_7702_invalid_chain_id_authorization
1 parent 8e78ad8 commit 13eaf46

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,65 @@ def test_bal_7702_invalid_nonce_authorization(
462462
blocks=[block],
463463
post=post,
464464
)
465+
466+
467+
def test_bal_7702_invalid_chain_id_authorization(
468+
pre: Alloc,
469+
blockchain_test: BlockchainTestFiller,
470+
):
471+
"""Ensure BAL handles failed authorization due to wrong chain id."""
472+
alice = pre.fund_eoa()
473+
bob = pre.fund_eoa(amount=0)
474+
relayer = pre.fund_eoa()
475+
oracle = pre.deploy_contract(code=Op.STOP)
476+
477+
tx = Transaction(
478+
sender=relayer, # Sponsored transaction
479+
to=bob,
480+
value=10,
481+
gas_limit=1_000_000,
482+
gas_price=0xA,
483+
authorization_list=[
484+
AuthorizationTuple(
485+
chain_id=999, # Wrong chain id
486+
address=oracle,
487+
nonce=0,
488+
signer=alice,
489+
)
490+
],
491+
)
492+
493+
block = Block(
494+
txs=[tx],
495+
expected_block_access_list=BlockAccessListExpectation(
496+
account_expectations={
497+
# Alice's account must not be read because
498+
# authorization fails before loading her account
499+
alice: None,
500+
# Ensuring silent fail
501+
bob: BalAccountExpectation(
502+
balance_changes=[BalBalanceChange(tx_index=1, post_balance=10)]
503+
),
504+
relayer: BalAccountExpectation(
505+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
506+
),
507+
# Oracle must NOT be present - authorization failed so account never accessed
508+
oracle: None,
509+
}
510+
),
511+
)
512+
513+
post = {
514+
relayer: Account(nonce=1),
515+
bob: Account(balance=10),
516+
}
517+
518+
blockchain_test(
519+
# Set chain id here
520+
# so this test holds if the default is
521+
# ever changed
522+
chain_id=1,
523+
pre=pre,
524+
blocks=[block],
525+
post=post,
526+
)

tests/amsterdam/eip7928_block_level_access_lists/test_cases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
| `test_bal_7702_delegation_clear` | Ensure BAL captures clearing of EOA delegation | Alice first delegates to `Oracle`, then in second tx clears delegation by authorizing to `0x0` address. Each transaction sends 10 wei to Bob. Two variants: (1) Self-funded: Alice sends both 7702 txs herself. (2) Sponsored: `Relayer` sends both 7702 txs on Alice's behalf. | BAL **MUST** include Alice: first tx has `code_changes` (delegation designation `0xef0100\|\|address(Oracle)`), `nonce_changes`. Second tx has `code_changes` (empty code - delegation cleared), `nonce_changes`. Bob: `balance_changes` (receives 10 wei on each tx). For sponsored variant, BAL **MUST** also include `Relayer`: `nonce_changes` for both transactions. `Oracle` and `0x0` address **MUST NOT** be present in BAL - accounts are never accessed. | ✅ Completed |
1919
| `test_bal_7702_delegated_storage_access` | Ensure BAL captures storage operations when calling a delegated EIP-7702 account | Alice has delegated her account to `Oracle`. `Oracle` contract contains code that reads from storage slot `0x01` and writes to storage slot `0x02`. Bob sends 10 wei to Alice (the delegated account), which executes `Oracle`'s code. | BAL **MUST** include Alice: `balance_changes` (receives 10 wei), `storage_changes` for slot `0x02` (write operation performed in Alice's storage), `storage_reads` for slot `0x01` (read operation from Alice's storage). Bob: `nonce_changes` (sender), `balance_changes` (loses 10 wei plus gas costs). `Oracle` (account access). | ✅ Completed |
2020
| `test_bal_7702_invalid_nonce_authorization` | Ensure BAL handles failed authorization due to wrong nonce | `Relayer` sends sponsored transaction to Bob (10 wei transfer succeeds) but Alice's authorization to delegate to `Oracle` uses incorrect nonce, causing silent authorization failure | BAL **MUST** include Alice with empty changes (account access), Bob with `balance_changes` (receives 10 wei), Relayer with `nonce_changes`. **MUST NOT** include `Oracle` (authorization failed, no delegation) | ✅ Completed |
21+
| `test_bal_7702_invalid_chain_id_authorization` | Ensure BAL handles failed authorization due to wrong chain id | `Relayer` sends sponsored transaction to Bob (10 wei transfer succeeds) but Alice's authorization to delegate to `Oracle` uses incorrect chain id, causing authorization failure before account access | BAL **MUST** include Bob with `balance_changes` (receives 10 wei), Relayer with `nonce_changes`. **MUST NOT** include Alice (authorization fails before loading account) or `Oracle` (authorization failed, no delegation) | ✅ Completed |
2122

2223
> ℹ️ Scope describes whether a test spans a single transaction (`tx`) or entire block (`blk`).

0 commit comments

Comments
 (0)