Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
acir_to_constraint_buf.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Federico], commit: 2094fd1467dd9a94803b2c5007cf60ac357aa7d2 }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8#include "acir_format.hpp"
9#include "serde/index.hpp"
10
11namespace acir_format {
12
14
17
24bb::fr from_buffer_with_bound_checks(const std::vector<uint8_t>& buffer);
25
29WitnessOrConstant<bb::fr> parse_input(const Acir::FunctionInput& input);
30
37
46void update_max_witness_index(const uint32_t witness_idx, AcirFormat& af);
47
55void update_max_witness_index_from_expression(Acir::Expression const& expr, AcirFormat& af);
56
63void update_max_witness_index_from_opcode(Acir::Opcode const& opcode, AcirFormat& af);
64
66
83
90template <typename T>
91T deserialize_msgpack_compact(std::vector<uint8_t>&& buf, std::function<T(msgpack::object const&)> decode_msgpack);
92
100AcirFormat circuit_serde_to_acir_format(Acir::Circuit const& circuit, bool is_mega);
101
109
116AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t>&& buf, bool is_mega);
117
122AcirFormat circuit_buf_to_mega_acir_format(std::vector<uint8_t>&& buf);
123
127WitnessVector witness_buf_to_witness_vector(std::vector<uint8_t>&& buf);
128
130
132
139
149
158 const std::map<uint32_t, bb::fr>& linear_terms,
159 bool is_mega);
160
169bool resolve_shared_wire_products(Acir::Expression const& arg, uint32_t& w_l, uint32_t& w_r, uint32_t& w_o);
170
181bool is_bilinear(Acir::Expression const& arg, const std::map<uint32_t, bb::fr>& linear_terms);
182
189bool is_batched_eq(Acir::Expression const& arg, const std::map<uint32_t, bb::fr>& linear_terms);
190
197bool is_single_arithmetic_gate(Acir::Expression const& arg, const std::map<uint32_t, bb::fr>& linear_terms);
198
202BilinearConstraint build_bilinear_constraint(Acir::Expression const& arg,
203 const std::map<uint32_t, bb::fr>& linear_terms);
204
205// clang-format off
249// clang-format on
251 std::map<uint32_t, bb::fr>& linear_terms);
252
257 uint32_t w1;
258 uint32_t w2;
263};
264
269 const std::map<uint32_t, bb::fr>& linear_terms,
270 size_t opcode_index);
271
279 const std::optional<BatchedEqEntry>& entry2);
280
298 AcirFormat& af,
299 size_t opcode_index,
300 std::vector<BatchedEqEntry>& batched_eq_assert_zeros,
301 bool is_mega);
302
310
312
319
325
327
346 AcirFormat& af,
347 size_t opcode_index);
348
349} // namespace acir_format
std::unique_ptr< uint8_t[]> buffer
Definition engine.cpp:60
void add_memory_op_to_block_constraint(Acir::Opcode::MemoryOp const &mem_op, BlockConstraint &block)
Process memory operation, either read or write, and update the BlockConstraint type accordingly.
AcirFormat circuit_serde_to_acir_format(Acir::Circuit const &circuit, bool is_mega)
Convert an Acir::Circuit into an AcirFormat by processing all the opcodes.
bool resolve_shared_wire_products(Acir::Expression const &arg, uint32_t &w_l, uint32_t &w_r, uint32_t &w_o)
Given an Arithmetic expression with two multiplication terms, determine whether they share a witness ...
WitnessOrConstant< bb::fr > parse_input(const Acir::FunctionInput &input)
Parse an Acir::FunctionInput (which can either be a witness or a constant) into a WitnessOrConstant.
void update_max_witness_index_from_opcode(Acir::Opcode const &opcode, AcirFormat &af)
Update the max witness index by processing all the witness indices contained in the Acir::Opcode.
bool is_batched_eq(Acir::Expression const &arg, const std::map< uint32_t, bb::fr > &linear_terms)
Whether an AssertZero is "batched-eq" — a pure linear constraint with 1 or 2 witnesses.
uint32_t get_witness_from_function_input(const Acir::FunctionInput &input)
Extract the witness index from an Acir::FunctionInput representing a witness.
void update_max_witness_index_from_expression(Acir::Expression const &expr, AcirFormat &af)
Update max_witness_index by processing all witnesses in an Acir::Expression.
WitnessVector witness_buf_to_witness_vector(std::vector< uint8_t > &&buf)
Convert a buffer representing a witness vector into Barretenberg's internal WitnessVector format.
std::vector< mul_quad_< fr > > split_into_mul_quad_gates(Acir::Expression const &arg, std::map< uint32_t, bb::fr > &linear_terms)
========= ACIR OPCODE HANDLERS ========= ///
void update_max_witness_index(const uint32_t witness_idx, AcirFormat &af)
Update the max_witness_index.
WitnessVector witness_map_to_witness_vector(Witnesses::WitnessMap const &witness_map)
Convert from the ACIR-native WitnessMap format to Barretenberg's internal WitnessVector format.
T deserialize_msgpack_compact(std::vector< uint8_t > &&buf, std::function< T(msgpack::object const &)> decode_msgpack)
========= BYTES TO BARRETENBERG'S REPRESENTATION ========= ///
AssertZeroGate classify_assert_zero(Acir::Expression const &arg, const std::map< uint32_t, bb::fr > &linear_terms, bool is_mega)
Classify an Acir::Expression with its processed linear terms into the gate it lowers to.
AcirFormat circuit_buf_to_acir_format(std::vector< uint8_t > &&buf, bool is_mega)
Convert a buffer representing a circuit into Barretenberg's internal AcirFormat representation.
BatchedEqCheckConstraint build_batched_eq_check_constraint(const BatchedEqEntry &entry1, const std::optional< BatchedEqEntry > &entry2)
Build a BATCHED_EQ row from batched-eq halves.
AcirFormat circuit_buf_to_mega_acir_format(std::vector< uint8_t > &&buf)
Specialization for Mega constructor.
std::vector< bb::fr > WitnessVector
void batched_eq_assert_zeros_into_constraints(AcirFormat &af, std::vector< BatchedEqEntry > &pending)
Pair buffered batched-eq AssertZeros into BATCHED_EQ rows (and emit any leftover as a single-half row...
bool is_single_arithmetic_gate(Acir::Expression const &arg, const std::map< uint32_t, bb::fr > &linear_terms)
Given an Acir::Expression and its processed linear terms, determine whether it can be represented by ...
void assert_zero_to_constraints(Acir::Opcode::AssertZero const &arg, AcirFormat &af, size_t opcode_index, std::vector< BatchedEqEntry > &batched_eq_assert_zeros, bool is_mega)
Single entrypoint for processing arithmetic (AssertZero) opcodes.
AssertZeroGate
How an AssertZero opcode is lowered to gates.
BilinearConstraint build_bilinear_constraint(Acir::Expression const &arg, const std::map< uint32_t, bb::fr > &linear_terms)
Build the bilinear-gate constraint for an AssertZero already classified as Bilinear.
BlockConstraint memory_init_to_block_constraint(Acir::Opcode::MemoryInit const &mem_init)
========= MEMORY OPERATIONS ========== ///
bb::fr from_buffer_with_bound_checks(const std::vector< uint8_t > &buffer)
========= HELPERS ========= ///
BatchedEqEntry build_batched_eq_entry(Acir::Expression const &arg, const std::map< uint32_t, bb::fr > &linear_terms, size_t opcode_index)
Build the batched-eq entry for an AssertZero already classified as BatchedEq.
void add_blackbox_func_call_to_acir_format(Acir::Opcode::BlackBoxFuncCall const &arg, AcirFormat &af, size_t opcode_index)
bool is_bilinear(Acir::Expression const &arg, const std::map< uint32_t, bb::fr > &linear_terms)
Whether an AssertZero fits a single bilinear-gate row.
std::map< uint32_t, bb::fr > process_linear_terms(Acir::Expression const &expr)
========= ACIR OPCODE HANDLERS ========= ///
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Barretenberg's representation of ACIR constraints.
BatchedEq constraint — BATCHED_EQ mode of the bilinear_batched_eq gate (see bilinear_or_batched_eq_ch...
Linear AssertZero (≤2 witnesses + constant)
size_t opcode_index
bb::fr c2
uint32_t w2
bb::fr q_c
uint32_t w1
bb::fr c1
Struct holding the data required to add memory constraints to a circuit.