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
44#pragma once
45
56
57namespace bb {
58
69template <typename FF_> class DependentTestRelationImpl {
70 public:
71 using FF = FF_;
72
73 static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS{
74 2 // degree 1: q_test * w_test_1
75 };
76
77 static constexpr std::array<bool, 1> SUBRELATION_LINEARLY_INDEPENDENT{
78 false // This subrelation is NOT linearly independent (should NOT be scaled)
79 };
80
81 template <typename AllEntities> static bool skip(const AllEntities& in) { return in.q_test.is_zero(); }
82
83 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
84 static void accumulate(ContainerOverSubrelations& evals,
85 const AllEntities& in,
86 const Parameters& /*unused*/,
87 const FF& /*scaling_factor*/)
88 {
90 // Note: NO scaling_factor used here - this is linearly dependent!
91 auto tmp = in.w_test_1 * in.q_test;
92 std::get<0>(evals) += Accumulator(tmp);
93 }
94};
95
97
98} // namespace bb
99
100namespace bb {
101
138template <typename CurveType = curve::BN254, bool HasZK_ = false, bool UseShortMonomials_ = true>
140 public:
143 using FF = typename Curve::ScalarField;
144 using GroupElement = typename Curve::Element;
151
152 // Configuration constants from template parameters
153 static constexpr bool HasZK = HasZK_;
154 static constexpr size_t TRACE_OFFSET = HasZK_ ? NUM_DISABLED_ROWS_IN_SUMCHECK : 0;
155 static constexpr bool USE_SHORT_MONOMIALS = UseShortMonomials_;
156 static constexpr bool USE_PADDING = false;
157 static constexpr size_t NUM_WIRES = bb::NUM_WIRES;
158
159 // Entity counts:
160 // Precomputed: q_m, q_l, q_r, q_o, q_4, q_c, q_arith + q_test = 8
161 // Witness: w_l, w_r, w_o, w_4 + w_test_1, w_test_2 = 6
162 // Shifted: w_l_shift, w_4_shift = 2
163 // Note: No gemini_masking_poly - that's a PCS concept, not sumcheck
164 static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 8;
165 static constexpr size_t NUM_WITNESS_ENTITIES = 6;
166 static constexpr size_t NUM_SHIFTED_ENTITIES = 2;
168
169 // Two relations: Arithmetic (linearly independent) + DependentTest (linearly dependent)
170 // Tests can activate either or both via selectors:
171 // - q_arith = 1 : activate arithmetic relation (linearly independent, WILL be scaled)
172 // - q_test = 1 : activate dependent test relation (linearly dependent, will NOT be scaled)
175
176 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
177 // For ZK flavors, BATCHED_RELATION_PARTIAL_LENGTH is incremented by 1 for the libra masking univariates
178 // For BN254 with ZK, this must match Curve::LIBRA_UNIVARIATES_LENGTH (9)
179 // Note: MAX_PARTIAL_RELATION_LENGTH = 6 (from ArithmeticRelation's [6,5])
180 // Non-ZK: 6 + 1 = 7
181 // ZK: 6 + 3 = 9 (matches BN254::LIBRA_UNIVARIATES_LENGTH)
183 static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
186
191 template <typename DataType> class PrecomputedEntities {
192 public:
193 DEFINE_FLAVOR_MEMBERS(DataType,
194 q_m, // Multiplication selector (arithmetic)
195 q_l, // Left wire selector (arithmetic)
196 q_r, // Right wire selector (arithmetic)
197 q_o, // Output wire selector (arithmetic)
198 q_4, // Fourth wire selector (arithmetic)
199 q_c, // Constant selector (arithmetic)
200 q_arith, // Arithmetic gate enable (linearly independent, WILL be scaled)
201 q_test) // Test relation enable (linearly dependent, will NOT be scaled)
202 };
203
208 template <typename DataType> class WitnessEntities {
209 public:
210 DEFINE_FLAVOR_MEMBERS(DataType,
211 w_l, // Left wire (arithmetic)
212 w_r, // Right wire (arithmetic)
213 w_o, // Output wire (arithmetic)
214 w_4, // Fourth wire (arithmetic)
215 w_test_1, // Test wire 1 (dependent test relation)
216 w_test_2) // Test wire 2 (dependent test relation, currently unused)
217 };
218
222 template <typename DataType> class ShiftedEntities {
223 public:
224 DEFINE_FLAVOR_MEMBERS(DataType,
225 w_l_shift, // w_l shifted by 1
226 w_4_shift) // w_4 shifted by 1
227 };
228
235 template <typename DataType>
236 class AllEntities : public PrecomputedEntities<DataType>,
237 public WitnessEntities<DataType>,
238 public ShiftedEntities<DataType> {
239 public:
241
247
248 // EntityId-keyed access. Relations that take an `AllEntities` (e.g. ArithmeticRelation)
249 // use `in[AllEntities::EntityId::name]`; member fields q_m/q_l/.../w_4_shift come from the
250 // DEFINE_FLAVOR_MEMBERS-emitted public fields in the three base classes above.
251 enum class EntityId : uint16_t {
252 q_m = 0,
253 q_l,
254 q_r,
255 q_o,
256 q_4,
257 q_c,
258 q_arith,
259 q_test,
260 w_l,
261 w_r,
262 w_o,
263 w_4,
264 w_test_1,
265 w_test_2,
266 w_l_shift,
267 w_4_shift,
268 };
269
270 static constexpr std::array<DataType AllEntities::*, NUM_ALL_ENTITIES> ENTITY_REFS{
272 &AllEntities::q_4, &AllEntities::q_c, &AllEntities::q_arith, &AllEntities::q_test,
274 &AllEntities::w_test_1, &AllEntities::w_test_2, &AllEntities::w_l_shift, &AllEntities::w_4_shift,
275 };
276 DataType& operator[](EntityId id) { return this->*ENTITY_REFS[static_cast<size_t>(id)]; }
277 const DataType& operator[](EntityId id) const { return this->*ENTITY_REFS[static_cast<size_t>(id)]; }
278 };
279
283 class ProverPolynomials : public AllEntities<Polynomial> {
284 public:
285 ProverPolynomials() = default;
286 ProverPolynomials(size_t circuit_size)
287 {
288 for (auto& poly : this->get_precomputed()) {
289 poly = Polynomial(circuit_size);
290 }
291 for (auto& poly : this->get_witness()) {
292 poly = Polynomial(circuit_size);
293 }
294 for (auto& poly : this->get_shifted()) {
295 poly = Polynomial(circuit_size);
296 }
297 }
298
299 [[nodiscard]] size_t get_polynomial_size() const { return this->w_l.size(); }
300
305 auto get_to_be_shifted() { return RefArray{ this->w_l, this->w_4 }; }
306
312 {
313 for (auto [shifted, to_be_shifted] : zip_view(this->get_shifted(), this->get_to_be_shifted())) {
314 shifted = to_be_shifted.shifted();
315 }
316 }
317 };
318
323
328
332 class AllValues : public AllEntities<FF> {
333 public:
335 using Base::Base;
336 };
337
343};
344
345// ================================================================================================
346// Convenient type aliases for common test configurations
347// ================================================================================================
348// Note: All flavors include both relations (arithmetic + test).
349// Tests can choose which to activate via selectors (q_arith = 1 or q_test = 1).
350
356
362
368
375
381
382} // 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:23
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
const DataType & operator[](EntityId id) const
static constexpr std::array< DataType AllEntities::*, NUM_ALL_ENTITIES > ENTITY_REFS
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 USE_PADDING
bb::Polynomial< FF > Polynomial
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
static constexpr size_t TRACE_OFFSET
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
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
typename Group::element Element
Definition grumpkin.hpp:63
typename Group::affine_element AffineElement
Definition grumpkin.hpp:64
Base class templates shared across Honk flavors.
#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