Skip to content

test_bal_withdrawal_predeploy_balance_observed_cross_tx()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_cross_index.py::test_bal_withdrawal_predeploy_balance_observed_cross_tx@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_cross_index.py::test_bal_withdrawal_predeploy_balance_observed_cross_tx --fork Amsterdam

Test that a subsequent transaction observes the post-state balance of the withdrawal predeploy after a prior transaction in the same block paid the withdrawal fee.

Within one block
  • tx 0: EOA sends fee wei to WITHDRAWAL_REQUEST_PREDEPLOY with a valid withdrawal-request calldata. The predeploy retains the fee, so its balance transitions 0 -> fee (BAL balance_change at index 1).
  • tx 1: calls a reader contract that performs SSTORE(0, BALANCE(WITHDRAWAL_REQUEST_PREDEPLOY)).

Per EIP-7928, the BAL prefix consumed by tx 1's execution must include tx 0's balance change for the predeploy, so the BALANCE opcode returns fee and slot 0 of the reader ends at fee. The predeploy is also touched by the prepare-block system call (storage reads at slots 0-3), making its address one whose pre-block snapshot would otherwise mask the BAL overlay if consulted ahead of the BAL prefix.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_cross_index.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
def test_bal_withdrawal_predeploy_balance_observed_cross_tx(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Test that a subsequent transaction observes the post-state balance of the
    withdrawal predeploy after a prior transaction in the same block paid the
    withdrawal fee.

    Within one block:
      - tx 0: EOA sends `fee` wei to WITHDRAWAL_REQUEST_PREDEPLOY with a valid
        withdrawal-request calldata. The predeploy retains the fee, so its
        balance transitions 0 -> fee (BAL balance_change at index 1).
      - tx 1: calls a reader contract that performs
        `SSTORE(0, BALANCE(WITHDRAWAL_REQUEST_PREDEPLOY))`.

    Per EIP-7928, the BAL prefix consumed by tx 1's execution must include
    tx 0's balance change for the predeploy, so the BALANCE opcode returns
    `fee` and slot 0 of the reader ends at `fee`. The predeploy is also
    touched by the prepare-block system call (storage reads at slots 0-3),
    making its address one whose pre-block snapshot would otherwise mask the
    BAL overlay if consulted ahead of the BAL prefix.
    """
    fee = 1  # Spec7002.get_fee(0) is 1 when excess == 0; one request fits.
    withdrawal_calldata = (
        (b"\x01" + b"\x00" * 47)  # 48-byte validator pubkey
        + (b"\x00" * 8)  # 8-byte amount
    )

    sender_0 = pre.fund_eoa()
    sender_1 = pre.fund_eoa()

    reader = pre.deploy_contract(
        code=Bytecode(
            Op.SSTORE(
                0,
                Op.BALANCE(WITHDRAWAL_REQUEST_ADDRESS),
            )
            + Op.STOP
        ),
    )

    tx_pay_fee = Transaction(
        sender=sender_0,
        to=WITHDRAWAL_REQUEST_ADDRESS,
        value=fee,
        data=withdrawal_calldata,
    )

    tx_read_balance = Transaction(sender=sender_1, to=reader)

    expected_block_access_list = BlockAccessListExpectation(
        account_expectations={
            # Predeploy: tx 0 records the fee as a BAL balance_change at
            # index 1; the framework also verifies the system-call storage
            # behaviour through its own post-execution invariants.
            WITHDRAWAL_REQUEST_ADDRESS: BalAccountExpectation(
                balance_changes=[
                    BalBalanceChange(
                        block_access_index=1,
                        post_balance=fee,
                    ),
                ],
            ),
            # Reader: tx 1 stores the predeploy balance at slot 0.
            # If the consumed BAL prefix did not surface tx 0's balance
            # change to BALANCE, post_value would be 0 and the assertion
            # below would fail.
            reader: BalAccountExpectation(
                storage_changes=[
                    BalStorageSlot(
                        slot=0,
                        slot_changes=[
                            BalStorageChange(
                                block_access_index=2,
                                post_value=fee,
                            ),
                        ],
                    ),
                ],
            ),
            sender_0: BalAccountExpectation(
                nonce_changes=[
                    BalNonceChange(block_access_index=1, post_nonce=1),
                ],
            ),
            sender_1: BalAccountExpectation(
                nonce_changes=[
                    BalNonceChange(block_access_index=2, post_nonce=1),
                ],
            ),
        }
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx_pay_fee, tx_read_balance],
                expected_block_access_list=expected_block_access_list,
            ),
        ],
        post={
            reader: Account(storage={0: fee}),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.