Skip to content

test_blobhash_invalid_blob_index()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_invalid_blob_index@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_invalid_blob_index --fork Prague

Tests that the BLOBHASH opcode returns a zeroed bytes32 value for invalid indexes.

Includes cases where the index is negative (index < 0) or exceeds the maximum number of blob_versioned_hash values stored: (index >= len(tx.message.blob_versioned_hashes)).

It confirms that the returned value is a zeroed bytes32 for each case.

Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
@pytest.mark.parametrize(
    "scenario",
    [
        "invalid_calls",
    ],
)
def test_blobhash_invalid_blob_index(
    pre: Alloc,
    fork: Fork,
    blockchain_test: BlockchainTestFiller,
    scenario: str,
    max_blobs_per_block: int,
):
    """
    Tests that the `BLOBHASH` opcode returns a zeroed `bytes32` value for invalid
    indexes.

    Includes cases where the index is negative (`index < 0`) or
    exceeds the maximum number of `blob_versioned_hash` values stored:
    (`index >= len(tx.message.blob_versioned_hashes)`).

    It confirms that the returned value is a zeroed `bytes32` for each case.
    """
    total_blocks = 5
    blobhash_calls = BlobhashScenario.generate_blobhash_bytecode(
        scenario_name=scenario, max_blobs_per_block=max_blobs_per_block
    )
    sender = pre.fund_eoa()
    blocks: List[Block] = []
    post = {}
    for i in range(total_blocks):
        address = pre.deploy_contract(blobhash_calls)
        blob_per_block = (i % max_blobs_per_block) + 1
        blobs = [random_blob_hashes[blob] for blob in range(blob_per_block)]
        blocks.append(
            Block(
                txs=[
                    Transaction(
                        ty=Spec.BLOB_TX_TYPE,
                        sender=sender,
                        to=address,
                        gas_limit=3_000_000,
                        data=Hash(0),
                        access_list=[],
                        max_fee_per_gas=10,
                        max_priority_fee_per_gas=10,
                        max_fee_per_blob_gas=(fork.min_base_fee_per_blob_gas() * 10),
                        blob_versioned_hashes=blobs,
                    )
                ]
            )
        )
        post[address] = Account(
            storage={
                index: (0 if index < 0 or index >= blob_per_block else blobs[index])
                for index in range(
                    -total_blocks,
                    blob_per_block + (total_blocks - (i % max_blobs_per_block)),
                )
            }
        )
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated) scenario
...fork_Cancun-blockchain_test-scenario_invalid_calls invalid_calls
...fork_Prague-blockchain_test-scenario_invalid_calls invalid_calls
...fork_Osaka-blockchain_test-scenario_invalid_calls invalid_calls