Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_proving_key.hpp
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
7#pragma once
8#include <utility>
9
12namespace bb {
13// TODO(https://github.com/AztecProtocol/barretenberg/issues/1317)
15 public:
18 using FF = typename Flavor::FF;
19 using BF = typename Flavor::BF;
24
26 // The actual circuit size is several times bigger than the trace in the circuit, because we use interleaving
27 // to bring the degree of relations down, while extending the length.
29
30 // Real mini and full circuit sizes i.e. the number of rows excluding those reserved for randomness (to achieve
31 // hiding of polynomial commitments and evaluation). Bound to change, but it has to be even as translator works two
32 // rows at a time
34 mini_circuit_dyadic_size - NUM_DISABLED_ROWS_IN_SUMCHECK;
35 static constexpr size_t dyadic_circuit_size_without_masking =
36 dyadic_circuit_size - NUM_DISABLED_ROWS_IN_SUMCHECK * Flavor::INTERLEAVING_GROUP_SIZE;
37
38 std::shared_ptr<ProvingKey> proving_key;
39
42
44
45 TranslatorProvingKey(const Circuit& circuit, const CommitmentKey& commitment_key = CommitmentKey())
48 {
49 PROFILE_THIS_NAME("TranslatorProvingKey(TranslatorCircuit&)");
50 // Check that the Translator Circuit does not exceed the fixed upper bound, the current value amounts to
51 // a number of EccOps sufficient for 10 rounds of folding (so 20 circuits)
52 if (circuit.num_gates > Flavor::MINI_CIRCUIT_SIZE - NUM_DISABLED_ROWS_IN_SUMCHECK) {
53 throw_or_abort("The Translator circuit size has exceeded the fixed upper bound");
54 }
55
57 auto wires = proving_key->polynomials.get_wires();
58 for (auto [wire_poly_, wire_] : zip_view(wires, circuit.wires)) {
59 auto& wire_poly = wire_poly_;
60 const auto& wire = wire_;
61 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1383)
62 parallel_for_range(circuit.num_gates, [&](size_t start, size_t end) {
63 for (size_t i = start; i < end; i++) {
64 if (i >= wire_poly.start_index() && i < wire_poly.end_index()) {
65 wire_poly.at(i) = circuit.get_variable(wire[i]);
66 } else {
67 BB_ASSERT_EQ(circuit.get_variable(wire[i]), 0);
68 }
69 }
70 });
71 }
72
73 // Iterate over all circuit wire polynomials, except the ones representing the op queue, and add random values
74 // at the end.
75 for (size_t idx = Flavor::NUM_OP_QUEUE_WIRES; idx < wires.size(); idx++) {
76 auto& wire = wires[idx];
77 for (size_t i = wire.end_index() - NUM_DISABLED_ROWS_IN_SUMCHECK; i < wire.end_index(); i++) {
78 wire.at(i) = FF::random_element();
79 }
80 }
81
82 // First and last lagrange polynomials (in the full circuit size)
83 // Construct polynomials with odd and even indices set to 1 up to the minicircuit margin + lagrange
84 // polynomials at second and second to last indices in the minicircuit
86
87 // Construct the extra range constraint numerator which contains all the additional values in the ordered range
88 // constraints not present in the interleaved polynomials
89 // NB this will always have a fixed size unless we change the allowed range
91
92 // Construct the polynomials resulted from interleaving the small polynomials in each group
94
95 // Construct the ordered polynomials, containing the values of the interleaved polynomials + enough values to
96 // bridge the range from 0 to 3 (3 is the maximum allowed range defined by the range constraint).
98 };
99
110 {
111 static const std::array<size_t, Flavor::SORTED_STEPS_COUNT> sorted_elements = [] {
113
114 // The value we have to end polynomials with, 2¹⁴ - 1
115 const size_t max_value = (1 << Flavor::MICRO_LIMB_BITS) - 1;
116
117 // min number of iterations for which we'll spin up a unique thread
118 const size_t min_iterations_per_thread = 1 << 6;
119 const size_t num_threads =
120 bb::calculate_num_threads_pow2(Flavor::SORTED_STEPS_COUNT, min_iterations_per_thread);
121 // actual iterations per thread
122 const size_t iterations_per_thread = Flavor::SORTED_STEPS_COUNT / num_threads;
123 const size_t leftovers = Flavor::SORTED_STEPS_COUNT % num_threads;
124
125 parallel_for(num_threads, [&](size_t thread_idx) {
126 const size_t start = thread_idx * iterations_per_thread;
127 const size_t end =
128 (thread_idx + 1) * iterations_per_thread + (thread_idx == num_threads - 1 ? leftovers : 0);
129 for (size_t idx = start; idx < end; ++idx) {
130 inner_array[idx] = max_value - Flavor::SORT_STEP * idx;
131 }
132 });
133
134 return inner_array;
135 }();
136
137 return sorted_elements;
138 }
139
140 void compute_lagrange_polynomials();
141
142 void compute_extra_range_constraint_numerator();
143
144 void compute_translator_range_constraint_ordered_polynomials();
145
146 void compute_interleaved_polynomials();
147
148 void split_interleaved_random_coefficients_to_ordered();
149};
150} // namespace bb
A container for the prover polynomials handles.
The proving key is responsible for storing the polynomials used by the prover.
static constexpr size_t MINI_CIRCUIT_SIZE
static constexpr size_t NUM_OP_QUEUE_WIRES
TranslatorCircuitBuilder CircuitBuilder
Curve::ScalarField FF
bb::CommitmentKey< Curve > CommitmentKey
bb::Polynomial< FF > Polynomial
static constexpr size_t INTERLEAVING_GROUP_SIZE
void compute_interleaved_polynomials()
Construct a set of polynomials that are the result of interleaving a group of polynomials into one....
typename Flavor::CommitmentKey CommitmentKey
static std::array< size_t, Flavor::SORTED_STEPS_COUNT > get_sorted_steps()
Create the array of steps inserted in each ordered range constraint to ensure they respect the approp...
static constexpr size_t mini_circuit_dyadic_size
void compute_extra_range_constraint_numerator()
Compute the extra numerator for the grand product polynomial.
static constexpr size_t dyadic_circuit_size_without_masking
TranslatorProvingKey(const Circuit &circuit, const CommitmentKey &commitment_key=CommitmentKey())
void compute_translator_range_constraint_ordered_polynomials()
Compute denominator polynomials for Translator's range constraint permutation.
static constexpr size_t dyadic_circuit_size
typename Flavor::ProverPolynomials ProverPolynomials
std::shared_ptr< ProvingKey > proving_key
static constexpr size_t dyadic_mini_circuit_size_without_masking
typename Flavor::ProvingKey ProvingKey
typename Flavor::Polynomial Polynomial
void compute_lagrange_polynomials()
Set all the precomputed lagrange polynomials used in Translator relations.
typename Flavor::CircuitBuilder Circuit
Entry point for Barretenberg command-line interface.
size_t calculate_num_threads_pow2(size_t num_iterations, size_t min_iterations_per_thread)
calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2
Definition thread.cpp:215
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:72
void parallel_for_range(size_t num_points, const std::function< void(size_t, size_t)> &func, size_t no_multhreading_if_less_or_equal)
Split a loop into several loops running in parallel.
Definition thread.cpp:102
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define PROFILE_THIS_NAME(name)
Definition op_count.hpp:16
static field random_element(numeric::RNG *engine=nullptr) noexcept
void throw_or_abort(std::string const &err)