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: Planned, auditors: [], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8#include <utility>
9
12namespace bb {
13// Bound to the short-monomial flavor to match TranslatorProver. The proving key uses no relations (only flavor
14// entity/constant definitions, which the short-monomial flavor inherits unchanged from TranslatorFlavor), so the
15// choice is functionally immaterial -- it just keeps the prover and proving key on a single flavor.
17 public:
20 using FF = typename Flavor::FF;
21 using BF = typename Flavor::BF;
26 // The actual circuit size is several times bigger than the trace in the circuit, because we use concatenation
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
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 28 app circuits
52 vinfo("Translator circuit size: ", circuit.num_gates());
53 BB_ASSERT_LTE(circuit.num_gates(),
55 "The Translator circuit size has exceeded the fixed upper bound");
56
58 auto wires = proving_key->polynomials.get_wires();
59 // Distribute wires across threads (one task per wire) rather than multithreading within each wire.
60 parallel_for(wires.size(), [&](size_t wire_idx) {
61 auto& wire_poly = wires[wire_idx];
62 const auto& wire = circuit.wires[wire_idx];
63 for (size_t i = 0; i < circuit.num_gates(); 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 // Iterate over all circuit wire polynomials, except the ones representing the op queue, and add random values
73 // at the end.
74 for (size_t idx = Flavor::NUM_OP_QUEUE_WIRES; idx < wires.size(); idx++) {
75 auto& wire = wires[idx];
76 for (size_t i = wire.end_index() - NUM_DISABLED_ROWS_IN_SUMCHECK; i < wire.end_index(); i++) {
77 wire.at(i) = FF::random_element();
78 }
79 }
80
82
83 // Construct the extra range constraint numerator which contains all the additional values in ordered range
84 // constraints not present in the concatenated polynomials
85 // NB this will always have a fixed size unless we change the allowed range
87
88 // Construct the concatenated polynomials from the groups of minicircuit wires
90
91 // Construct the ordered polynomials, containing the values of the concatenated polynomials + enough values to
92 // bridge the range from 0 to 3 (3 is the maximum difference between two consecutive values in the ordered range
93 // constraint).
95 };
96
107 {
108 static const std::array<size_t, Flavor::SORTED_STEPS_COUNT> sorted_elements = [] {
110
111 // The value we have to end polynomials with, 2¹⁴ - 1
112 const size_t max_value = (1 << Flavor::MICRO_LIMB_BITS) - 1;
113
114 parallel_for([&](const ThreadChunk& chunk) {
115 for (size_t idx : chunk.range(Flavor::SORTED_STEPS_COUNT)) {
116 inner_array[idx] = max_value - Flavor::SORT_STEP * idx;
117 }
118 });
119
120 return inner_array;
121 }();
122
123 return sorted_elements;
124 }
125
126 void compute_lagrange_polynomials();
127
128 void compute_extra_range_constraint_numerator();
129
130 void compute_translator_range_constraint_ordered_polynomials();
131
132 void compute_concatenated_polynomials();
133
134 void split_concatenated_random_coefficients_to_ordered();
135};
136} // namespace bb
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:264
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
static constexpr size_t CONCATENATION_GROUP_SIZE
static constexpr size_t NUM_MASKED_ROWS_END
bb::Polynomial< FF > Polynomial
void compute_concatenated_polynomials()
Construct a set of polynomials that are the result of concatenating a group of polynomials into one....
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
void compute_translator_range_constraint_ordered_polynomials()
Compute denominator polynomials for Translator's range constraint permutation.
static constexpr size_t dyadic_circuit_size
TranslatorProvingKey(const Circuit &circuit)
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()
Constructs all Lagrange precomputed polynomials required for Translator relations....
typename Flavor::CircuitBuilder Circuit
#define vinfo(...)
Definition log.hpp:94
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
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
auto range(size_t size, size_t offset=0) const
Definition thread.hpp:152
static field random_element(numeric::RNG *engine=nullptr) noexcept