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