Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
polynomials.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4
9
10namespace bb::avm2::constraining {
11
13{
15
16 // Polynomials that will be shifted need special care.
17 AVM_TRACK_TIME("proving/init_polys_to_be_shifted", ({
18 auto to_be_shifted = polys.get_to_be_shifted();
19
20 // NOTE: we can't parallelize because Polynomial construction uses parallelism.
21 for (size_t i = 0; i < to_be_shifted.size(); i++) {
22 auto& poly = to_be_shifted[i];
23 // WARNING! Column-Polynomials order matters!
24 Column col = static_cast<Column>(TO_BE_SHIFTED_COLUMNS_ARRAY.at(i));
25 uint32_t num_rows = trace.get_column_rows(col);
26 // Since we are shifting, we need to allocate one less row.
27 // The first row is always zero.
28 uint32_t allocated_size = num_rows > 0 ? num_rows - 1 : 0;
29
31 /*memory size*/ allocated_size,
32 /*largest possible index*/ MAX_AVM_TRACE_SIZE, // TODO(#16660): use real size?
33 /*make shiftable with offset*/ 1);
34 }
35 }));
36
37 // Catch-all with fully formed polynomials
38 // Note: derived polynomials (i.e., inverses) are not in the trace at this point, because they can only
39 // be computed after committing to the other witnesses. Therefore, they will be initialized as empty
40 // and they will be not set below. The derived polynomials will be reinitialized and set in the prover
41 // itself mid-proving. (TO BE DONE!).
42 //
43 // NOTE FOR SELF: however, the counts will be known here and the inv have the same size?
44 // think about it and check the formula.
45 AVM_TRACK_TIME("proving/init_polys_unshifted", ({
46 auto unshifted = polys.get_unshifted();
47 bb::parallel_for(unshifted.size(), [&](size_t i) {
48 auto& poly = unshifted[i];
49 // Some of the polynomials have been initialized above. Skip those.
50 if (poly.virtual_size() > 0) {
51 // Already initialized above.
52 return;
53 }
54
55 // WARNING! Column-Polynomials order matters!
56 Column col = static_cast<Column>(i);
57 const auto num_rows = trace.get_column_rows(col);
59 });
60 }));
61
62 AVM_TRACK_TIME("proving/set_polys_unshifted", ({
63 auto unshifted = polys.get_unshifted();
64 // TODO: We are now visiting per-column. Profile if per-row is better.
65 // This would need changes to the trace container.
66 bb::parallel_for(unshifted.size(), [&](size_t i) {
67 // WARNING! Column-Polynomials order matters!
68 auto& poly = unshifted[i];
69 Column col = static_cast<Column>(i);
70
71 trace.visit_column(col, [&](size_t row, const AvmProver::FF& value) {
72 // We use `at` because we are sure the row exists and the value is non-zero.
73 poly.at(row) = value;
74 });
75 // We free columns as we go.
76 // TODO: If we merge the init with the setting, this would be even more memory efficient.
78 });
79 }));
80
81 AVM_TRACK_TIME("proving/set_polys_shifted", ({
82 for (auto [shifted, to_be_shifted] : zip_view(polys.get_shifted(), polys.get_to_be_shifted())) {
83 shifted = to_be_shifted.shifted();
84 }
85 }));
86
87 return polys;
88}
89
90} // namespace bb::avm2::constraining
static Polynomial create_non_parallel_zero_init(size_t size, size_t virtual_size)
A factory to construct a polynomial where parallel initialization is not possible (e....
A container for the prover polynomials handles.
Definition flavor.hpp:296
Flavor::Polynomial Polynomial
Definition prover.hpp:20
uint32_t get_column_rows(Column col) const
TestTraceContainer trace
AvmProver::ProverPolynomials compute_polynomials(tracegen::TraceContainer &trace)
constexpr size_t MAX_AVM_TRACE_SIZE
Definition constants.hpp:10
constexpr auto TO_BE_SHIFTED_COLUMNS_ARRAY
Definition columns.hpp:42
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:72
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:17