Skip to content

test_bal_invalid_duplicate_entries()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_duplicate_entries@2119b382.

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_duplicate_entries --fork Amsterdam

Test that clients reject blocks where BAL contains duplicate entries.

Oracle writes storage, reads storage, and CREATEs a small contract. Verify the EIP-7928 uniqueness constraints: each block_access_index must appear at most once per change list (nonce, balance, code, slot), each storage key at most once in storage_changes and storage_reads, and no key in both.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
@pytest.mark.valid_from("Amsterdam")
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "modifier",
    [
        pytest.param(
            lambda alice, **_: duplicate_nonce_change(alice, 1),
            id="duplicate_nonce_change",
        ),
        pytest.param(
            lambda oracle, **_: duplicate_balance_change(oracle, 1),
            id="duplicate_balance_change",
        ),
        pytest.param(
            lambda created, **_: duplicate_code_change(created, 1),
            id="duplicate_code_change",
        ),
        pytest.param(
            lambda oracle, **_: duplicate_storage_slot(oracle, 1),
            id="duplicate_storage_slot",
        ),
        pytest.param(
            lambda oracle, **_: duplicate_storage_read(oracle, 2),
            id="duplicate_storage_read",
        ),
        pytest.param(
            lambda oracle, **_: duplicate_slot_change(oracle, 1, 1),
            id="duplicate_slot_change",
        ),
        pytest.param(
            lambda oracle, **_: insert_storage_read(oracle, 1),
            id="storage_key_in_both_changes_and_reads",
        ),
    ],
)
def test_bal_invalid_duplicate_entries(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    modifier: Callable,
) -> None:
    """
    Test that clients reject blocks where BAL contains duplicate entries.

    Oracle writes storage, reads storage, and CREATEs a small contract.
    Verify the EIP-7928 uniqueness constraints: each block_access_index
    must appear at most once per change list (nonce, balance, code,
    slot), each storage key at most once in storage_changes and
    storage_reads, and no key in both.
    """
    alice = pre.fund_eoa()
    deploy_code = b"\x13\x37"
    initcode = Initcode(deploy_code=deploy_code)
    initcode_word = int.from_bytes(bytes(initcode).ljust(32, b"\x00"), "big")
    oracle = pre.deploy_contract(
        code=(
            Op.SSTORE(1, 0x42)
            + Op.SLOAD(2)
            + Op.MSTORE(0, initcode_word)
            + Op.CREATE(0, 0, len(initcode))
        ),
        storage={2: 0x84},
    )
    created = compute_create_address(address=oracle, nonce=1)

    tx = Transaction(
        sender=alice,
        to=oracle,
        value=100,
    )

    blockchain_test(
        pre=pre,
        post=pre,
        blocks=[
            Block(
                txs=[tx],
                exception=BlockException.INVALID_BLOCK_ACCESS_LIST,
                expected_block_access_list=BlockAccessListExpectation(
                    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=100,
                                ),
                            ],
                            storage_changes=[
                                BalStorageSlot(
                                    slot=1,
                                    slot_changes=[
                                        BalStorageChange(
                                            block_access_index=1,
                                            post_value=0x42,
                                        ),
                                    ],
                                ),
                            ],
                            storage_reads=[2],
                        ),
                        created: BalAccountExpectation(
                            code_changes=[
                                BalCodeChange(
                                    block_access_index=1,
                                    new_code=deploy_code,
                                ),
                            ],
                        ),
                    }
                ).modify(
                    modifier(
                        alice=alice,
                        oracle=oracle,
                        created=created,
                    )
                ),
            )
        ],
    )

Parametrized Test Cases

This test generates 7 parametrized test cases across 1 fork.