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
11
namespace
acir_format
{
12
14
17
24
bb::fr
from_buffer_with_bound_checks
(
const
std::vector<uint8_t>&
buffer
);
25
29
WitnessOrConstant<bb::fr>
parse_input
(
const
Acir::FunctionInput
& input);
30
36
uint32_t
get_witness_from_function_input
(
const
Acir::FunctionInput
& input);
37
46
void
update_max_witness_index
(
const
uint32_t witness_idx, AcirFormat& af);
47
55
void
update_max_witness_index_from_expression
(
Acir::Expression
const
& expr, AcirFormat& af);
56
63
void
update_max_witness_index_from_opcode
(
Acir::Opcode
const
& opcode, AcirFormat& af);
64
66
83
90
template
<
typename
T>
91
T
deserialize_msgpack_compact
(std::vector<uint8_t>&& buf, std::function<T(msgpack::object
const
&)> decode_msgpack);
92
100
AcirFormat
circuit_serde_to_acir_format
(
Acir::Circuit
const
& circuit,
bool
is_mega);
101
108
WitnessVector
witness_map_to_witness_vector
(
Witnesses::WitnessMap
const
& witness_map);
109
116
AcirFormat
circuit_buf_to_acir_format
(std::vector<uint8_t>&& buf,
bool
is_mega);
117
122
AcirFormat
circuit_buf_to_mega_acir_format
(std::vector<uint8_t>&& buf);
123
127
WitnessVector
witness_buf_to_witness_vector
(std::vector<uint8_t>&& buf);
128
130
132
138
std::map<uint32_t, bb::fr>
process_linear_terms
(
Acir::Expression
const
& expr);
139
148
enum class
AssertZeroGate
: uint8_t {
Bilinear
,
BatchedEq
,
SingleArithmetic
,
MultiArithmetic
};
149
157
AssertZeroGate
classify_assert_zero
(
Acir::Expression
const
& arg,
158
const
std::map<uint32_t, bb::fr>
& linear_terms,
159
bool
is_mega);
160
169
bool
resolve_shared_wire_products
(
Acir::Expression
const
& arg, uint32_t& w_l, uint32_t& w_r, uint32_t& w_o);
170
181
bool
is_bilinear
(
Acir::Expression
const
& arg,
const
std::map<uint32_t, bb::fr>
& linear_terms);
182
189
bool
is_batched_eq
(
Acir::Expression
const
& arg,
const
std::map<uint32_t, bb::fr>
& linear_terms);
190
197
bool
is_single_arithmetic_gate
(
Acir::Expression
const
& arg,
const
std::map<uint32_t, bb::fr>
& linear_terms);
198
202
BilinearConstraint
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
250
std::vector<mul_quad_<fr>
>
split_into_mul_quad_gates
(
Acir::Expression
const
& arg,
251
std::map<uint32_t, bb::fr>
& linear_terms);
252
256
struct
BatchedEqEntry
{
257
uint32_t
w1
;
258
uint32_t
w2
;
259
bb::fr
c1
;
260
bb::fr
c2
;
261
bb::fr
q_c
;
262
size_t
opcode_index
;
263
};
264
268
BatchedEqEntry
build_batched_eq_entry
(
Acir::Expression
const
& arg,
269
const
std::map<uint32_t, bb::fr>
& linear_terms,
270
size_t
opcode_index);
271
278
BatchedEqCheckConstraint
build_batched_eq_check_constraint
(
const
BatchedEqEntry
& entry1,
279
const
std::optional<BatchedEqEntry>
& entry2);
280
297
void
assert_zero_to_constraints
(
Acir::Opcode::AssertZero
const
& arg,
298
AcirFormat
& af,
299
size_t
opcode_index,
300
std::vector<BatchedEqEntry>
& batched_eq_assert_zeros,
301
bool
is_mega);
302
309
void
batched_eq_assert_zeros_into_constraints
(
AcirFormat
& af,
std::vector<BatchedEqEntry>
& pending);
310
312
318
BlockConstraint
memory_init_to_block_constraint
(
Acir::Opcode::MemoryInit
const
& mem_init);
319
324
void
add_memory_op_to_block_constraint
(
Acir::Opcode::MemoryOp
const
& mem_op,
BlockConstraint
& block);
325
327
345
void
add_blackbox_func_call_to_acir_format
(
Acir::Opcode::BlackBoxFuncCall
const
& arg,
346
AcirFormat
& af,
347
size_t
opcode_index);
348
349
}
// namespace acir_format
acir_format.hpp
buffer
std::unique_ptr< uint8_t[]> buffer
Definition
engine.cpp:60
index.hpp
acir_format
Definition
acir_format.cpp:30
acir_format::add_memory_op_to_block_constraint
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.
Definition
acir_to_constraint_buf.cpp:1045
acir_format::circuit_serde_to_acir_format
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.
Definition
acir_to_constraint_buf.cpp:330
acir_format::resolve_shared_wire_products
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 ...
Definition
acir_to_constraint_buf.cpp:588
acir_format::parse_input
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.
Definition
acir_to_constraint_buf.cpp:43
acir_format::update_max_witness_index_from_opcode
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.
Definition
acir_to_constraint_buf.cpp:93
acir_format::is_batched_eq
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.
Definition
acir_to_constraint_buf.cpp:654
acir_format::get_witness_from_function_input
uint32_t get_witness_from_function_input(const Acir::FunctionInput &input)
Extract the witness index from an Acir::FunctionInput representing a witness.
Definition
acir_to_constraint_buf.cpp:63
acir_format::update_max_witness_index_from_expression
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.
Definition
acir_to_constraint_buf.cpp:79
acir_format::witness_buf_to_witness_vector
WitnessVector witness_buf_to_witness_vector(std::vector< uint8_t > &&buf)
Convert a buffer representing a witness vector into Barretenberg's internal WitnessVector format.
Definition
acir_to_constraint_buf.cpp:432
acir_format::split_into_mul_quad_gates
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 ========= ///
Definition
acir_to_constraint_buf.cpp:478
acir_format::update_max_witness_index
void update_max_witness_index(const uint32_t witness_idx, AcirFormat &af)
Update the max_witness_index.
Definition
acir_to_constraint_buf.cpp:72
acir_format::witness_map_to_witness_vector
WitnessVector witness_map_to_witness_vector(Witnesses::WitnessMap const &witness_map)
Convert from the ACIR-native WitnessMap format to Barretenberg's internal WitnessVector format.
Definition
acir_to_constraint_buf.cpp:453
acir_format::deserialize_msgpack_compact
T deserialize_msgpack_compact(std::vector< uint8_t > &&buf, std::function< T(msgpack::object const &)> decode_msgpack)
========= BYTES TO BARRETENBERG'S REPRESENTATION ========= ///
Definition
acir_to_constraint_buf.cpp:301
acir_format::classify_assert_zero
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.
Definition
acir_to_constraint_buf.cpp:1111
acir_format::circuit_buf_to_acir_format
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.
Definition
acir_to_constraint_buf.cpp:405
acir_format::build_batched_eq_check_constraint
BatchedEqCheckConstraint build_batched_eq_check_constraint(const BatchedEqEntry &entry1, const std::optional< BatchedEqEntry > &entry2)
Build a BATCHED_EQ row from batched-eq halves.
Definition
acir_to_constraint_buf.cpp:731
acir_format::circuit_buf_to_mega_acir_format
AcirFormat circuit_buf_to_mega_acir_format(std::vector< uint8_t > &&buf)
Specialization for Mega constructor.
Definition
acir_to_constraint_buf.cpp:427
acir_format::WitnessVector
std::vector< bb::fr > WitnessVector
Definition
acir_format.hpp:36
acir_format::batched_eq_assert_zeros_into_constraints
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...
Definition
acir_to_constraint_buf.cpp:749
acir_format::is_single_arithmetic_gate
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 ...
Definition
acir_to_constraint_buf.cpp:1064
acir_format::assert_zero_to_constraints
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.
Definition
acir_to_constraint_buf.cpp:763
acir_format::AssertZeroGate
AssertZeroGate
How an AssertZero opcode is lowered to gates.
Definition
acir_to_constraint_buf.hpp:148
acir_format::AssertZeroGate::MultiArithmetic
@ MultiArithmetic
acir_format::AssertZeroGate::SingleArithmetic
@ SingleArithmetic
acir_format::AssertZeroGate::Bilinear
@ Bilinear
acir_format::AssertZeroGate::BatchedEq
@ BatchedEq
acir_format::build_bilinear_constraint
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.
Definition
acir_to_constraint_buf.cpp:659
acir_format::memory_init_to_block_constraint
BlockConstraint memory_init_to_block_constraint(Acir::Opcode::MemoryInit const &mem_init)
========= MEMORY OPERATIONS ========== ///
Definition
acir_to_constraint_buf.cpp:1013
acir_format::from_buffer_with_bound_checks
bb::fr from_buffer_with_bound_checks(const std::vector< uint8_t > &buffer)
========= HELPERS ========= ///
Definition
acir_to_constraint_buf.cpp:37
acir_format::build_batched_eq_entry
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.
Definition
acir_to_constraint_buf.cpp:708
acir_format::add_blackbox_func_call_to_acir_format
void add_blackbox_func_call_to_acir_format(Acir::Opcode::BlackBoxFuncCall const &arg, AcirFormat &af, size_t opcode_index)
Definition
acir_to_constraint_buf.cpp:840
acir_format::is_bilinear
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.
Definition
acir_to_constraint_buf.cpp:628
acir_format::process_linear_terms
std::map< uint32_t, bb::fr > process_linear_terms(Acir::Expression const &expr)
========= ACIR OPCODE HANDLERS ========= ///
Definition
acir_to_constraint_buf.cpp:1129
std::get
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition
tuple.hpp:13
Acir::Circuit
Definition
acir.hpp:7230
Acir::Expression
Definition
acir.hpp:5854
Acir::FunctionInput
Definition
acir.hpp:4250
Acir::Opcode::AssertZero
Definition
acir.hpp:6329
Acir::Opcode::BlackBoxFuncCall
Definition
acir.hpp:6347
Acir::Opcode::MemoryInit
Definition
acir.hpp:6413
Acir::Opcode::MemoryOp
Definition
acir.hpp:6365
Acir::Opcode
Definition
acir.hpp:6327
Witnesses::WitnessMap
Definition
witness_stack.hpp:172
acir_format::AcirFormat
Barretenberg's representation of ACIR constraints.
Definition
acir_format.hpp:85
acir_format::BatchedEqCheckConstraint
BatchedEq constraint — BATCHED_EQ mode of the bilinear_batched_eq gate (see bilinear_or_batched_eq_ch...
Definition
arithmetic_constraints.hpp:59
acir_format::BatchedEqEntry
Linear AssertZero (≤2 witnesses + constant)
Definition
acir_to_constraint_buf.hpp:256
acir_format::BatchedEqEntry::opcode_index
size_t opcode_index
Definition
acir_to_constraint_buf.hpp:262
acir_format::BatchedEqEntry::c2
bb::fr c2
Definition
acir_to_constraint_buf.hpp:260
acir_format::BatchedEqEntry::w2
uint32_t w2
Definition
acir_to_constraint_buf.hpp:258
acir_format::BatchedEqEntry::q_c
bb::fr q_c
Definition
acir_to_constraint_buf.hpp:261
acir_format::BatchedEqEntry::w1
uint32_t w1
Definition
acir_to_constraint_buf.hpp:257
acir_format::BatchedEqEntry::c1
bb::fr c1
Definition
acir_to_constraint_buf.hpp:259
acir_format::BlockConstraint
Struct holding the data required to add memory constraints to a circuit.
Definition
block_constraint.hpp:54
bb::field< Bn254FrParams >
src
barretenberg
dsl
acir_format
acir_to_constraint_buf.hpp
Generated by
1.9.8