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
35 static constexpr size_t dyadic_circuit_size_without_masking =
37
38 std::shared_ptr<ProvingKey> proving_key;
39
42
44
45 TranslatorProvingKey(const Circuit& circuit, const CommitmentKey& commitment_key = CommitmentKey())
48 {
49 BB_BENCH_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) {
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
83
84 // Construct the extra range constraint numerator which contains all the additional values in ordered range
85 // constraints not present in the interleaved polynomials
86 // NB this will always have a fixed size unless we change the allowed range
88
89 // Construct the polynomials resulted from interleaving the small range constraints polynomials in each group
90 // to be interleaved
92
93 // Construct the ordered polynomials, containing the values of the interleaved polynomials + enough values to
94 // bridge the range from 0 to 3 (3 is the maximum difference between two consecutive values in the ordered range
95 // constraint).
97 };
98
109 {
110 static const std::array<size_t, Flavor::SORTED_STEPS_COUNT> sorted_elements = [] {
112
113 // The value we have to end polynomials with, 2¹⁴ - 1
114 const size_t max_value = (1 << Flavor::MICRO_LIMB_BITS) - 1;
115
116 // min number of iterations for which we'll spin up a unique thread
117 const size_t min_iterations_per_thread = 1 << 6;
118 const size_t num_threads =
119 bb::calculate_num_threads_pow2(Flavor::SORTED_STEPS_COUNT, min_iterations_per_thread);
120 // actual iterations per thread
121 const size_t iterations_per_thread = Flavor::SORTED_STEPS_COUNT / num_threads;
122 const size_t leftovers = Flavor::SORTED_STEPS_COUNT % num_threads;
123
124 parallel_for(num_threads, [&](size_t thread_idx) {
125 const size_t start = thread_idx * iterations_per_thread;
126 const size_t end =
127 (thread_idx + 1) * iterations_per_thread + (thread_idx == num_threads - 1 ? leftovers : 0);
128 for (size_t idx = start; idx < end; ++idx) {
129 inner_array[idx] = max_value - Flavor::SORT_STEP * idx;
130 }
131 });
132
133 return inner_array;
134 }();
135
136 return sorted_elements;
137 }
138
139 void compute_lagrange_polynomials();
140
141 void compute_extra_range_constraint_numerator();
142
143 void compute_translator_range_constraint_ordered_polynomials();
144
145 void compute_interleaved_polynomials();
146
147 void split_interleaved_random_coefficients_to_ordered();
148};
149} // namespace bb
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:218
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
static constexpr size_t NUM_MASKED_ROWS_END
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()
Construct 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:254
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
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:141
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept
void throw_or_abort(std::string const &err)