Skip to content

test_invalid_history_contract_calls()

Documentation for tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_invalid_history_contract_calls@verkle@v0.0.6.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_invalid_history_contract_calls --fork=Prague --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Prague:

fill -v tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_invalid_history_contract_calls --until=Prague

Test calling the history contract with invalid block numbers, such as blocks from the future or overflowing block numbers.

Also test the BLOCKHASH opcode with the same block numbers, which should not affect the behavior of the opcode, even after verkle.

Source code in tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
@pytest.mark.parametrize(
    "block_number,reverts",
    [
        pytest.param(1, False, id="current_block"),
        pytest.param(2, False, id="future_block"),
        pytest.param(2**64 - 1, False, id="2**64-1"),
        pytest.param(2**64, True, id="2**64"),
    ],
)
@pytest.mark.valid_from("Prague")
def test_invalid_history_contract_calls(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    block_number: int,
    reverts: bool,
):
    """
    Test calling the history contract with invalid block numbers, such as blocks from the future
    or overflowing block numbers.

    Also test the BLOCKHASH opcode with the same block numbers, which should not affect the
    behavior of the opcode, even after verkle.
    """
    storage = Storage()

    return_code_slot = storage.store_next(not reverts)
    returned_block_hash_slot = storage.store_next(0)
    block_hash_opcode_slot = storage.store_next(0)

    # Check the first block outside of the window if any
    code = (
        Op.MSTORE(0, block_number)
        + Op.SSTORE(
            return_code_slot, Op.CALL(Op.GAS, Spec.HISTORY_STORAGE_ADDRESS, 0, 0, 32, 32, 64)
        )
        + Op.SSTORE(returned_block_hash_slot, Op.MLOAD(32))
        + Op.SSTORE(block_hash_opcode_slot, Op.BLOCKHASH(block_number))
    )
    check_contract_address = pre.deploy_contract(code, storage=storage.canary())

    txs = [
        Transaction(
            to=check_contract_address,
            gas_limit=10_000_000,
            sender=pre.fund_eoa(),
        )
    ]
    post = {check_contract_address: Account(storage=storage)}

    blocks = [Block(txs=txs)]
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
        reverts=reverts,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Skipped Parameters

For more concise readability, the table below does not list the following parameter values: fork, blockchain_test, state_test, state_test_only, eof_test, eof_state_test.

Test ID block_number reverts
current_block 1 False
future_block 2 False
2**64-1 18446744073709551615 False
2**64 18446744073709551616 True