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 {
14 public:
17 using FF = typename Flavor::FF;
18 using BF = typename Flavor::BF;
23 // The actual circuit size is several times bigger than the trace in the circuit, because we use concatenation
24 // to bring the degree of relations down, while extending the length.
26
27 // Real mini and full circuit sizes i.e. the number of rows excluding those reserved for randomness (to achieve
28 // hiding of polynomial commitments and evaluation). Bound to change, but it has to be even as translator works two
29 // rows at a time
32 static constexpr size_t dyadic_circuit_size_without_masking =
34
35 std::shared_ptr<ProvingKey> proving_key;
36
39
41
45 {
46 BB_BENCH_NAME("TranslatorProvingKey(TranslatorCircuit&)");
47 // Check that the Translator Circuit does not exceed the fixed upper bound, the current value amounts to
48 // a number of EccOps sufficient for 28 app circuits
49 vinfo("Translator circuit size: ", circuit.num_gates());
50 BB_ASSERT_LTE(circuit.num_gates(),
52 "The Translator circuit size has exceeded the fixed upper bound");
53
55 auto wires = proving_key->polynomials.get_wires();
56 // Distribute wires across threads (one task per wire) rather than multithreading within each wire.
57 parallel_for(wires.size(), [&](size_t wire_idx) {
58 auto& wire_poly = wires[wire_idx];
59 const auto& wire = circuit.wires[wire_idx];
60 for (size_t i = 0; i < circuit.num_gates(); i++) {
61 if (i >= wire_poly.start_index() && i < wire_poly.end_index()) {
62 wire_poly.at(i) = circuit.get_variable(wire[i]);
63 } else {
64 BB_ASSERT_EQ(circuit.get_variable(wire[i]), 0);
65 }
66 }
67 });
68
69 // Iterate over all circuit wire polynomials, except the ones representing the op queue, and add random values
70 // at the end.
71 for (size_t idx = Flavor::NUM_OP_QUEUE_WIRES; idx < wires.size(); idx++) {
72 auto& wire = wires[idx];
73 for (size_t i = wire.end_index() - NUM_DISABLED_ROWS_IN_SUMCHECK; i < wire.end_index(); i++) {
74 wire.at(i) = FF::random_element();
75 }
76 }
77
79
80 // Construct the extra range constraint numerator which contains all the additional values in ordered range
81 // constraints not present in the concatenated polynomials
82 // NB this will always have a fixed size unless we change the allowed range
84
85 // Construct the concatenated polynomials from the groups of minicircuit wires
87
88 // Construct the ordered polynomials, containing the values of the concatenated polynomials + enough values to
89 // bridge the range from 0 to 3 (3 is the maximum difference between two consecutive values in the ordered range
90 // constraint).
92 };
93
104 {
105 static const std::array<size_t, Flavor::SORTED_STEPS_COUNT> sorted_elements = [] {
107
108 // The value we have to end polynomials with, 2¹⁴ - 1
109 const size_t max_value = (1 << Flavor::MICRO_LIMB_BITS) - 1;
110
111 parallel_for([&](const ThreadChunk& chunk) {
112 for (size_t idx : chunk.range(Flavor::SORTED_STEPS_COUNT)) {
113 inner_array[idx] = max_value - Flavor::SORT_STEP * idx;
114 }
115 });
116
117 return inner_array;
118 }();
119
120 return sorted_elements;
121 }
122
123 void compute_lagrange_polynomials();
124
125 void compute_extra_range_constraint_numerator();
126
127 void compute_translator_range_constraint_ordered_polynomials();
128
129 void compute_concatenated_polynomials();
130
131 void split_concatenated_random_coefficients_to_ordered();
132};
133} // 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
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
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