Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
blake3_constraint.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
11#include "round.hpp"
12
13namespace acir_format {
14
15template <typename Builder> void create_blake3_constraints(Builder& builder, const Blake3Constraint& constraint)
16{
19
20 // Create byte array struct
22
23 // Get the witness assignment for each witness index
24 // Write the witness assignment to the byte_array
25 for (const auto& witness_index_num_bits : constraint.inputs) {
26 auto witness_index = witness_index_num_bits.blackbox_input;
27 auto num_bits = witness_index_num_bits.num_bits;
28
29 // XXX: The implementation requires us to truncate the element to the nearest byte and not bit
30 auto num_bytes = round_to_nearest_byte(num_bits);
31 BB_ASSERT_LTE(num_bytes, 1024U, "barretenberg does not support blake3 inputs with more than 1024 bytes");
32 field_ct element = to_field_ct(witness_index, builder);
33 byte_array_ct element_bytes(element, num_bytes);
34
35 arr.write(element_bytes);
36 }
37
39
40 // Convert byte array to vector of field_t
41 auto bytes = output_bytes.bytes();
42
43 for (size_t i = 0; i < bytes.size(); ++i) {
44 builder.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]);
45 }
46}
47
49 const Blake3Constraint& constraint);
51 const Blake3Constraint& constraint);
52
53} // namespace acir_format
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:129
static byte_array_ct hash(const byte_array_ct &input)
Definition blake3s.cpp:183
Represents a dynamic array of bytes in-circuit.
byte_array & write(byte_array const &other)
Appends the contents of another byte_array (other) to the end of this one.
bytes_t const & bytes() const
AluTraceBuilder builder
Definition alu.test.cpp:123
template void create_blake3_constraints< bb::UltraCircuitBuilder >(bb::UltraCircuitBuilder &builder, const Blake3Constraint &constraint)
void create_blake3_constraints(Builder &builder, const Blake3Constraint &constraint)
uint32_t round_to_nearest_byte(uint32_t num_bits)
Definition round.cpp:23
bb::stdlib::field_t< Builder > to_field_ct(const WitnessOrConstant< FF > &input, Builder &builder)
template void create_blake3_constraints< bb::MegaCircuitBuilder >(bb::MegaCircuitBuilder &builder, const Blake3Constraint &constraint)
std::conditional_t< IsGoblinBigGroup< C, Fq, Fr, G >, element_goblin::goblin_element< C, goblin_field< C >, Fr, G >, element_default::element< C, Fq, Fr, G > > element
element wraps either element_default::element or element_goblin::goblin_element depending on parametr...
std::array< uint32_t, 32 > result
std::vector< Blake3Input > inputs