Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
multilinear_batching_flavor.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
17
18namespace bb {
19
21 public:
26 using PCS = KZG<Curve>;
31
32 // An upper bound on the size of the MultilinearBatching-circuits. `CONST_FOLDING_LOG_N` bounds the log circuit
33 // sizes in the Chonk context. `MEGA_AVM_LOG_N` is determined by the size of the AVMRecursiveVerifier.
34 static constexpr size_t VIRTUAL_LOG_N = std::max(CONST_FOLDING_LOG_N, MEGA_AVM_LOG_N);
35 static constexpr bool USE_SHORT_MONOMIALS = false;
36 // Indicates that this flavor runs with non-ZK Sumcheck.
37 static constexpr bool HasZK = false;
38 // Indicates that this flavor runs with Multilinear Batching.
39 static constexpr bool IS_MULTILINEAR_BATCHING = true;
40 // To achieve fixed proof size and that the recursive verifier circuit is constant, we are using padding in Sumcheck
41 // and Shplemini
42 static constexpr bool USE_PADDING = true;
43 static constexpr size_t NUM_WIRES = 4;
44 // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often
45 // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`.
46 static constexpr size_t NUM_ALL_ENTITIES = 6;
47 // The total number of witness entities not including shifts.
48 static constexpr size_t NUM_WITNESS_ENTITIES = 4;
49 // The number of shifted witness entities including derived witness entities
50 static constexpr size_t NUM_SHIFTED_ENTITIES = 2;
51
52 // define the tuple of Relations that comprise the Sumcheck relation
53 // Note: made generic for use in MegaRecursive.
54 template <typename FF>
55 using Relations_ =
58
59 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
60 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
61 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
62 // length = 3
65
66 // A challenge whose powers are used to batch subrelation contributions during Sumcheck
67 static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
69
70 // Whether or not the first row of the execution trace is reserved for 0s to enable shifts
71 static constexpr bool has_zero_row = false;
72
73 static constexpr size_t num_frs_comm = FrCodec::calc_num_fields<Commitment>();
74 static constexpr size_t num_frs_fr = FrCodec::calc_num_fields<FF>();
75
76 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS()
77 {
78 return /*accumulator commitments*/ (NUM_WITNESS_ENTITIES / 2 * num_frs_comm) +
79 /*multivariate challenges*/ (VIRTUAL_LOG_N * num_frs_fr) +
80 /*witness evaluations*/ (NUM_WITNESS_ENTITIES / 2 * num_frs_fr) +
81 /*sumcheck univariates*/ (VIRTUAL_LOG_N * BATCHED_RELATION_PARTIAL_LENGTH * num_frs_fr) +
82 /*sumcheck evaluations*/ (NUM_ALL_ENTITIES * num_frs_fr);
83 }
84
85 // WireEntities for basic witness entities
86 template <typename DataType> class WireEntities {
87 public:
89 w_non_shifted_accumulator, // column 0
90 w_non_shifted_instance, // column 1
91 w_evaluations_accumulator, // column 2, eq(Sumcheck::alpha, accumulator_challenge)
92 w_evaluations_instance); // column 3, eq(Sumcheck::alpha, instance_challenge)
93 };
94
100 template <typename DataType> class WitnessEntities : public WireEntities<DataType> {
101 public:
103 w_non_shifted_accumulator, // column 0
104 w_non_shifted_instance, // column 1
105 w_evaluations_accumulator, // column 2, eq(Sumcheck::alpha, accumulator_challenge)
106 w_evaluations_instance); // column 3, eq(Sumcheck::alpha, instance_challenge)
107
108 MSGPACK_FIELDS(this->w_non_shifted_accumulator,
109 this->w_non_shifted_instance,
110 this->w_evaluations_accumulator,
111 this->w_evaluations_instance);
112 };
113
117 template <typename DataType> class ShiftedEntities {
118 public:
120 w_shifted_accumulator, // column 0
121 w_shifted_instance // column 1
122 );
123 auto get_shifted() { return RefArray{ w_shifted_accumulator, w_shifted_instance }; };
124 };
125
135 template <typename DataType>
145
150 class AllValues : public AllEntities<FF> {
151 public:
153 using Base::Base;
154 };
155
159 class ProverPolynomials : public AllEntities<Polynomial> {
160 public:
161 // Define all operations as default, except copy construction/assignment
162 ProverPolynomials() = default;
163 // fully-formed constructor
164 ProverPolynomials(size_t circuit_size)
165 {
166 BB_BENCH_NAME("ProverPolynomials(size_t)");
167
168 // catch-all with fully formed polynomials
169 for (auto& poly : get_unshifted()) {
170 if (poly.is_empty()) {
171 // Not set above
172 poly = Polynomial{ /*memory size*/ circuit_size, /*largest possible index*/ 1 << VIRTUAL_LOG_N };
173 }
174 }
175
176 for (auto& poly : get_shifted()) {
177 poly = Polynomial{ /*memory size*/ circuit_size, /*largest possible index*/ 1 << VIRTUAL_LOG_N };
178 }
179 }
180 [[nodiscard]] size_t get_polynomial_size() const { return w_non_shifted_accumulator.size(); }
181 void increase_polynomials_virtual_size(const size_t size_in)
182 {
183 for (auto& polynomial : this->get_all()) {
184 polynomial.increase_virtual_size(size_in);
185 }
186 }
187 };
188
194 public:
195 ProverPolynomials polynomials; // storage for all polynomials evaluated by the prover
196 std::vector<FF> accumulator_challenge;
197 std::vector<FF> instance_challenge;
198 std::vector<FF> accumulator_evaluations;
199 std::vector<FF> instance_evaluations;
213 };
214
218 class PartiallyEvaluatedMultivariates : public AllEntities<Polynomial> {
219
220 public:
222 PartiallyEvaluatedMultivariates(const ProverPolynomials& full_polynomials, size_t circuit_size)
223 {
224 for (auto [poly, full_poly] : zip_view(get_all(), full_polynomials.get_all())) {
225 // After the initial sumcheck round, the new size is CEIL(size/2).
226 size_t desired_size = full_poly.end_index() / 2 + full_poly.end_index() % 2;
227 poly = Polynomial(desired_size, circuit_size / 2);
228 }
229 }
230 };
231
237
242
247
254 class CommitmentLabels : public AllEntities<std::string> {
255 public:
257 {
258 w_non_shifted_accumulator = "W_NON_SHIFTED_ACCUMULATOR";
259 w_non_shifted_instance = "W_NON_SHIFTED_INSTANCE";
260 w_evaluations_accumulator = "W_EVALUATIONS_ACCUMULATOR";
261 w_evaluations_instance = "W_EVALUATIONS_INSTANCE";
262 w_shifted_accumulator = "W_SHIFTED_ACCUMULATOR";
263 w_shifted_instance = "W_SHIFTED_INSTANCE";
264 };
265 };
266};
267
268} // namespace bb
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:219
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
A base class labelling all entities (for instance, all of the polynomials used by the prover during s...
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
A container for storing the partially evaluated multivariates produced by sumcheck.
PartiallyEvaluatedMultivariates(const ProverPolynomials &full_polynomials, size_t circuit_size)
A container for the prover polynomials handles.
The proving key is responsible for storing the polynomials used by the prover.
ProvingKey(ProverPolynomials &&polynomials, std::vector< FF > accumulator_challenge, std::vector< FF > instance_challenge, std::vector< FF > accumulator_evaluations, std::vector< FF > instance_evaluations)
Class for ShiftedEntities, containing the shifted witness polynomials.
DEFINE_FLAVOR_MEMBERS(DataType, w_shifted_accumulator, w_shifted_instance)
DEFINE_FLAVOR_MEMBERS(DataType, w_non_shifted_accumulator, w_non_shifted_instance, w_evaluations_accumulator, w_evaluations_instance)
Container for all witness polynomials used/constructed by the prover.
DEFINE_FLAVOR_MEMBERS(DataType, w_non_shifted_accumulator, w_non_shifted_instance, w_evaluations_accumulator, w_evaluations_instance)
MSGPACK_FIELDS(this->w_non_shifted_accumulator, this->w_non_shifted_instance, this->w_evaluations_accumulator, this->w_evaluations_instance)
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS()
std::tuple< bb::MultilinearBatchingAccumulatorRelation< FF >, bb::MultilinearBatchingInstanceRelation< FF > > Relations_
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
typename Group::element Element
Definition bn254.hpp:21
typename Group::affine_element AffineElement
Definition bn254.hpp:22
bb::fr ScalarField
Definition bn254.hpp:18
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
#define DEFINE_COMPOUND_GET_ALL(...)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13