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
10
11namespace bb::avm2::constraining {
12
14{
16
17 // Polynomials that will be shifted need special care.
18 AVM_TRACK_TIME("proving/init_polys_to_be_shifted", ({
19 auto to_be_shifted = polys.get_to_be_shifted();
20 assert(to_be_shifted.size() == TO_BE_SHIFTED_COLUMNS_ARRAY.size());
21
22 // NOTE: we can't parallelize because Polynomial construction uses parallelism.
23 for (size_t i = 0; i < to_be_shifted.size(); i++) {
24 auto& poly = to_be_shifted[i];
25 // WARNING! Column-Polynomials order matters!
26 Column col = static_cast<Column>(TO_BE_SHIFTED_COLUMNS_ARRAY.at(i));
27 uint32_t num_rows = trace.get_column_rows(col);
28 // Since we are shifting, we need to allocate one less row.
29 // The first row is always zero.
30 uint32_t allocated_size = num_rows > 0 ? num_rows - 1 : 0;
31
33 /*memory size*/ allocated_size,
34 /*largest possible index*/ MAX_AVM_TRACE_SIZE, // TODO(#16660): use real size?
35 /*make shiftable with offset*/ 1);
36 }
37 }));
38
39 // Catch-all with fully formed polynomials
40 // Note: derived polynomials (i.e., inverses) are not in the trace at this point, because they can only
41 // be computed after committing to the other witnesses. Therefore, they will be initialized as empty
42 // and they will be not set below. The derived polynomials will be reinitialized and set in the prover
43 // itself mid-proving.
44 AVM_TRACK_TIME("proving/init_polys_unshifted", ({
45 auto unshifted = polys.get_unshifted();
46 bb::parallel_for(unshifted.size(), [&](size_t i) {
47 auto& poly = unshifted[i];
48 // Some of the polynomials have been initialized above. Skip those.
49 if (poly.virtual_size() > 0) {
50 // Already initialized above.
51 return;
52 }
53
54 // WARNING! Column-Polynomials order matters!
55 Column col = static_cast<Column>(i);
56 const auto num_rows = trace.get_column_rows(col);
58 });
59 }));
60
61 AVM_TRACK_TIME("proving/set_polys_unshifted", ({
62 auto unshifted = polys.get_unshifted();
63 bb::parallel_for(unshifted.size(), [&](size_t i) {
64 // WARNING! Column-Polynomials order matters!
65 auto& poly = unshifted[i];
66 Column col = static_cast<Column>(i);
67
68 trace.visit_column(col, [&](size_t row, const AvmProver::FF& value) {
69 // We use `at` because we are sure the row exists and the value is non-zero.
70 poly.at(row) = value;
71 });
72 // We free columns as we go.
74 });
75 }));
76
77 AVM_TRACK_TIME("proving/set_polys_shifted", ({
78 for (auto [shifted, to_be_shifted] : zip_view(polys.get_shifted(), polys.get_to_be_shifted())) {
79 shifted = to_be_shifted.shifted();
80 }
81 }));
82
83 return polys;
84}
85
87 Column inverses_col,
88 Column src_selector_col,
89 Column dst_selector_col)
90{
91 auto& inverse_polynomial = prover_polynomials.get(static_cast<ColumnAndShifts>(inverses_col));
92 const auto& src_selector = prover_polynomials.get(static_cast<ColumnAndShifts>(src_selector_col));
93 const auto& dst_selector = prover_polynomials.get(static_cast<ColumnAndShifts>(dst_selector_col));
94
95 if (!inverse_polynomial.is_empty()) {
96 throw std::runtime_error("Inverse polynomial is expected to be empty at this point.");
97 }
98
99 const size_t num_rows = std::max<size_t>(src_selector.end_index(), dst_selector.end_index());
100 inverse_polynomial = AvmProver::Polynomial::create_non_parallel_zero_init(num_rows, MAX_AVM_TRACE_SIZE);
101 assert(prover_polynomials.get(static_cast<ColumnAndShifts>(inverses_col)).size() == num_rows);
102}
103
104} // 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....
DataType & get(ColumnAndShifts c)
Definition flavor.hpp:150
A container for the prover polynomials handles.
Definition flavor.hpp:281
Flavor::Polynomial Polynomial
Definition prover.hpp:20
uint32_t get_column_rows(Column col) const
TestTraceContainer trace
void resize_inverses(AvmFlavor::ProverPolynomials &prover_polynomials, Column inverses_col, Column src_selector_col, Column dst_selector_col)
AvmProver::ProverPolynomials compute_polynomials(tracegen::TraceContainer &trace)
constexpr std::size_t MAX_AVM_TRACE_SIZE
Definition constants.hpp:11
constexpr auto TO_BE_SHIFTED_COLUMNS_ARRAY
Definition columns.hpp:77
ColumnAndShifts
Definition columns.hpp:34
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:16