Skip to content

test_bal_invalid_extraneous_entries()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_extraneous_entries@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_extraneous_entries --fork Amsterdam

Test that clients reject blocks where BAL contains extraneous entries.

Alice sends 100 wei to Oracle (1 transaction). Oracle reads storage slot 0. Charlie is uninvolved in this transaction. A valid BAL is created containing nonce change for Alice, balance change and storage read for Oracle which is further modified as:

  • extra_nonce: Extra nonce change for Oracle.
  • extra_balance: Extra balance change for uninvolved Charlie.
  • extra_code: Extra code change for Oracle.
  • extra_storage_write_touched: Extra storage write for an already read slot (slot 0) for Oracle.
  • extra_storage_write_untouched: Extra storage write for an unread slot (slot 1) for Oracle.
  • extra_storage_write_uninvolved_account: Extra storage write for uninvolved account (Charlie) that isn't accessed at all.
  • extra_account_access: Uninvolved account (Charlie) added to BAL entirely.
  • extra_storage_read: Extra storage read for Oracle (slot 999).

BAL is corrupted with extraneous entries at various block_access_index values: - bal_index=1: current transaction - bal_index=2: system transaction (tx_count + 1) - bal_index=3: beyond system transaction (tx_count + 2)

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
@pytest.mark.valid_from("Amsterdam")
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "modifier",
    [
        pytest.param(
            lambda idx, **actors: append_change(
                account=actors["oracle"],
                change=BalNonceChange(block_access_index=idx, post_nonce=999),
            ),
            id="extra_nonce",
        ),
        pytest.param(
            lambda idx, **actors: append_account(
                BalAccountChange(
                    address=actors["charlie"],
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=idx, post_balance=999
                        )
                    ],
                )
            ),
            id="extra_balance",
        ),
        pytest.param(
            lambda idx, **actors: append_change(
                account=actors["oracle"],
                change=BalCodeChange(
                    block_access_index=idx, new_code=b"Amsterdam"
                ),
            ),
            id="extra_code",
        ),
        pytest.param(
            lambda idx, **actors: append_storage(
                address=actors["oracle"],
                slot=0,
                change=BalStorageChange(
                    block_access_index=idx, post_value=0xCAFE
                ),
            ),
            id="extra_storage_write_touched",
        ),
        pytest.param(
            lambda idx, **actors: append_storage(
                address=actors["oracle"],
                slot=1,
                change=BalStorageChange(
                    block_access_index=idx, post_value=0xCAFE
                ),
            ),
            id="extra_storage_write_untouched",
        ),
        pytest.param(
            lambda idx, **actors: append_account(
                BalAccountChange(
                    address=actors["charlie"],
                    storage_changes=[
                        BalStorageSlot(
                            slot=0,
                            slot_changes=[
                                BalStorageChange(
                                    block_access_index=idx,
                                    post_value=0xDEAD,
                                )
                            ],
                        )
                    ],
                )
            ),
            id="extra_storage_write_uninvolved_account",
        ),
        pytest.param(
            lambda idx, **actors: append_account(  # noqa: ARG005
                BalAccountChange(
                    address=actors["charlie"],
                )
            ),
            id="extra_account_access",
        ),
        pytest.param(
            lambda idx, **actors: append_storage(  # noqa: ARG005
                address=actors["oracle"],
                slot=999,
                read=True,
            ),
            id="extra_storage_read",
        ),
    ],
)
@pytest.mark.parametrize(
    "bal_index",
    [
        pytest.param(1, id="same_tx"),
        pytest.param(2, id="system_tx"),
        pytest.param(3, id="out_of_bounds"),
    ],
)
def test_bal_invalid_extraneous_entries(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    modifier: Callable,
    bal_index: int,
) -> None:
    """
    Test that clients reject blocks where BAL contains extraneous entries.

    Alice sends 100 wei to Oracle (1 transaction). Oracle reads storage slot 0.
    Charlie is uninvolved in this transaction.
    A valid BAL is created containing nonce change for Alice, balance change
    and storage read for Oracle which is further modified as:

    - extra_nonce: Extra nonce change for Oracle.
    - extra_balance: Extra balance change for uninvolved Charlie.
    - extra_code: Extra code change for Oracle.
    - extra_storage_write_touched: Extra storage write for an already read slot
      (slot 0) for Oracle.
    - extra_storage_write_untouched: Extra storage write for an unread slot
      (slot 1) for Oracle.
    - extra_storage_write_uninvolved_account: Extra storage write for
      uninvolved account (Charlie) that isn't accessed at all.
    - extra_account_access: Uninvolved account (Charlie) added to BAL entirely.
    - extra_storage_read: Extra storage read for Oracle (slot 999).

    BAL is corrupted with extraneous entries at various block_access_index
    values:
    - bal_index=1: current transaction
    - bal_index=2: system transaction (tx_count + 1)
    - bal_index=3: beyond system transaction (tx_count + 2)
    """
    transfer_value = 100

    alice = pre.fund_eoa()
    oracle = pre.deploy_contract(code=Op.SLOAD(0), storage={0: 42})
    charlie = pre.fund_eoa(amount=0)

    tx = Transaction(
        sender=alice,
        to=oracle,
        value=transfer_value,
        gas_limit=1_000_000,
    )

    blockchain_test(
        pre=pre,
        # The block reverts and the post state remains unchanged.
        post=pre,
        blocks=[
            Block(
                txs=[tx],
                exception=BlockException.INVALID_BLOCK_ACCESS_LIST,
                expected_block_access_list=BlockAccessListExpectation(
                    # Valid BAL expectation: nonce change for Alice,
                    # balance change and storage read for Oracle.
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                )
                            ],
                        ),
                        oracle: BalAccountExpectation(
                            balance_changes=[
                                BalBalanceChange(
                                    block_access_index=1,
                                    post_balance=transfer_value,
                                )
                            ],
                            storage_reads=[0],
                        ),
                    }
                ).modify(
                    # The parameterized modifier is applied to the BAL
                    # which adds an extraneous entry.
                    modifier(
                        idx=bal_index,
                        alice=alice,
                        oracle=oracle,
                        charlie=charlie,
                    )
                ),
            )
        ],
    )

Parametrized Test Cases

This test generates 24 parametrized test cases across 1 fork.