Skip to content

test_blake2b_invalid_input()

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

Generate fixtures for these test cases for Bogota with:

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

Test BLAKE2b precompile invalid calls using different gas limits.

Source code in tests/istanbul/eip152_blake2/test_blake2.py
@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 10 forks.