Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
trace_to_polynomials.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
10
16namespace bb {
17
18template <class Flavor>
20{
21
22 BB_BENCH_NAME("trace populate");
23
24 auto copy_cycles = populate_wires_and_selectors_and_compute_copy_cycles(builder, polynomials);
25
26 if constexpr (IsMegaFlavor<Flavor>) {
27 BB_BENCH_NAME("add_ecc_op_wires_to_prover_instance");
28
29 add_ecc_op_wires_to_prover_instance(builder, polynomials);
30 }
31
32 // Compute the permutation argument polynomials (sigma/id) and add them to proving key
33 {
34 BB_BENCH_NAME("compute_permutation_argument_polynomials");
35
36 compute_permutation_argument_polynomials<Flavor>(builder, polynomials, copy_cycles);
37 }
38}
39
40template <class Flavor>
42 Builder& builder, ProverPolynomials& polynomials)
43{
44
45 BB_BENCH_NAME("construct_trace_data");
46
48 copy_cycles.resize(builder.get_num_variables()); // at most one copy cycle per variable
49
50 RefArray<Polynomial, NUM_WIRES> wires = polynomials.get_wires();
51 auto selectors = polynomials.get_selectors();
52
53 // For each block in the trace, populate wire polys, copy cycles and selector polys
54 for (auto& block : builder.blocks.get()) {
55 const uint32_t offset = block.trace_offset();
56 const uint32_t block_size = static_cast<uint32_t>(block.size());
57
58 // Update wire polynomials and copy cycles
59 // NB: The order of row/column loops is arbitrary but needs to be row/column to match old copy_cycle code
60 {
61 BB_BENCH_NAME("populating wires and copy_cycles");
62
63 for (uint32_t block_row_idx = 0; block_row_idx < block_size; ++block_row_idx) {
64 for (uint32_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
65 uint32_t var_idx = block.wires[wire_idx][block_row_idx]; // an index into the variables array
66 uint32_t real_var_idx = builder.real_variable_index[var_idx];
67 uint32_t trace_row_idx = block_row_idx + offset;
68 // Insert the real witness values from this block into the wire polys at the correct offset
69 wires[wire_idx].at(trace_row_idx) = builder.get_variable(var_idx);
70 // Add the address of the witness value to its corresponding copy cycle
71 // Note that the copy_cycles are indexed by real_variable_indices.
72 copy_cycles[real_var_idx].emplace_back(cycle_node{ wire_idx, trace_row_idx });
73 }
74 }
75 }
76
77 RefVector<Selector<FF>> block_selectors = block.get_selectors();
78 // Insert the selector values for this block into the selector polynomials at the correct offset
79 // TODO(https://github.com/AztecProtocol/barretenberg/issues/398): implicit arithmetization/flavor consistency
80 for (size_t selector_idx = 0; selector_idx < block_selectors.size(); selector_idx++) {
81 auto& selector = block_selectors[selector_idx];
82 for (size_t row_idx = 0; row_idx < block_size; ++row_idx) {
83 size_t trace_row_idx = row_idx + offset;
84 selectors[selector_idx].set_if_valid_index(trace_row_idx, selector[row_idx]);
85 }
86 }
87 }
88
89 return copy_cycles;
90}
91
92template <class Flavor>
95{
96 auto& ecc_op_selector = polynomials.lagrange_ecc_op;
97 const size_t wire_idx_offset = Flavor::has_zero_row ? 1 : 0;
98
99 // Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates. The data is
100 // stored in the ecc op wires starting from index 0, whereas the wires contain the data offset by a zero row.
101 const size_t num_ecc_ops = builder.blocks.ecc_op.size();
102 for (auto [ecc_op_wire, wire] : zip_view(polynomials.get_ecc_op_wires(), polynomials.get_wires())) {
103 for (size_t i = 0; i < num_ecc_ops; ++i) {
104 ecc_op_wire.at(i) = wire[i + wire_idx_offset];
105 ecc_op_selector.at(i) = 1; // construct selector as the indicator on the ecc op block
106 }
107 }
108}
109
113#ifdef STARKNET_GARAGA_FLAVORS
116#endif
119template class TraceToPolynomials<MegaFlavor>;
121
122} // namespace bb
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:219
A container for the prover polynomials.
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
std::size_t size() const
typename Flavor::CircuitBuilder Builder
static std::vector< CyclicPermutation > populate_wires_and_selectors_and_compute_copy_cycles(Builder &builder, ProverPolynomials &)
Populate wire polynomials, selector polynomials and copy cycles from raw circuit data.
static void add_ecc_op_wires_to_prover_instance(Builder &builder, ProverPolynomials &)
Construct and add the goblin ecc op wires to the proving key.
static void populate(Builder &builder, ProverPolynomials &)
Given a circuit, populate a proving key with wire polys, selector polys, and sigma/id polys.
typename Flavor::ProverPolynomials ProverPolynomials
AluTraceBuilder builder
Definition alu.test.cpp:124
ssize_t offset
Definition engine.cpp:36
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
cycle_node represents the idx of a value of the circuit. It will belong to a CyclicPermutation,...