Skip to content

test_blake2b_invalid_input()

Documentation for tests/istanbul/eip152_blake2/test_blake2.py::test_blake2b_invalid_input@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/istanbul/eip152_blake2/test_blake2.py::test_blake2b_invalid_input --fork Amsterdam

Test BLAKE2b precompile invalid calls using different gas limits.

Source code in tests/istanbul/eip152_blake2/test_blake2.py
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
@pytest.mark.valid_from("Istanbul")
@pytest.mark.parametrize("call_opcode", [Op.CALL, Op.CALLCODE])
@pytest.mark.parametrize(
    ["data"],
    [
        pytest.param(
            Bytes(),
            id="empty-input",
        ),
        pytest.param(
            Bytes(b"\0" * 212),
            id="one_too_short",
        ),
        pytest.param(
            Bytes(b"\0" * 214),
            id="one_too_long",
        ),
        pytest.param(
            Blake2bInput(
                rounds_length=3,
            ),
            id="invalid_rounds_length_short",
        ),
        pytest.param(
            Blake2bInput(
                rounds_length=5,
            ),
            id="invalid_rounds_length_long",
        ),
        pytest.param(
            Blake2bInput(
                f=2,
            ),
            id="invalid_final_block_flag_value_0x02",
        ),
        pytest.param(
            Blake2bInput(
                rounds=0,
                rounds_length=0,
                h="00",
                m="00",
                t_0=0,
                t_1=SpecTestVectors.BLAKE2_OFFSET_COUNTER_1,
                f=0,
            ),
            id="RFC_7693_zero_input",
        ),
        # Excessive number of rounds expects to run out of gas, valid otherwise
        pytest.param(
            Blake2bInput(
                rounds=4294967295,
            ),
            id="oog-rounds-4294967295",
        ),
    ],
)
@pytest.mark.parametrize("precompile_gas", [0, 200_000])
def test_blake2b_invalid_input(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    blake2b_contract_bytecode: Bytecode,
    data: Blake2bInput | bytes,
) -> None:
    """Test BLAKE2b precompile invalid calls using different gas limits."""
    account = pre.deploy_contract(
        blake2b_contract_bytecode,
        storage={0: 0xDEADBEEF, 1: 0xDEADBEEF, 2: 0xDEADBEEF},
    )
    sender = pre.fund_eoa()
    tx = Transaction(to=account, data=data, sender=sender)

    post = {
        account: Account(
            storage={0: 0x0, 1: 0x0, 2: 0x0},
            nonce=0x1,
        )
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 32 parametrized test cases across 9 forks.