Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
sumcheck_test_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
50#pragma once
51
60
61namespace bb {
62
73template <typename FF_> class DependentTestRelationImpl {
74 public:
75 using FF = FF_;
76
77 static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS{
78 2 // degree 1: q_test * w_test_1
79 };
80
81 static constexpr std::array<bool, 1> SUBRELATION_LINEARLY_INDEPENDENT{
82 false // This subrelation is NOT linearly independent (should NOT be scaled)
83 };
84
85 template <typename AllEntities> static bool skip(const AllEntities& in) { return in.q_test.is_zero(); }
86
87 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
88 static void accumulate(ContainerOverSubrelations& evals,
89 const AllEntities& in,
90 const Parameters& /*unused*/,
91 const FF& /*scaling_factor*/)
92 {
94 // Note: NO scaling_factor used here - this is linearly dependent!
95 auto tmp = in.w_test_1 * in.q_test;
96 std::get<0>(evals) += Accumulator(tmp);
97 }
98};
99
101
102} // namespace bb
103
104namespace bb {
105
142template <typename CurveType = curve::BN254, bool HasZK_ = false, bool UseShortMonomials_ = true>
144 public:
147 using FF = typename Curve::ScalarField;
148 using GroupElement = typename Curve::Element;
155
156 // Configuration constants from template parameters
157 static constexpr bool HasZK = HasZK_;
158 static constexpr bool USE_SHORT_MONOMIALS = UseShortMonomials_;
159 static constexpr bool USE_PADDING = false;
160 static constexpr size_t NUM_WIRES = 4;
161
162 // Entity counts:
163 // Precomputed: q_m, q_l, q_r, q_o, q_4, q_c, q_arith + q_test = 8
164 // Witness: w_l, w_r, w_o, w_4 + w_test_1, w_test_2 = 6
165 // Shifted: w_l_shift, w_4_shift = 2
166 // Note: No gemini_masking_poly - that's a PCS concept, not sumcheck
167 static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 8;
168 static constexpr size_t NUM_WITNESS_ENTITIES = 6;
169 static constexpr size_t NUM_SHIFTED_ENTITIES = 2;
171
172 // Two relations: Arithmetic (linearly independent) + DependentTest (linearly dependent)
173 // Tests can activate either or both via selectors:
174 // - q_arith = 1 : activate arithmetic relation (linearly independent, WILL be scaled)
175 // - q_test = 1 : activate dependent test relation (linearly dependent, will NOT be scaled)
178
179 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
180 // For ZK flavors, BATCHED_RELATION_PARTIAL_LENGTH is incremented by 1 for the libra masking univariates
181 // For BN254 with ZK, this must match Curve::LIBRA_UNIVARIATES_LENGTH (9)
182 // Note: MAX_PARTIAL_RELATION_LENGTH = 6 (from ArithmeticRelation's [6,5])
183 // Non-ZK: 6 + 1 = 7
184 // ZK: 6 + 3 = 9 (matches BN254::LIBRA_UNIVARIATES_LENGTH)
186 static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
189
190 static constexpr bool has_zero_row = false;
191
196 template <typename DataType> class PrecomputedEntities {
197 public:
198 DEFINE_FLAVOR_MEMBERS(DataType,
199 q_m, // Multiplication selector (arithmetic)
200 q_l, // Left wire selector (arithmetic)
201 q_r, // Right wire selector (arithmetic)
202 q_o, // Output wire selector (arithmetic)
203 q_4, // Fourth wire selector (arithmetic)
204 q_c, // Constant selector (arithmetic)
205 q_arith, // Arithmetic gate enable (linearly independent, WILL be scaled)
206 q_test) // Test relation enable (linearly dependent, will NOT be scaled)
207 };
208
213 template <typename DataType> class WitnessEntities {
214 public:
215 DEFINE_FLAVOR_MEMBERS(DataType,
216 w_l, // Left wire (arithmetic)
217 w_r, // Right wire (arithmetic)
218 w_o, // Output wire (arithmetic)
219 w_4, // Fourth wire (arithmetic)
220 w_test_1, // Test wire 1 (dependent test relation)
221 w_test_2) // Test wire 2 (dependent test relation, currently unused)
222 };
223
227 template <typename DataType> class ShiftedEntities {
228 public:
229 DEFINE_FLAVOR_MEMBERS(DataType,
230 w_l_shift, // w_l shifted by 1
231 w_4_shift) // w_4 shifted by 1
232 };
233
240 template <typename DataType>
252
256 class ProverPolynomials : public AllEntities<Polynomial> {
257 public:
258 ProverPolynomials() = default;
259 ProverPolynomials(size_t circuit_size)
260 {
261 for (auto& poly : this->get_precomputed()) {
262 poly = Polynomial(circuit_size);
263 }
264 for (auto& poly : this->get_witness()) {
265 poly = Polynomial(circuit_size);
266 }
267 for (auto& poly : this->get_shifted()) {
268 poly = Polynomial(circuit_size);
269 }
270 }
271
272 [[nodiscard]] size_t get_polynomial_size() const { return this->w_l.size(); }
273
278 auto get_to_be_shifted() { return RefArray{ this->w_l, this->w_4 }; }
279
285 {
286 for (auto [shifted, to_be_shifted] : zip_view(this->get_shifted(), this->get_to_be_shifted())) {
287 shifted = to_be_shifted.shifted();
288 }
289 }
290 };
291
296
301
305 class AllValues : public AllEntities<FF> {
306 public:
308 using Base::Base;
309 };
310
314 class PartiallyEvaluatedMultivariates : public AllEntities<Polynomial> {
315 public:
317 PartiallyEvaluatedMultivariates(const ProverPolynomials& full_polynomials, size_t circuit_size)
318 {
319 for (auto [poly, full_poly] : zip_view(this->get_all(), full_polynomials.get_all())) {
320 size_t desired_size = (full_poly.end_index() / 2) + (full_poly.end_index() % 2);
321 poly = Polynomial(desired_size, circuit_size / 2);
322 }
323 }
324 };
325};
326
327// ================================================================================================
328// Convenient type aliases for common test configurations
329// ================================================================================================
330// Note: All flavors include both relations (arithmetic + test).
331// Tests can choose which to activate via selectors (q_arith = 1 or q_test = 1).
332
338
344
350
357
363
364} // namespace bb
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 linearly dependent test relation for sumcheck testing.
static bool skip(const AllEntities &in)
static constexpr std::array< bool, 1 > SUBRELATION_LINEARLY_INDEPENDENT
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const Parameters &, const FF &)
static constexpr std::array< size_t, 1 > SUBRELATION_PARTIAL_LENGTHS
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...
Partially evaluated multivariates for folded sumcheck.
PartiallyEvaluatedMultivariates(const ProverPolynomials &full_polynomials, size_t circuit_size)
auto get_to_be_shifted()
Get the polynomials that will be shifted.
void set_shifted()
Set all shifted polynomials based on their to-be-shifted counterpart.
A flexible, minimal test flavor for sumcheck testing.
typename Curve::ScalarField FF
static constexpr size_t NUM_SUBRELATIONS
std::tuple< ArithmeticRelation< FF_ >, DependentTestRelation< FF_ > > Relations_
static constexpr bool USE_SHORT_MONOMIALS
static constexpr size_t NUM_ALL_ENTITIES
typename Curve::AffineElement Commitment
static constexpr bool has_zero_row
static constexpr bool USE_PADDING
bb::Polynomial< FF > Polynomial
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t NUM_WIRES
typename Curve::Element GroupElement
static constexpr size_t NUM_RELATIONS
typename Group::element Element
Definition grumpkin.hpp:62
typename Group::affine_element AffineElement
Definition grumpkin.hpp:63
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
#define DEFINE_FLAVOR_MEMBERS(DataType,...)
Define the body of a flavor class, included each member and a pointer view with which to iterate the ...
#define DEFINE_COMPOUND_GET_ALL(...)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
CurveType
Definition types.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13