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// TODO(https://github.com/AztecProtocol/barretenberg/issues/1317)
15 public:
18 using FF = typename Flavor::FF;
19 using BF = typename Flavor::BF;
24 // The actual circuit size is several times bigger than the trace in the circuit, because we use concatenation
25 // to bring the degree of relations down, while extending the length.
27
28 // Real mini and full circuit sizes i.e. the number of rows excluding those reserved for randomness (to achieve
29 // hiding of polynomial commitments and evaluation). Bound to change, but it has to be even as translator works two
30 // rows at a time
33 static constexpr size_t dyadic_circuit_size_without_masking =
35
36 std::shared_ptr<ProvingKey> proving_key;
37
40
42
46 {
47 BB_BENCH_NAME("TranslatorProvingKey(TranslatorCircuit&)");
48 // Check that the Translator Circuit does not exceed the fixed upper bound, the current value amounts to
49 // a number of EccOps sufficient for 28 app circuits
50 vinfo("Translator circuit size: ", circuit.num_gates());
51 BB_ASSERT_LTE(circuit.num_gates(),
53 "The Translator circuit size has exceeded the fixed upper bound");
54
56 auto wires = proving_key->polynomials.get_wires();
57 for (auto [wire_poly_, wire_] : zip_view(wires, circuit.wires)) {
58 auto& wire_poly = wire_poly_;
59 const auto& wire = wire_;
60 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1383)
61 parallel_for_range(circuit.num_gates(), [&](size_t start, size_t end) {
62 for (size_t i = start; i < end; i++) {
63 if (i >= wire_poly.start_index() && i < wire_poly.end_index()) {
64 wire_poly.at(i) = circuit.get_variable(wire[i]);
65 } else {
66 BB_ASSERT_EQ(circuit.get_variable(wire[i]), 0);
67 }
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:225
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 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
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
auto range(size_t size, size_t offset=0) const
Definition thread.hpp:152
static field random_element(numeric::RNG *engine=nullptr) noexcept