Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
eccvm_flavor.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Raju], commit: 2a49eb6 }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
31
32// NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
33
34namespace bb {
35
37 public:
41 using G1 = typename Curve::Group;
42 using FF = typename Curve::ScalarField;
43 using BF = typename Curve::BaseField;
45 using GroupElement = typename G1::element;
46 using Commitment = typename G1::affine_element;
50 using Codec = FrCodec;
54
55 // indicates when evaluating sumcheck, edges must be extended to be MAX_PARTIAL_RELATION_LENGTH
56 static constexpr bool USE_SHORT_MONOMIALS = false;
57
58 // Indicates that this flavor runs with ZK Sumcheck.
59 static constexpr bool HasZK = true;
60 // ECCVM proof size and its recursive verifier circuit are genuinely fixed, hence no padding is needed.
61 static constexpr bool USE_PADDING = false;
62 // Fixed size of the ECCVM circuits used in Chonk
63 // Important: these constants cannot be arbitrarily changes - please consult with a member of the Crypto team if
64 // they become too small.
65 static constexpr size_t ECCVM_FIXED_SIZE = 1UL << CONST_ECCVM_LOG_N;
66
67 static constexpr size_t NUM_WIRES = 85;
68
69 // The number of entities added for ZK (gemini_masking_poly)
70 static constexpr size_t NUM_MASKING_POLYNOMIALS = 1;
71
72 // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often
73 // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`.
74 // Note: this number does not include the individual sorted list polynomials.
75 // Includes gemini_masking_poly for ZK (NUM_ALL_ENTITIES = 117 + NUM_MASKING_POLYNOMIALS)
76 static constexpr size_t NUM_ALL_ENTITIES = 118;
77 // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying
78 // assignment of witnesses. We again choose a neutral name.
79 static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 4;
80 // The total number of witness entities not including shifts.
81 // Includes gemini_masking_poly for ZK (NUM_WITNESS_ENTITIES = 86 + NUM_MASKING_POLYNOMIALS)
82 static constexpr size_t NUM_WITNESS_ENTITIES = 87;
83 // The number of entities in ShiftedEntities.
84 static constexpr size_t NUM_SHIFTED_ENTITIES = 26;
85 // The number of entities in DerivedWitnessEntities that are not going to be shifted.
86 static constexpr size_t NUM_DERIVED_WITNESS_ENTITIES_NON_SHIFTED = 1;
87 // A container to be fed to ShpleminiVerifier to avoid redundant scalar muls, the first number is the index of the
88 // first witness to be shifted.
94
96 // define the tuple of Relations that comprise the Sumcheck relation
97 template <typename FF>
107
108 static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
109 using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;
110
111 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
112
113 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
114 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
115 // length = 3.
116 // The degree has to be further increased by 1 because the relation is multiplied by the Row Disabling //
117 // Polynomial
119 static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;
120
121 static constexpr size_t num_frs_comm = FrCodec::calc_num_fields<Commitment>();
122 static constexpr size_t num_frs_fq = FrCodec::calc_num_fields<FF>();
123
124 // Proof length formula
125 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS =
126 /* 1. NUM_WITNESS_ENTITIES commitments */ ((NUM_WITNESS_ENTITIES + NUM_MASKING_POLYNOMIALS) * num_frs_comm) +
127 /* 2. Libra concatenation commitment*/ (num_frs_comm) +
128 /* 3. Libra sum */ (num_frs_fq) +
129 /* 4. CONST_ECCVM_LOG_N sumcheck univariates commitments */
130 (CONST_ECCVM_LOG_N * num_frs_comm) +
131 /* 5. 2 * CONST_ECCVM_LOG_N sumcheck univariate evaluations */
132 (2 * CONST_ECCVM_LOG_N * num_frs_fq) +
133 /* 6. NUM_ALL_ENTITIES sumcheck evaluations*/ (NUM_ALL_ENTITIES * num_frs_fq) +
134 /* 7. Libra claimed evaluation */ (num_frs_fq) +
135 /* 8. Libra grand sum commitment */ (num_frs_comm) +
136 /* 9. Libra quotient commitment */ (num_frs_comm) +
137 /* 10. CONST_ECCVM_LOG_N - 1 Gemini Fold commitments */
138 ((CONST_ECCVM_LOG_N - 1) * num_frs_comm) +
139 /* 11. CONST_ECCVM_LOG_N Gemini a evaluations */
140 (CONST_ECCVM_LOG_N * num_frs_fq) +
141 /* 12. NUM_SMALL_IPA_EVALUATIONS libra evals */ (NUM_SMALL_IPA_EVALUATIONS * num_frs_fq) +
142 /* 13. Shplonk Q commitment */ (num_frs_comm) +
143 /* 14. Translator concatenated masking term commitment */ (num_frs_comm) +
144 /* 15 Translator op evaluation */ (num_frs_fq) +
145 /* 16 Translator Px evaluation */ (num_frs_fq) +
146 /* 17 Translator Py evaluation */ (num_frs_fq) +
147 /* 18 Translator z1 evaluation */ (num_frs_fq) +
148 /* 19 Translator z2 evaluation */ (num_frs_fq) +
149 /* 20 Translator concatenated masking term evaluation */ (num_frs_fq) +
150 /* 21 Translator grand sum commitment */ (num_frs_comm) +
151 /* 22 Translator quotient commitment */ (num_frs_comm) +
152 /* 23 Translator concatenation eval */ (num_frs_fq) +
153 /* 24 Translator grand sum shift eval */ (num_frs_fq) +
154 /* 25 Translator grand sum eval */ (num_frs_fq) +
155 /* 26 Translator quotient eval */ (num_frs_fq) +
156 /* 27 Shplonk Q commitment */ (num_frs_comm);
157
158 // The sub-protocol `compute_translation_opening_claims` outputs an opening claim for the batched univariate
159 // evaluation of `op`, `Px`, `Py`, `z1`, and `z2`, and an array of opening claims for the evaluations of the
160 // SmallSubgroupIPA witness polynomials.
161 static constexpr size_t NUM_TRANSLATION_OPENING_CLAIMS = NUM_SMALL_IPA_EVALUATIONS + 1;
162
163 // TODO(https://github.com/AztecProtocol/barretenberg/issues/989): refine access specifiers in flavors, this is
164 // public as it is also used in the recursive flavor but the two could possibly me unified eventually
169 template <typename DataType_> class PrecomputedEntities {
170 public:
171 bool operator==(const PrecomputedEntities& other) const = default;
172 using DataType = DataType_;
174 lagrange_first, // column 0
175 lagrange_second, // column 1 - hiding op row
176 lagrange_third, // column 2 - first real op row
177 lagrange_last); // column 3
178
179 DataType get_selectors() { return get_all(); };
180 };
181
186 template <typename DataType> struct DerivedWitnessEntities {
188 z_perm, // column 0
189 lookup_inverses); // column 1
190 };
191 template <typename DataType> class WireNonShiftedEntities {
192 public:
193 DEFINE_FLAVOR_MEMBERS(DataType,
194 transcript_add, // column 0
195 transcript_eq, // column 1
196 transcript_msm_transition, // column 2
197 transcript_Px, // column 3
198 transcript_Py, // column 4
199 transcript_z1, // column 5
200 transcript_z2, // column 6
201 transcript_z1zero, // column 7
202 transcript_z2zero, // column 8
203 transcript_op, // column 9
204 transcript_msm_x, // column 10
205 transcript_msm_y, // column 11
206 precompute_point_transition, // column 12
207 precompute_s1lo, // column 13
208 precompute_s2hi, // column 14
209 precompute_s2lo, // column 15
210 precompute_s3hi, // column 16
211 precompute_s3lo, // column 17
212 precompute_s4hi, // column 18
213 precompute_s4lo, // column 19
214 precompute_skew, // column 20
215 msm_size_of_msm, // column 21
216 msm_add2, // column 22
217 msm_add3, // column 23
218 msm_add4, // column 24
219 msm_x1, // column 25
220 msm_y1, // column 26
221 msm_x2, // column 27
222 msm_y2, // column 28
223 msm_x3, // column 29
224 msm_y3, // column 30
225 msm_x4, // column 31
226 msm_y4, // column 32
227 msm_collision_x1, // column 33
228 msm_collision_x2, // column 34
229 msm_collision_x3, // column 35
230 msm_collision_x4, // column 36
231 msm_lambda1, // column 37
232 msm_lambda2, // column 38
233 msm_lambda3, // column 39
234 msm_lambda4, // column 40
235 msm_slice1, // column 41
236 msm_slice2, // column 42
237 msm_slice3, // column 43
238 msm_slice4, // column 44
239 transcript_reset_accumulator, // column 45
240 lookup_read_counts_0, // column 46
241 lookup_read_counts_1, // column 47
242 transcript_base_infinity, // column 48
243 transcript_base_x_inverse, // column 49
244 transcript_base_y_inverse, // column 50
245 transcript_add_x_equal, // column 51
246 transcript_add_y_equal, // column 52
247 transcript_add_lambda, // column 53
248 transcript_msm_intermediate_x, // column 54
249 transcript_msm_intermediate_y, // column 55
250 transcript_msm_infinity, // column 56
251 transcript_msm_x_inverse, // column 57
252 transcript_msm_count_zero_at_transition, // column 58
253 transcript_msm_count_at_transition_inverse) // column 59
254 };
255
260 template <typename DataType> class MaskingEntities {
261 public:
262 DEFINE_FLAVOR_MEMBERS(DataType, gemini_masking_poly)
263 };
264
270 template <typename DataType> class WireToBeShiftedWithoutAccumulatorsEntities {
271 public:
272 DEFINE_FLAVOR_MEMBERS(DataType,
273 transcript_mul, // column 60
274 transcript_msm_count, // column 61
275 precompute_scalar_sum, // column 62
276 precompute_s1hi, // column 63
277 precompute_dx, // column 64
278 precompute_dy, // column 65
279 precompute_tx, // column 66
280 precompute_ty, // column 67
281 msm_transition, // column 68
282 msm_add, // column 69
283 msm_double, // column 70
284 msm_skew, // column 71
285 msm_accumulator_x, // column 72
286 msm_accumulator_y, // column 73
287 msm_count, // column 74
288 msm_round, // column 75
289 msm_add1, // column 76
290 msm_pc, // column 77
291 precompute_pc, // column 78
292 transcript_pc, // column 79
293 precompute_round, // column 80
294 precompute_select) // column 81
295 };
296
301 template <typename DataType> class WireToBeShiftedAccumulatorEntities {
302 public:
303 DEFINE_FLAVOR_MEMBERS(DataType,
304 transcript_accumulator_not_empty, // column 82
305 transcript_accumulator_x, // column 83
306 transcript_accumulator_y) // column 84
307 };
308
313 template <typename DataType>
338
342 template <typename DataType> class ShiftedEntities {
343 public:
345 transcript_mul_shift, // column 0
346 transcript_msm_count_shift, // column 1
347 precompute_scalar_sum_shift, // column 2
348 precompute_s1hi_shift, // column 3
349 precompute_dx_shift, // column 4
350 precompute_dy_shift, // column 5
351 precompute_tx_shift, // column 6
352 precompute_ty_shift, // column 7
353 msm_transition_shift, // column 8
354 msm_add_shift, // column 9
355 msm_double_shift, // column 10
356 msm_skew_shift, // column 11
357 msm_accumulator_x_shift, // column 12
358 msm_accumulator_y_shift, // column 13
359 msm_count_shift, // column 14
360 msm_round_shift, // column 15
361 msm_add1_shift, // column 16
362 msm_pc_shift, // column 17
363 precompute_pc_shift, // column 18
364 transcript_pc_shift, // column 19
365 precompute_round_shift, // column 20
366 precompute_select_shift, // column 21
367 transcript_accumulator_not_empty_shift, // column 22
368 transcript_accumulator_x_shift, // column 23
369 transcript_accumulator_y_shift, // column 24
370 z_perm_shift); // column 25
371 };
372
373 template <typename DataType, typename PrecomputedAndWitnessEntitiesSuperset>
374 static auto get_to_be_shifted(PrecomputedAndWitnessEntitiesSuperset& entities)
375 {
376 // NOTE: must match order of ShiftedEntities above!
377 return RefArray{ entities.transcript_mul, // column 0
378 entities.transcript_msm_count, // column 1
379 entities.precompute_scalar_sum, // column 2
380 entities.precompute_s1hi, // column 3
381 entities.precompute_dx, // column 4
382 entities.precompute_dy, // column 5
383 entities.precompute_tx, // column 6
384 entities.precompute_ty, // column 7
385 entities.msm_transition, // column 8
386 entities.msm_add, // column 9
387 entities.msm_double, // column 10
388 entities.msm_skew, // column 11
389 entities.msm_accumulator_x, // column 12
390 entities.msm_accumulator_y, // column 13
391 entities.msm_count, // column 14
392 entities.msm_round, // column 15
393 entities.msm_add1, // column 16
394 entities.msm_pc, // column 17
395 entities.precompute_pc, // column 18
396 entities.transcript_pc, // column 19
397 entities.precompute_round, // column 20
398 entities.precompute_select, // column 21
399 entities.transcript_accumulator_not_empty, // column 22
400 entities.transcript_accumulator_x, // column 23
401 entities.transcript_accumulator_y, // column 24
402 entities.z_perm }; // column 25
403 }
404
415 template <typename DataType>
416 class AllEntities : public MaskingEntities<DataType>,
417 public PrecomputedEntities<DataType>,
418 public WitnessEntities<DataType>,
419 public ShiftedEntities<DataType> {
420 public:
431 auto get_to_be_shifted() { return ECCVMFlavor::get_to_be_shifted<DataType>(*this); }
434 };
435
440 class AllValues : public AllEntities<FF> {
441 public:
443 using Base::Base;
444 };
445
450
455
459 class ProverPolynomials : public AllEntities<Polynomial> {
460 public:
461 // Define all operations as default, except copy construction/assignment
462 ProverPolynomials() = default;
465 ProverPolynomials(ProverPolynomials&& o) noexcept = default;
468 [[nodiscard]] size_t get_polynomial_size() const { return this->lagrange_first.size(); }
469
474 AllValues get_row(const size_t row_idx) const
475 {
476 AllValues result;
477 for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) {
478 result_field = polynomial[row_idx];
479 }
480 return result;
481 }
482 // Set all shifted polynomials based on their to-be-shifted counterpart
484 {
485 for (auto [shifted, to_be_shifted] : zip_view(get_shifted(), get_to_be_shifted())) {
486 shifted = to_be_shifted.shifted();
487 }
488 }
489
490#ifdef FUZZING
491 ProverPolynomials(const CircuitBuilder& builder, bool disable_fixed_dyadic_trace_size = false)
492#else
590#endif
591 {
592 // compute rows for the three different sections of the ECCVM execution trace
593 // Note: the first operation (index 0) is always a hiding op with random Px, Py values
594 const auto transcript_rows =
595 ECCVMTranscriptBuilder::compute_rows(builder.op_queue->get_eccvm_ops(), builder.get_number_of_muls());
596 const std::vector<MSM> msms = builder.get_msms();
597 const auto point_table_rows =
599 const auto result = ECCVMMSMMBuilder::compute_rows(
600 msms, builder.get_number_of_muls(), builder.op_queue->get_num_msm_rows());
601 const auto& msm_rows = std::get<0>(result);
602 const auto& point_table_read_counts = std::get<1>(result);
603
604 const size_t num_rows = std::max({ point_table_rows.size(), msm_rows.size(), transcript_rows.size() }) +
605 NUM_DISABLED_ROWS_IN_SUMCHECK;
606 vinfo("Num rows in the ECCVM: ", num_rows);
607 const auto log_num_rows = static_cast<size_t>(numeric::get_msb64(num_rows));
608 size_t dyadic_num_rows = 1UL << (log_num_rows + (1UL << log_num_rows == num_rows ? 0 : 1));
609 BB_ASSERT_LTE(dyadic_num_rows,
611 "The ECCVM circuit size has exceeded the fixed upper bound! Fixed size: " +
612 std::to_string(ECCVM_FIXED_SIZE) + " actual size: " + std::to_string(dyadic_num_rows));
613
614#ifdef FUZZING
615 // We don't want to spend all the time generating the full trace if we are just fuzzing eccvm.
616 if (disable_fixed_dyadic_trace_size) {
617 dyadic_num_rows = num_rows;
618 } else {
619 dyadic_num_rows = ECCVM_FIXED_SIZE;
620 }
621#else
622 dyadic_num_rows = ECCVM_FIXED_SIZE;
623#endif
624 size_t unmasked_witness_size = dyadic_num_rows - NUM_DISABLED_ROWS_IN_SUMCHECK;
625
626 for (auto& poly : get_to_be_shifted()) {
627 poly = Polynomial{ /*memory size*/ dyadic_num_rows - 1,
628 /*largest possible index*/ dyadic_num_rows,
629 /* offset */ 1 };
630 }
631 // allocate polynomials; define lagrange and lookup read count polynomials
632 for (auto& poly : get_all()) {
633 if (poly.is_empty()) {
634 poly = Polynomial(dyadic_num_rows);
635 }
636 }
637 lagrange_first.at(0) = 1;
638 lagrange_second.at(1) = 1;
639 lagrange_third.at(2) = 1;
640 lagrange_last.at(unmasked_witness_size - 1) = 1;
641 for (size_t i = 0; i < point_table_read_counts[0].size(); ++i) {
642 // Explanation of off-by-one offset:
643 // When computing the WNAF slice for a point at point counter value `pc` and a round index `round`, the
644 // row number that computes the slice can be derived. This row number is then mapped to the index of
645 // `lookup_read_counts`. We do this mapping in `ecc_msm_relation`. We are off-by-one because we add an
646 // empty row at the start of the WNAF columns that is not accounted for (index of lookup_read_counts
647 // maps to the row in our WNAF columns that computes a slice for a given value of pc and round)
648 lookup_read_counts_0.at(i + 1) = point_table_read_counts[0][i];
649 lookup_read_counts_1.at(i + 1) = point_table_read_counts[1][i];
650 }
651
652 // compute polynomials for transcript columns
653 parallel_for_range(transcript_rows.size(), [&](size_t start, size_t end) {
654 for (size_t i = start; i < end; i++) {
655 transcript_accumulator_not_empty.set_if_valid_index(i, transcript_rows[i].accumulator_not_empty);
656 transcript_add.set_if_valid_index(i, transcript_rows[i].q_add);
657 transcript_mul.set_if_valid_index(i, transcript_rows[i].q_mul);
658 transcript_eq.set_if_valid_index(i, transcript_rows[i].q_eq);
659 transcript_reset_accumulator.set_if_valid_index(i, transcript_rows[i].q_reset_accumulator);
660 transcript_msm_transition.set_if_valid_index(i, transcript_rows[i].msm_transition);
661 transcript_pc.set_if_valid_index(i, transcript_rows[i].pc);
662 transcript_msm_count.set_if_valid_index(i, transcript_rows[i].msm_count);
663 transcript_Px.set_if_valid_index(i, transcript_rows[i].base_x);
664 transcript_Py.set_if_valid_index(i, transcript_rows[i].base_y);
665 transcript_z1.set_if_valid_index(i, transcript_rows[i].z1);
666 transcript_z2.set_if_valid_index(i, transcript_rows[i].z2);
667 transcript_z1zero.set_if_valid_index(i, transcript_rows[i].z1_zero);
668 transcript_z2zero.set_if_valid_index(i, transcript_rows[i].z2_zero);
669 transcript_op.set_if_valid_index(i, transcript_rows[i].opcode);
670 transcript_accumulator_x.set_if_valid_index(i, transcript_rows[i].accumulator_x);
671 transcript_accumulator_y.set_if_valid_index(i, transcript_rows[i].accumulator_y);
672 transcript_msm_x.set_if_valid_index(i, transcript_rows[i].msm_output_x);
673 transcript_msm_y.set_if_valid_index(i, transcript_rows[i].msm_output_y);
674 transcript_base_infinity.set_if_valid_index(i, transcript_rows[i].base_infinity);
675 transcript_base_x_inverse.set_if_valid_index(i, transcript_rows[i].base_x_inverse);
676 transcript_base_y_inverse.set_if_valid_index(i, transcript_rows[i].base_y_inverse);
677 transcript_add_x_equal.set_if_valid_index(i, transcript_rows[i].transcript_add_x_equal);
678 transcript_add_y_equal.set_if_valid_index(i, transcript_rows[i].transcript_add_y_equal);
679 transcript_add_lambda.set_if_valid_index(i, transcript_rows[i].transcript_add_lambda);
680 transcript_msm_intermediate_x.set_if_valid_index(i,
681 transcript_rows[i].transcript_msm_intermediate_x);
682 transcript_msm_intermediate_y.set_if_valid_index(i,
683 transcript_rows[i].transcript_msm_intermediate_y);
684 transcript_msm_infinity.set_if_valid_index(i, transcript_rows[i].transcript_msm_infinity);
685 transcript_msm_x_inverse.set_if_valid_index(i, transcript_rows[i].transcript_msm_x_inverse);
686 transcript_msm_count_zero_at_transition.set_if_valid_index(
687 i, transcript_rows[i].msm_count_zero_at_transition);
688 transcript_msm_count_at_transition_inverse.set_if_valid_index(
689 i, transcript_rows[i].msm_count_at_transition_inverse);
690 }
691 });
692
693 parallel_for_range(point_table_rows.size(), [&](size_t start, size_t end) {
694 for (size_t i = start; i < end; i++) {
695 // first row is always an empty row (to accommodate shifted polynomials which must have 0 as 1st
696 // coefficient). All other rows in the point_table_rows represent active wnaf gates (i.e.
697 // precompute_select = 1)
698 precompute_select.set_if_valid_index(i, (i != 0) ? 1 : 0);
699 precompute_pc.set_if_valid_index(i, point_table_rows[i].pc);
700 precompute_point_transition.set_if_valid_index(
701 i, static_cast<uint64_t>(point_table_rows[i].point_transition));
702 precompute_round.set_if_valid_index(i, point_table_rows[i].round);
703 precompute_scalar_sum.set_if_valid_index(i, point_table_rows[i].scalar_sum);
704 precompute_s1hi.set_if_valid_index(i, point_table_rows[i].s1);
705 precompute_s1lo.set_if_valid_index(i, point_table_rows[i].s2);
706 precompute_s2hi.set_if_valid_index(i, point_table_rows[i].s3);
707 precompute_s2lo.set_if_valid_index(i, point_table_rows[i].s4);
708 precompute_s3hi.set_if_valid_index(i, point_table_rows[i].s5);
709 precompute_s3lo.set_if_valid_index(i, point_table_rows[i].s6);
710 precompute_s4hi.set_if_valid_index(i, point_table_rows[i].s7);
711 precompute_s4lo.set_if_valid_index(i, point_table_rows[i].s8);
712 // If skew is active (i.e. we need to subtract a base point from the msm result),
713 // write `7` into rows.precompute_skew. `7`, in binary representation, equals `-1` when converted
714 // into WNAF form
715 precompute_skew.set_if_valid_index(i, point_table_rows[i].skew ? 7 : 0);
716 precompute_dx.set_if_valid_index(i, point_table_rows[i].precompute_double.x);
717 precompute_dy.set_if_valid_index(i, point_table_rows[i].precompute_double.y);
718 precompute_tx.set_if_valid_index(i, point_table_rows[i].precompute_accumulator.x);
719 precompute_ty.set_if_valid_index(i, point_table_rows[i].precompute_accumulator.y);
720 }
721 });
722
723 // compute polynomials for the msm columns
724 parallel_for_range(msm_rows.size(), [&](size_t start, size_t end) {
725 for (size_t i = start; i < end; i++) {
726 msm_transition.set_if_valid_index(i, static_cast<int>(msm_rows[i].msm_transition));
727 msm_add.set_if_valid_index(i, static_cast<int>(msm_rows[i].q_add));
728 msm_double.set_if_valid_index(i, static_cast<int>(msm_rows[i].q_double));
729 msm_skew.set_if_valid_index(i, static_cast<int>(msm_rows[i].q_skew));
730 msm_accumulator_x.set_if_valid_index(i, msm_rows[i].accumulator_x);
731 msm_accumulator_y.set_if_valid_index(i, msm_rows[i].accumulator_y);
732 msm_pc.set_if_valid_index(i, msm_rows[i].pc);
733 msm_size_of_msm.set_if_valid_index(i, msm_rows[i].msm_size);
734 msm_count.set_if_valid_index(i, msm_rows[i].msm_count);
735 msm_round.set_if_valid_index(i, msm_rows[i].msm_round);
736 msm_add1.set_if_valid_index(i, static_cast<int>(msm_rows[i].add_state[0].add));
737 msm_add2.set_if_valid_index(i, static_cast<int>(msm_rows[i].add_state[1].add));
738 msm_add3.set_if_valid_index(i, static_cast<int>(msm_rows[i].add_state[2].add));
739 msm_add4.set_if_valid_index(i, static_cast<int>(msm_rows[i].add_state[3].add));
740 msm_x1.set_if_valid_index(i, msm_rows[i].add_state[0].point.x);
741 msm_y1.set_if_valid_index(i, msm_rows[i].add_state[0].point.y);
742 msm_x2.set_if_valid_index(i, msm_rows[i].add_state[1].point.x);
743 msm_y2.set_if_valid_index(i, msm_rows[i].add_state[1].point.y);
744 msm_x3.set_if_valid_index(i, msm_rows[i].add_state[2].point.x);
745 msm_y3.set_if_valid_index(i, msm_rows[i].add_state[2].point.y);
746 msm_x4.set_if_valid_index(i, msm_rows[i].add_state[3].point.x);
747 msm_y4.set_if_valid_index(i, msm_rows[i].add_state[3].point.y);
748 msm_collision_x1.set_if_valid_index(i, msm_rows[i].add_state[0].collision_inverse);
749 msm_collision_x2.set_if_valid_index(i, msm_rows[i].add_state[1].collision_inverse);
750 msm_collision_x3.set_if_valid_index(i, msm_rows[i].add_state[2].collision_inverse);
751 msm_collision_x4.set_if_valid_index(i, msm_rows[i].add_state[3].collision_inverse);
752 msm_lambda1.set_if_valid_index(i, msm_rows[i].add_state[0].lambda);
753 msm_lambda2.set_if_valid_index(i, msm_rows[i].add_state[1].lambda);
754 msm_lambda3.set_if_valid_index(i, msm_rows[i].add_state[2].lambda);
755 msm_lambda4.set_if_valid_index(i, msm_rows[i].add_state[3].lambda);
756 msm_slice1.set_if_valid_index(i, msm_rows[i].add_state[0].slice);
757 msm_slice2.set_if_valid_index(i, msm_rows[i].add_state[1].slice);
758 msm_slice3.set_if_valid_index(i, msm_rows[i].add_state[2].slice);
759 msm_slice4.set_if_valid_index(i, msm_rows[i].add_state[3].slice);
760 }
761 });
762 this->set_shifted();
763 }
764 };
765
771
777 public:
778 size_t circuit_size = ECCVM_FIXED_SIZE; // The circuit size is fixed for the ECCVM.
779 size_t log_circuit_size = CONST_ECCVM_LOG_N;
780
781 // Used to amortize the commitment time if the `fixed size` > `real_size`.
782 size_t real_size = 0;
783
784 ProverPolynomials polynomials; // storage for all polynomials evaluated by the prover
786
787 // Constructor for fixed size ProvingKey
789 : real_size(builder.get_circuit_subgroup_size(builder.get_estimated_num_finalized_gates()))
790 , polynomials(builder)
791 {}
792 };
793
799
806 class CommitmentLabels : public AllEntities<std::string> {
807 private:
809
810 public:
812 : AllEntities<std::string>()
813 {
814 Base::transcript_add = "TRANSCRIPT_ADD";
815 Base::transcript_mul = "TRANSCRIPT_MUL";
816 Base::transcript_eq = "TRANSCRIPT_EQ";
817 Base::transcript_msm_transition = "TRANSCRIPT_MSM_TRANSITION";
818 Base::transcript_pc = "TRANSCRIPT_PC";
819 Base::transcript_msm_count = "TRANSCRIPT_MSM_COUNT";
820 Base::transcript_Px = "TRANSCRIPT_PX";
821 Base::transcript_Py = "TRANSCRIPT_PY";
822 Base::transcript_z1 = "TRANSCRIPT_Z1";
823 Base::transcript_z2 = "TRANSCRIPT_Z2";
824 Base::transcript_z1zero = "TRANSCRIPT_Z1ZERO";
825 Base::transcript_z2zero = "TRANSCRIPT_Z2ZERO";
826 Base::transcript_op = "TRANSCRIPT_OP";
827 Base::transcript_accumulator_x = "TRANSCRIPT_ACCUMULATOR_X";
828 Base::transcript_accumulator_y = "TRANSCRIPT_ACCUMULATOR_Y";
829 Base::transcript_msm_x = "TRANSCRIPT_MSM_X";
830 Base::transcript_msm_y = "TRANSCRIPT_MSM_Y";
831 Base::precompute_pc = "PRECOMPUTE_PC";
832 Base::precompute_point_transition = "PRECOMPUTE_POINT_TRANSITION";
833 Base::precompute_round = "PRECOMPUTE_ROUND";
834 Base::precompute_scalar_sum = "PRECOMPUTE_SCALAR_SUM";
835 Base::precompute_s1hi = "PRECOMPUTE_S1HI";
836 Base::precompute_s1lo = "PRECOMPUTE_S1LO";
837 Base::precompute_s2hi = "PRECOMPUTE_S2HI";
838 Base::precompute_s2lo = "PRECOMPUTE_S2LO";
839 Base::precompute_s3hi = "PRECOMPUTE_S3HI";
840 Base::precompute_s3lo = "PRECOMPUTE_S3LO";
841 Base::precompute_s4hi = "PRECOMPUTE_S4HI";
842 Base::precompute_s4lo = "PRECOMPUTE_S4LO";
843 Base::precompute_skew = "PRECOMPUTE_SKEW";
844 Base::precompute_dx = "PRECOMPUTE_DX";
845 Base::precompute_dy = "PRECOMPUTE_DY";
846 Base::precompute_tx = "PRECOMPUTE_TX";
847 Base::precompute_ty = "PRECOMPUTE_TY";
848 Base::msm_transition = "MSM_TRANSITION";
849 Base::msm_add = "MSM_ADD";
850 Base::msm_double = "MSM_DOUBLE";
851 Base::msm_skew = "MSM_SKEW";
852 Base::msm_accumulator_x = "MSM_ACCUMULATOR_X";
853 Base::msm_accumulator_y = "MSM_ACCUMULATOR_Y";
854 Base::msm_pc = "MSM_PC";
855 Base::msm_size_of_msm = "MSM_SIZE_OF_MSM";
856 Base::msm_count = "MSM_COUNT";
857 Base::msm_round = "MSM_ROUND";
858 Base::msm_add1 = "MSM_ADD1";
859 Base::msm_add2 = "MSM_ADD2";
860 Base::msm_add3 = "MSM_ADD3";
861 Base::msm_add4 = "MSM_ADD4";
862 Base::msm_x1 = "MSM_X1";
863 Base::msm_y1 = "MSM_Y1";
864 Base::msm_x2 = "MSM_X2";
865 Base::msm_y2 = "MSM_Y2";
866 Base::msm_x3 = "MSM_X3";
867 Base::msm_y3 = "MSM_Y3";
868 Base::msm_x4 = "MSM_X4";
869 Base::msm_y4 = "MSM_Y4";
870 Base::msm_collision_x1 = "MSM_COLLISION_X1";
871 Base::msm_collision_x2 = "MSM_COLLISION_X2";
872 Base::msm_collision_x3 = "MSM_COLLISION_X3";
873 Base::msm_collision_x4 = "MSM_COLLISION_X4";
874 Base::msm_lambda1 = "MSM_LAMBDA1";
875 Base::msm_lambda2 = "MSM_LAMBDA2";
876 Base::msm_lambda3 = "MSM_LAMBDA3";
877 Base::msm_lambda4 = "MSM_LAMBDA4";
878 Base::msm_slice1 = "MSM_SLICE1";
879 Base::msm_slice2 = "MSM_SLICE2";
880 Base::msm_slice3 = "MSM_SLICE3";
881 Base::msm_slice4 = "MSM_SLICE4";
882 Base::transcript_accumulator_not_empty = "TRANSCRIPT_ACCUMULATOR_NOT_EMPTY";
883 Base::transcript_reset_accumulator = "TRANSCRIPT_RESET_ACCUMULATOR";
884 Base::precompute_select = "PRECOMPUTE_SELECT";
885 Base::lookup_read_counts_0 = "LOOKUP_READ_COUNTS_0";
886 Base::lookup_read_counts_1 = "LOOKUP_READ_COUNTS_1";
887 Base::transcript_base_infinity = "TRANSCRIPT_BASE_INFINITY";
888 Base::transcript_base_x_inverse = "TRANSCRIPT_BASE_X_INVERSE";
889 Base::transcript_base_y_inverse = "TRANSCRIPT_BASE_Y_INVERSE";
890 Base::transcript_add_x_equal = "TRANSCRIPT_ADD_X_EQUAL";
891 Base::transcript_add_y_equal = "TRANSCRIPT_ADD_Y_EQUAL";
892 Base::transcript_add_lambda = "TRANSCRIPT_ADD_LAMBDA";
893 Base::transcript_msm_intermediate_x = "TRANSCRIPT_MSM_INTERMEDIATE_X";
894 Base::transcript_msm_intermediate_y = "TRANSCRIPT_MSM_INTERMEDIATE_Y";
895 Base::transcript_msm_infinity = "TRANSCRIPT_MSM_INFINITY";
896 Base::transcript_msm_x_inverse = "TRANSCRIPT_MSM_X_INVERSE";
897 Base::transcript_msm_count_zero_at_transition = "TRANSCRIPT_MSM_COUNT_ZERO_AT_TRANSITION";
898 Base::transcript_msm_count_at_transition_inverse = "TRANSCRIPT_MSM_COUNT_AT_TRANSITION_INVERSE";
899 Base::z_perm = "Z_PERM";
900 Base::z_perm_shift = "Z_PERM_SHIFT";
901 Base::lookup_inverses = "LOOKUP_INVERSES";
902 // The ones beginning with "__" are only used for debugging
903 Base::lagrange_first = "__LAGRANGE_FIRST";
904 Base::lagrange_second = "__LAGRANGE_SECOND";
905 Base::lagrange_third = "__LAGRANGE_THIRD";
906 Base::lagrange_last = "__LAGRANGE_LAST";
907 };
908 };
909
910 template <typename Commitment, typename VerificationKey>
911 class VerifierCommitments_ : public AllEntities<Commitment> {
912 public:
913 VerifierCommitments_(const std::shared_ptr<VerificationKey>& verification_key)
914 {
915 this->lagrange_first = verification_key->lagrange_first;
916 this->lagrange_second = verification_key->lagrange_second;
917 this->lagrange_third = verification_key->lagrange_third;
918 this->lagrange_last = verification_key->lagrange_last;
919 }
920 };
921
923
929 public:
931 std::vector<Commitment> ipa_l_comms;
932 std::vector<Commitment> ipa_r_comms;
935
936 IPATranscript() = default;
937
939 {
940 // take current proof and put them into the struct
941 size_t num_frs_read = 0;
942 ipa_poly_degree = NativeTranscript::template deserialize_from_buffer<uint32_t>(NativeTranscript::proof_data,
943 num_frs_read);
944
945 for (size_t i = 0; i < CONST_ECCVM_LOG_N; ++i) {
946 ipa_l_comms.emplace_back(NativeTranscript::template deserialize_from_buffer<Commitment>(
947 NativeTranscript::proof_data, num_frs_read));
948 ipa_r_comms.emplace_back(NativeTranscript::template deserialize_from_buffer<Commitment>(
949 NativeTranscript::proof_data, num_frs_read));
950 }
951 ipa_G_0_eval = NativeTranscript::template deserialize_from_buffer<Commitment>(NativeTranscript::proof_data,
952 num_frs_read);
953 ipa_a_0_eval =
954 NativeTranscript::template deserialize_from_buffer<FF>(NativeTranscript::proof_data, num_frs_read);
955 }
956
958 {
959 size_t old_proof_length = NativeTranscript::proof_data.size();
960 NativeTranscript::proof_data.clear();
961
962 NativeTranscript::serialize_to_buffer(ipa_poly_degree, NativeTranscript::proof_data);
963 for (size_t i = 0; i < CONST_ECCVM_LOG_N; ++i) {
964 NativeTranscript::serialize_to_buffer(ipa_l_comms[i], NativeTranscript::proof_data);
965 NativeTranscript::serialize_to_buffer(ipa_r_comms[i], NativeTranscript::proof_data);
966 }
967
968 serialize_to_buffer(ipa_G_0_eval, proof_data);
969 serialize_to_buffer(ipa_a_0_eval, proof_data);
970
971 BB_ASSERT_EQ(NativeTranscript::proof_data.size(), old_proof_length);
972 }
973 };
974
985 template <typename ProverPolynomialsOrPartiallyEvaluatedMultivariates, typename EdgeType>
986 static bool skip_entire_row([[maybe_unused]] const ProverPolynomialsOrPartiallyEvaluatedMultivariates& polynomials,
987 [[maybe_unused]] const EdgeType edge_idx)
988 {
989 // SKIP CONDITIONS:
990 // The most important skip condition is that `z_perm == z_perm_shift`. This implies that none of the wire values
991 // for the present input are involved in non-trivial copy constraints. Edge cases where nonzero rows do not
992 // contribute to permutation:
993 //
994 // 1: If `lagrange_last != 0`, the permutation polynomial identity is updated even if
995 // z_perm == z_perm_shift. Therefore, we must force it to be zero.
996 //
997 // 2: The final MSM row won't add to the permutation but still has polynomial identitiy
998 // contributions. This is because the permutation argument uses the SHIFTED msm columns when performing
999 // lookups i.e. `msm_accumulator_x[last_edge_idx]` will change `z_perm[last_edge_idx - 1]` and
1000 // `z_perm_shift[last_edge_idx - 1]`
1001 //
1002 // 3. The value of `transcript_mul` is non-zero at the end of an MSM of points-at-infinity, which will
1003 // cause `full_msm_count` to be non-zero while `transcript_msm_count` vanishes. We therefore force
1004 // transcript_mul == 0 as a skip-row condition.
1005 //
1006 // 4: We also force that `transcript_op==0`.
1007 return (polynomials.z_perm[edge_idx] == polynomials.z_perm_shift[edge_idx]) &&
1008 (polynomials.z_perm[edge_idx + 1] == polynomials.z_perm_shift[edge_idx + 1]) &&
1009 (polynomials.lagrange_last[edge_idx] == 0 && polynomials.lagrange_last[edge_idx + 1]) == 0 &&
1010 (polynomials.msm_transition[edge_idx] == 0 && polynomials.msm_transition[edge_idx + 1] == 0) &&
1011 (polynomials.transcript_mul[edge_idx] == 0 && polynomials.transcript_mul[edge_idx + 1] == 0) &&
1012 (polynomials.transcript_op[edge_idx] == 0 && polynomials.transcript_op[edge_idx + 1] == 0);
1013 }
1014};
1015} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
static std::vector< ScalarMul > get_flattened_scalar_muls(const std::vector< MSM > &msms)
A base class labelling all entities (for instance, all of the polynomials used by the prover during s...
DEFINE_COMPOUND_GET_ALL(MaskingEntities< DataType >, PrecomputedEntities< DataType >, WitnessEntities< DataType >, ShiftedEntities< DataType >) auto get_unshifted()
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
A container for commitment labels.
Derived class that defines proof structure for ECCVM IPA proof, as well as supporting functions.
std::vector< Commitment > ipa_r_comms
std::vector< Commitment > ipa_l_comms
Container for ZK entities (gemini masking polynomial for ZK-PCS)
A base class labelling precomputed entities and (ordered) subsets of interest.
bool operator==(const PrecomputedEntities &other) const =default
DEFINE_FLAVOR_MEMBERS(DataType, lagrange_first, lagrange_second, lagrange_third, lagrange_last)
A container for the prover polynomials.
AllValues get_row(const size_t row_idx) const
Returns the evaluations of all prover polynomials at one point on the boolean hypercube,...
ProverPolynomials(const ProverPolynomials &o)=delete
ProverPolynomials(ProverPolynomials &&o) noexcept=default
ProverPolynomials(const CircuitBuilder &builder)
Compute the ECCVM flavor polynomial data required to generate an ECCVM Proof.
ProverPolynomials & operator=(const ProverPolynomials &)=delete
ProverPolynomials & operator=(ProverPolynomials &&o) noexcept=default
The proving key is responsible for storing the polynomials used by the prover.
ProverPolynomials polynomials
ProvingKey(const CircuitBuilder &builder)
Represents polynomials shifted by 1 or their evaluations, defined relative to WitnessEntities.
DEFINE_FLAVOR_MEMBERS(DataType, transcript_mul_shift, transcript_msm_count_shift, precompute_scalar_sum_shift, precompute_s1hi_shift, precompute_dx_shift, precompute_dy_shift, precompute_tx_shift, precompute_ty_shift, msm_transition_shift, msm_add_shift, msm_double_shift, msm_skew_shift, msm_accumulator_x_shift, msm_accumulator_y_shift, msm_count_shift, msm_round_shift, msm_add1_shift, msm_pc_shift, precompute_pc_shift, transcript_pc_shift, precompute_round_shift, precompute_select_shift, transcript_accumulator_not_empty_shift, transcript_accumulator_x_shift, transcript_accumulator_y_shift, z_perm_shift)
VerifierCommitments_(const std::shared_ptr< VerificationKey > &verification_key)
Containter for transcript accumulators, they stand out as the only to-be-shifted wires that are alway...
Container for all to-be-shifted witness polynomials excluding the accumulators used/constructed by th...
Container for all witness polynomials used/constructed by the prover.
DEFINE_COMPOUND_GET_ALL(WireNonShiftedEntities< DataType >, WireToBeShiftedWithoutAccumulatorsEntities< DataType >, WireToBeShiftedAccumulatorEntities< DataType >, DerivedWitnessEntities< DataType >) auto get_wires()
static constexpr size_t ECCVM_FIXED_SIZE
static constexpr bool HasZK
typename Curve::ScalarField FF
static constexpr size_t NUM_MASKING_POLYNOMIALS
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
static auto get_to_be_shifted(PrecomputedAndWitnessEntitiesSuperset &entities)
std::tuple< ECCVMTranscriptRelation< FF >, ECCVMPointTableRelation< FF >, ECCVMWnafRelation< FF >, ECCVMMSMRelation< FF >, ECCVMSetRelation< FF >, ECCVMLookupRelation< FF >, ECCVMBoolsRelation< FF > > Relations_
typename G1::affine_element Commitment
typename Curve::BaseField BF
bb::Polynomial< FF > Polynomial
static bool skip_entire_row(const ProverPolynomialsOrPartiallyEvaluatedMultivariates &polynomials, const EdgeType edge_idx)
When evaluating the sumcheck protocol - can we skip evaluation of all relations for a given row?...
typename G1::element GroupElement
std::tuple< ECCVMSetRelation< FF > > GrandProductRelations
typename Curve::Group G1
static constexpr bool USE_SHORT_MONOMIALS
static constexpr size_t NUM_WITNESS_ENTITIES
static constexpr size_t NUM_TRANSLATION_OPENING_CLAIMS
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
static constexpr size_t NUM_WIRES
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t num_frs_comm
static constexpr bool USE_PADDING
static constexpr size_t num_frs_fq
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
static constexpr size_t NUM_RELATIONS
Relations_< FF > Relations
bb::eccvm::MSM< CycleGroup > MSM
static constexpr size_t NUM_DERIVED_WITNESS_ENTITIES_NON_SHIFTED
std::array< FF, NUM_SUBRELATIONS - 1 > SubrelationSeparators
Stores the fixed ECCVM VK commitments (to precomputed polynomials) that depend only on the circuit si...
static std::tuple< std::vector< MSMRow >, std::array< std::vector< size_t >, 2 > > compute_rows(const std::vector< MSM > &msms, const uint32_t total_number_of_muls, const size_t num_msm_rows)
Computes the row values for the Straus MSM columns of the ECCVM.
static std::vector< PointTablePrecomputationRow > compute_rows(const std::vector< bb::eccvm::ScalarMul< CycleGroup > > &ecc_muls)
static std::vector< TranscriptRow > compute_rows(const std::vector< ECCVMOperation > &vm_operations, const uint32_t total_number_of_muls)
Computes the ECCVM transcript rows.
Simple verification key class for fixed-size circuits (ECCVM, Translator).
Definition flavor.hpp:136
A container for storing the partially evaluated multivariates produced by sumcheck.
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 grumpkin::g1 Group
Definition grumpkin.hpp:61
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:36
#define vinfo(...)
Definition log.hpp:94
AluTraceBuilder builder
Definition alu.test.cpp:124
typename ECCVMFlavor::ProverPolynomials ProverPolynomials
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 ...
std::vector< ScalarMul< CycleGroup > > MSM
constexpr uint64_t get_msb64(const uint64_t in)
Definition get_msb.hpp:30
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
group< fq, fr, Bn254G1Params > g1
Definition g1.hpp:33
std::vector< fr > HonkProof
Definition proof.hpp:15
RefArray< T,(Ns+...)> constexpr concatenate(const RefArray< T, Ns > &... ref_arrays)
Concatenates multiple RefArray objects into a single RefArray.
void parallel_for_range(size_t num_points, const std::function< void(size_t, size_t)> &func, size_t no_multhreading_if_less_or_equal)
Split a loop into several loops running in parallel.
Definition thread.cpp:141
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
Container for all derived witness polynomials used/constructed by the prover.
DEFINE_FLAVOR_MEMBERS(DataType, z_perm, lookup_inverses)