Skip to content

test_bal_cross_tx_reverted_storage_reads()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_cross_tx_reverted_storage_reads@8acae1b0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_cross_tx_reverted_storage_reads --fork Amsterdam

Reverted SSTOREs from two transactions accumulate in one account's storage_reads.

Each transaction succeeds while the frame holding its SSTORE reverts, so both demoted writes must survive their transaction boundary and the block-level list must hold the union of the two slots. Reported in erigontech/erigon#23407.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
def test_bal_cross_tx_reverted_storage_reads(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Reverted `SSTORE`s from two transactions accumulate in one account's
    `storage_reads`.

    Each transaction succeeds while the frame holding its `SSTORE` reverts,
    so both demoted writes must survive their transaction boundary and the
    block-level list must hold the union of the two slots. Reported in
    https://github.com/erigontech/erigon/issues/23407.
    """
    alice = pre.fund_eoa()
    slots = [0x01, 0x02]  # one per transaction
    pre_value = 0xDEAD

    reverting_writer = pre.deploy_contract(
        code=Op.SSTORE(Op.CALLDATALOAD(0), 0x42) + Op.REVERT(0, 0),
        storage=dict.fromkeys(slots, pre_value),
    )
    # Ignores the failed call so the transaction itself succeeds and only
    # `reverting_writer`'s frame is rolled back.
    caller = pre.deploy_contract(
        code=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.POP(
            Op.CALL(
                gas=Op.GAS,
                address=reverting_writer,
                args_offset=0,
                args_size=Op.CALLDATASIZE,
            )
        )
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[
                    Transaction(sender=alice, to=caller, data=Hash(slot))
                    for slot in slots
                ],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                ),
                                BalNonceChange(
                                    block_access_index=2, post_nonce=2
                                ),
                            ],
                        ),
                        caller: BalAccountExpectation.empty(),
                        reverting_writer: BalAccountExpectation(
                            storage_changes=[],
                            storage_reads=slots,
                        ),
                    }
                ),
            )
        ],
        post={
            alice: Account(nonce=2),
            reverting_writer: Account(storage=dict.fromkeys(slots, pre_value)),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.