Пример #1
0
def test_blake2(input_hex, expected_result):
    input_bytes = to_bytes(hexstr=input_hex)

    if not isinstance(expected_result, str):
        with pytest.raises(expected_result):
            blake2b_params = extract_blake2b_parameters(input_bytes)
            blake2b_compress(*blake2b_params)
    else:
        blake2b_params = extract_blake2b_parameters(input_bytes)

        # a bit of parameter massaging for the pure python implementation
        rounds, h_state = blake2b_params[:2]
        message = input_bytes[
            68:196]  # python implementation uses bytes instead of decoded ints
        t_offset_counters, final_block_flag = blake2b_params[-2:]

        result_bytes = blake2b_compress(
            rounds,
            h_state,
            message,
            t_offset_counters,
            final_block_flag,
        )

        assert result_bytes.hex() == expected_result
Пример #2
0
def test_blake2(input_hex, expected_result):
    input_bytes = to_bytes(hexstr=input_hex)

    if not isinstance(expected_result, str):
        with pytest.raises(expected_result):
            blake2b_params = extract_blake2b_parameters(input_bytes)
            blake2b_compress(*blake2b_params)
    else:
        blake2b_params = extract_blake2b_parameters(input_bytes)
        result_bytes = blake2b_compress(*blake2b_params)

        assert result_bytes.hex() == expected_result
Пример #3
0
def blake2b_fcompress(computation: BaseComputation) -> BaseComputation:
    try:
        parameters = extract_blake2b_parameters(computation.msg.data_as_bytes)
    except ValidationError as exc:
        raise VMError(
            f"Blake2b input parameter validation failure: {exc}") from exc

    num_rounds = parameters[0]
    gas_cost = GAS_COST_PER_ROUND * num_rounds

    computation.consume_gas(
        gas_cost, reason=f"Blake2b Compress Precompile w/ {num_rounds} rounds")

    computation.output = _do_compression(*parameters)
    return computation