Skip to content

test_blake2b_gas()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test BLAKE2b precompile with different gas limits.

Source code in tests/istanbul/eip152_blake2/test_blake2.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
@pytest.mark.valid_from("Istanbul")
@pytest.mark.parametrize("call_opcode", [Op.CALL, Op.CALLCODE])
@pytest.mark.parametrize(
    ["data", "output"],
    [
        pytest.param(
            Blake2bInput(
                rounds=0,
            ),
            ExpectedOutput(
                data_1="0x08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5",
                data_2="0xd282e6ad7f520e511f6c3e2b8c68059b9442be0454267ce079217e1319cde05b",
            ),
            id="EIP-152-case3-data4-gas-limit",
        ),
        pytest.param(
            Blake2bInput(),
            ExpectedOutput(
                data_1="0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1",
                data_2="0x7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923",
            ),
            id="EIP-152-case4-data5-gas-limit",
        ),
        pytest.param(
            Blake2bInput(
                f=False,
            ),
            ExpectedOutput(
                data_1="0x75ab69d3190a562c51aef8d88f1c2775876944407270c42c9844252c26d28752",
                data_2="0x98743e7f6d5ea2f2d3e8d226039cd31b4e426ac4f2d3d666a610c2116fde4735",
            ),
            id="EIP-152-case5-data6-gas-limit",
        ),
        pytest.param(
            Blake2bInput(
                rounds=1,
            ),
            ExpectedOutput(
                data_1="0xb63a380cb2897d521994a85234ee2c181b5f844d2c624c002677e9703449d2fb",
                data_2="0xa551b3a8333bcdf5f2f7e08993d53923de3d64fcc68c034e717b9293fed7a421",
            ),
            id="EIP-152-case6-data7-gas-limit",
        ),
        pytest.param(
            Blake2bInput(
                rounds=0,
                h="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                m="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                t_0=0,
                t_1=SpecTestVectors.BLAKE2_OFFSET_COUNTER_1,
                f=0,
            ),
            ExpectedOutput(
                data_1="0x08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5",
                data_2="0xd182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
            ),
            id="EIP-152-case7-data8-gas-limit",
        ),
    ],
)
@pytest.mark.parametrize(
    "precompile_gas_modifier",
    [
        pytest.param(0, id="sufficient_gas"),
        pytest.param(-1, id="insufficient_gas"),
    ],
)
@pytest.mark.eels_base_coverage
def test_blake2b_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    blake2b_contract_bytecode: Bytecode,
    data: Blake2bInput | bytes,
    precompile_gas: int,
    output: ExpectedOutput,
    precompile_gas_modifier: int,
) -> None:
    """Test BLAKE2b precompile with different gas limits."""
    sufficient_gas = precompile_gas_modifier == 0
    if not sufficient_gas and precompile_gas == 0:
        pytest.skip("Precompile cost is zero, cannot run oog")

    account = pre.deploy_contract(
        blake2b_contract_bytecode, storage={0: 0xDEADBEEF}
    )
    sender = pre.fund_eoa()

    tx = Transaction(to=account, data=data, sender=sender)

    post = {
        account: Account(
            storage={0: 0x1, 1: output.data_1, 2: output.data_2}
            if sufficient_gas
            else {0: 0x0, 1: 0x0, 2: 0x0}
        )
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 20 parametrized test cases across 9 forks.