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: 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
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.
34 static constexpr size_t VIRTUAL_LOG_N = CONST_FOLDING_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 batched_unshifted_accumulator, // column 0: batched unshifted poly for accumulator
90 batched_unshifted_instance, // column 1: batched unshifted poly for instance
91 eq_accumulator, // column 2: eq(u, r_acc) - selects accumulator eval point
92 eq_instance); // column 3: eq(u, r_inst) - selects instance eval point
93 };
94
100 template <typename DataType> class WitnessEntities : public WireEntities<DataType> {
101 public:
103 batched_unshifted_accumulator, // column 0: batched unshifted poly for accumulator
104 batched_unshifted_instance, // column 1: batched unshifted poly for instance
105 eq_accumulator, // column 2: eq(u, r_acc) - selects accumulator eval point
106 eq_instance); // column 3: eq(u, r_inst) - selects instance eval point
107 };
108
112 template <typename DataType> class ShiftedEntities {
113 public:
115 batched_shifted_accumulator, // column 0: batched shifted poly for accumulator
116 batched_shifted_instance // column 1: batched shifted poly for instance
117 );
118 auto get_shifted() { return RefArray{ batched_shifted_accumulator, batched_shifted_instance }; };
119 };
120
130 template <typename DataType>
140
145 class AllValues : public AllEntities<FF> {
146 public:
148 using Base::Base;
149 };
150
154 class ProverPolynomials : public AllEntities<Polynomial> {
155 public:
156 // Define all operations as default, except copy construction/assignment
157 ProverPolynomials() = default;
158 // fully-formed constructor
159 ProverPolynomials(size_t circuit_size)
160 {
161 BB_BENCH_NAME("ProverPolynomials(size_t)");
162
163 // catch-all with fully formed polynomials
164 for (auto& poly : get_unshifted()) {
165 if (poly.is_empty()) {
166 // Not set above
167 poly = Polynomial{ /*memory size*/ circuit_size, /*largest possible index*/ 1 << VIRTUAL_LOG_N };
168 }
169 }
170
171 for (auto& poly : get_shifted()) {
172 poly = Polynomial{ /*memory size*/ circuit_size, /*largest possible index*/ 1 << VIRTUAL_LOG_N };
173 }
174 }
175 [[nodiscard]] size_t get_polynomial_size() const { return batched_unshifted_accumulator.size(); }
176 void increase_polynomials_virtual_size(const size_t size_in)
177 {
178 for (auto& polynomial : this->get_all()) {
179 polynomial.increase_virtual_size(size_in);
180 }
181 }
182 };
183
189 public:
190 ProverPolynomials polynomials; // storage for all polynomials evaluated by the prover
191 std::vector<FF> accumulator_challenge;
192 std::vector<FF> instance_challenge;
193 std::vector<FF> accumulator_evaluations;
194 std::vector<FF> instance_evaluations;
208 };
209
213 class PartiallyEvaluatedMultivariates : public AllEntities<Polynomial> {
214
215 public:
217 PartiallyEvaluatedMultivariates(const ProverPolynomials& full_polynomials, size_t circuit_size)
218 {
219 for (auto [poly, full_poly] : zip_view(get_all(), full_polynomials.get_all())) {
220 // After the initial sumcheck round, the new size is CEIL(size/2).
221 size_t desired_size = full_poly.end_index() / 2 + full_poly.end_index() % 2;
222 poly = Polynomial(desired_size, circuit_size / 2);
223 }
224 }
225 };
226
232
237
242
249 class CommitmentLabels : public AllEntities<std::string> {
250 public:
252 {
253 batched_unshifted_accumulator = "BATCHED_UNSHIFTED_ACCUMULATOR";
254 batched_unshifted_instance = "BATCHED_UNSHIFTED_INSTANCE";
255 eq_accumulator = "EQ_ACCUMULATOR";
256 eq_instance = "EQ_INSTANCE";
257 batched_shifted_accumulator = "BATCHED_SHIFTED_ACCUMULATOR";
258 batched_shifted_instance = "BATCHED_SHIFTED_INSTANCE";
259 };
260 };
261};
262
263} // 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, batched_shifted_accumulator, batched_shifted_instance)
DEFINE_FLAVOR_MEMBERS(DataType, batched_unshifted_accumulator, batched_unshifted_instance, eq_accumulator, eq_instance)
Container for all witness polynomials used/constructed by the prover.
DEFINE_FLAVOR_MEMBERS(DataType, batched_unshifted_accumulator, batched_unshifted_instance, eq_accumulator, eq_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...
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
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