Skip to content

test_bal_7002_request_invalid()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7002.py::test_bal_7002_request_invalid@21507778.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7002.py::test_bal_7002_request_invalid --fork Amsterdam

Ensure BAL correctly handles invalid withdrawal request scenarios.

Tests various failure modes: - insufficient_fee: Transaction reverts due to fee below minimum - calldata_too_short: Transaction reverts due to short calldata (55 bytes) - calldata_too_long: Transaction reverts due to long calldata (57 bytes) - oog: Transaction runs out of gas before completion - invalid_call_type_*: Contract call via DELEGATECALL/STATICCALL/CALLCODE - contract_reverts: Contract calls system contract but reverts after

In all cases: - Sender's nonce increments (transaction executed) - Sender pays gas costs - System contract is accessed during dequeue but has no state changes - No withdrawal request is queued

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7002.py
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
@pytest.mark.parametrize(
    "interaction",
    [
        pytest.param(
            WithdrawalRequestTransaction(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=0,  # Below MIN_WITHDRAWAL_REQUEST_FEE
                        valid=False,
                    )
                ]
            ),
            id="insufficient_fee",
        ),
        pytest.param(
            WithdrawalRequestTransaction(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        calldata_modifier=lambda x: x[
                            :-1
                        ],  # 55 bytes instead of 56
                        valid=False,
                    )
                ]
            ),
            id="calldata_too_short",
        ),
        pytest.param(
            WithdrawalRequestTransaction(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        calldata_modifier=lambda x: (
                            x + b"\x00"
                        ),  # 57 bytes instead of 56
                        valid=False,
                    )
                ]
            ),
            id="calldata_too_long",
        ),
        pytest.param(
            WithdrawalRequestTransaction(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        gas_limit=25_000,  # Insufficient gas
                        valid=False,
                    )
                ]
            ),
            id="oog",
        ),
        pytest.param(
            WithdrawalRequestContract(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        valid=False,
                    )
                ],
                call_type=Op.DELEGATECALL,
            ),
            id="invalid_call_type_delegatecall",
        ),
        pytest.param(
            WithdrawalRequestContract(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        valid=False,
                    )
                ],
                call_type=Op.STATICCALL,
            ),
            id="invalid_call_type_staticcall",
        ),
        pytest.param(
            WithdrawalRequestContract(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        valid=False,
                    )
                ],
                call_type=Op.CALLCODE,
            ),
            id="invalid_call_type_callcode",
        ),
        pytest.param(
            WithdrawalRequestContract(
                requests=[
                    WithdrawalRequest(
                        validator_pubkey=0x01,
                        amount=0,
                        fee=Spec7002.get_fee(0),
                        valid=False,
                    )
                ],
                extra_code=Op.REVERT(0, 0),
            ),
            id="contract_reverts",
        ),
    ],
)
def test_bal_7002_request_invalid(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    interaction: WithdrawalRequestInteractionBase,
) -> None:
    """
    Ensure BAL correctly handles invalid withdrawal request scenarios.

    Tests various failure modes:
    - insufficient_fee: Transaction reverts due to fee below minimum
    - calldata_too_short: Transaction reverts due to short calldata (55 bytes)
    - calldata_too_long: Transaction reverts due to long calldata (57 bytes)
    - oog: Transaction runs out of gas before completion
    - invalid_call_type_*: Contract call via DELEGATECALL/STATICCALL/CALLCODE
    - contract_reverts: Contract calls system contract but reverts after

    In all cases:
    - Sender's nonce increments (transaction executed)
    - Sender pays gas costs
    - System contract is accessed during dequeue but has no state changes
    - No withdrawal request is queued
    """
    # Use helper to set up pre-state and get transaction
    prepared = interaction.update_pre(pre)
    tx = prepared.transactions()[0]
    alice = prepared.sender_account

    # Build account expectations
    account_expectations = {
        alice: BalAccountExpectation(
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
        ),
        Spec7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS: BalAccountExpectation(
            storage_reads=[
                Spec7002.EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT,
                Spec7002.WITHDRAWAL_REQUEST_COUNT_STORAGE_SLOT,
                Spec7002.WITHDRAWAL_REQUEST_QUEUE_HEAD_STORAGE_SLOT,
                Spec7002.WITHDRAWAL_REQUEST_QUEUE_TAIL_STORAGE_SLOT,
            ],
            storage_changes=[],
        ),
    }

    # For all invalid scenarios, system contract should have reads but
    # no write since the dequeue operation still happens post-execution
    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=account_expectations
        ),
    )

    post: dict = {
        alice: Account(nonce=1),
        Spec7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS: Account(storage={}),
    }

    # Add relay contract to post-state for contract scenarios
    if isinstance(prepared, WithdrawalRequestContract):
        post[prepared.contract_address] = Account()

    blockchain_test(
        pre=pre,
        blocks=[block],
        post=post,
    )

Parametrized Test Cases

This test generates 8 parametrized test cases across 1 fork.