Skip to content

Commit 4d7c9e5

Browse files
raxhvlfselmo
authored andcommitted
✨ feat(tests): test_bal_delegated_storage_reads
1 parent a1fbc90 commit 4d7c9e5

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,11 @@ def test_bal_delegated_storage_writes(
567567
alice = pre.fund_eoa()
568568

569569
# TargetContract that writes 0x42 to slot 0x01
570-
target_code = Op.SSTORE(0x01, 0x42) + Op.STOP
570+
target_code = Op.SSTORE(0x01, 0x42)
571571
target_contract = pre.deploy_contract(code=target_code)
572572

573573
# Oracle contract that uses delegated opcode to execute TargetContract's code
574-
oracle_code = delegated_opcode(target_contract) + Op.STOP
574+
oracle_code = delegated_opcode(target_contract)
575575
oracle_contract = pre.deploy_contract(code=oracle_code)
576576

577577
tx = Transaction(
@@ -601,3 +601,55 @@ def test_bal_delegated_storage_writes(
601601
)
602602

603603
blockchain_test(pre=pre, blocks=[block], post={})
604+
605+
606+
@pytest.mark.parametrize(
607+
"delegated_opcode",
608+
[
609+
pytest.param(
610+
lambda target_addr: Op.DELEGATECALL(50000, target_addr, 0, 0, 0, 0), id="delegatecall"
611+
),
612+
pytest.param(
613+
lambda target_addr: Op.CALLCODE(50000, target_addr, 0, 0, 0, 0, 0), id="callcode"
614+
),
615+
],
616+
)
617+
def test_bal_delegated_storage_reads(
618+
pre: Alloc,
619+
blockchain_test: BlockchainTestFiller,
620+
delegated_opcode,
621+
):
622+
"""Ensure BAL captures delegated storage reads via DELEGATECALL and CALLCODE."""
623+
alice = pre.fund_eoa()
624+
625+
# TargetContract that reads from slot 0x01
626+
target_code = Op.SLOAD(0x01) + Op.STOP
627+
target_contract = pre.deploy_contract(code=target_code)
628+
629+
# Oracle contract with storage slot 0x01 = 0x42,
630+
# uses delegated opcode to execute TargetContract's code
631+
oracle_code = delegated_opcode(target_contract)
632+
oracle_contract = pre.deploy_contract(code=oracle_code, storage={0x01: 0x42})
633+
634+
tx = Transaction(
635+
sender=alice,
636+
to=oracle_contract,
637+
gas_limit=1_000_000,
638+
)
639+
640+
block = Block(
641+
txs=[tx],
642+
expected_block_access_list=BlockAccessListExpectation(
643+
account_expectations={
644+
alice: BalAccountExpectation(
645+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
646+
),
647+
oracle_contract: BalAccountExpectation(
648+
storage_reads=[0x01],
649+
),
650+
target_contract: BalAccountExpectation(),
651+
}
652+
),
653+
)
654+
655+
blockchain_test(pre=pre, blocks=[block], post={})

tests/amsterdam/eip7928_block_level_access_lists/test_cases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| `test_bal_call_with_value_transfer` | Ensure BAL captures balance changes from `CALL` opcode with value transfer | Alice calls `Oracle` contract (200 wei balance) which uses `CALL` opcode to transfer 100 wei to Bob (0 wei balance). | BAL MUST include Alice (nonce changes), Oracle (balance change to 100 wei), and Bob (balance change to 100 wei). | ✅ Completed |
1414
| `test_bal_callcode_with_value_transfer` | Ensure BAL captures balance changes from `CALLCODE` opcode with value transfer | Alice calls `Oracle` contract (200 wei balance) which uses `CALLCODE` opcode to execute `TargetContract`'s code with 100 wei value transfer to Bob (0 wei balance). | BAL MUST include Alice (nonce changes), `Oracle` (balance change to 100 wei), Bob (balance change to 100 wei), and `TargetContract` (empty changes). | ✅ Completed |
1515
| `test_bal_delegated_storage_writes` | Ensure BAL captures delegated storage writes via `DELEGATECALL` and `CALLCODE` | Alice calls `Oracle` contract which uses `DELEGATECALL`/`CALLCODE` to `TargetContract` that writes `0x42` to slot `0x01`. | BAL MUST include Alice (nonce changes), `Oracle` (storage changes for slot `0x01` = `0x42`), and `TargetContract` (empty changes). | ✅ Completed |
16+
| `test_bal_delegated_storage_reads` | Ensure BAL captures delegated storage reads via `DELEGATECALL` and `CALLCODE` | Alice calls `Oracle` contract (with slot `0x01` = `0x42`) which uses `DELEGATECALL`/`CALLCODE` to `TargetContract` that reads from slot `0x01`. | BAL MUST include Alice (nonce changes), `Oracle` (storage reads for slot `0x01`), and `TargetContract` (empty changes). | ✅ Completed |
1617
| `test_bal_2930_slot_listed_but_untouched` | Ensure 2930 access list alone doesn’t appear in BAL | Include `(KV, S=0x01)` in tx’s EIP-2930 access list; tx executes code that does **no** `SLOAD`/`SSTORE` to `S` (e.g., pure arithmetic/log). | BAL **MUST NOT** contain any entry for `(KV, S)` — neither reads nor writes — because the slot wasn’t touched. | 🟡 Planned |
1718
| `test_bal_2930_slot_listed_and_modified` | Ensure BAL records writes only because the slot is touched | Same access list as above, but tx executes `SSTORE` to `S`. | BAL **MUST** include `storage_changes` for `(KV, S)` (and no separate read record for that slot if implementation deduplicates). Presence in the access list is irrelevant; inclusion is due to the actual write. | 🟡 Planned |
1819
| `test_bal_7702_delegated_create` | BAL tracks EIP-7702 delegation indicator write and contract creation | Alice sends a type-4 (7702) tx authorizing herself to delegate to `Deployer` code which executes `CREATE` | BAL MUST include for **Alice**: `code_changes` (delegation indicator), `nonce_changes` (increment from 7702 processing), and `balance_changes` (post-gas). For **Child**: `code_changes` (runtime bytecode) and `nonce_changes = 1`. | 🟡 Planned |

0 commit comments

Comments
 (0)