Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
protogalaxy_verifier.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
12
13namespace bb {
14
15template <class DeciderVerificationKeys>
17 const std::vector<FF>& proof)
18{
19 transcript->load_proof(proof);
20 auto key = keys_to_fold[0];
21 auto domain_separator = std::to_string(0);
22 if (!key->is_complete) {
23 OinkVerifier<Flavor> oink_verifier{ key, transcript, domain_separator + '_' };
24 oink_verifier.verify();
25 key->target_sum = 0;
26 // Get the gate challenges for sumcheck/combiner computation
27 key->gate_challenges =
28 transcript->template get_powers_of_challenge<FF>(domain_separator + "_gate_challenge", CONST_PG_LOG_N);
29 }
30
31 key = keys_to_fold[1];
32 domain_separator = std::to_string(1);
33 OinkVerifier<Flavor> oink_verifier{ key, transcript, domain_separator + '_' };
34 oink_verifier.verify();
35}
36
37template <typename FF, size_t NUM>
39{
40 static_assert(NUM < 5);
41 static constexpr FF inverse_two = FF(2).invert();
42
43 std::vector<FF> lagranges(NUM);
44 FF vanishing_polynomial_at_challenge;
45 if constexpr (NUM == 2) {
46 vanishing_polynomial_at_challenge = combiner_challenge * (combiner_challenge - FF(1));
47 lagranges = { FF(1) - combiner_challenge, combiner_challenge };
48 } else if constexpr (NUM == 3) {
49 vanishing_polynomial_at_challenge =
50 combiner_challenge * (combiner_challenge - FF(1)) * (combiner_challenge - FF(2));
51 lagranges = { (FF(1) - combiner_challenge) * (FF(2) - combiner_challenge) * inverse_two,
52 combiner_challenge * (FF(2) - combiner_challenge),
53 combiner_challenge * (combiner_challenge - FF(1)) * inverse_two };
54 } else if constexpr (NUM == 4) {
55 static constexpr FF inverse_six = FF(6).invert();
56 vanishing_polynomial_at_challenge = combiner_challenge * (combiner_challenge - FF(1)) *
57 (combiner_challenge - FF(2)) * (combiner_challenge - FF(3));
58 lagranges = { (FF(1) - combiner_challenge) * (FF(2) - combiner_challenge) * (FF(3) - combiner_challenge) *
59 inverse_six,
60 combiner_challenge * (FF(2) - combiner_challenge) * (FF(3) - combiner_challenge) * inverse_two,
61 combiner_challenge * (combiner_challenge - FF(1)) * (FF(3) - combiner_challenge) * inverse_two,
62 combiner_challenge * (combiner_challenge - FF(1)) * (combiner_challenge - FF(2)) * inverse_six };
63 }
64 return std::make_tuple(vanishing_polynomial_at_challenge, lagranges);
65}
66
67template <class DeciderVerificationKeys>
69 DeciderVerificationKeys>::verify_folding_proof(const std::vector<FF>& proof)
70{
71 static constexpr size_t BATCHED_EXTENDED_LENGTH = DeciderVerificationKeys::BATCHED_EXTENDED_LENGTH;
72 static constexpr size_t NUM_KEYS = DeciderVerificationKeys::NUM;
73 // The degree of the combiner quotient (K in the paper) is dk - k - 1 = k(d - 1) - 1.
74 // Hence we need k(d - 1) evaluations to represent it.
75 static constexpr size_t COMBINER_LENGTH = BATCHED_EXTENDED_LENGTH - NUM_KEYS;
76
77 const std::shared_ptr<DeciderVK>& accumulator = keys_to_fold[0];
78
79 run_oink_verifier_on_each_incomplete_key(proof);
80
81 // Perturbator round
82 const std::vector<FF> deltas = transcript->template get_powers_of_challenge<FF>("delta", CONST_PG_LOG_N);
83
84 std::vector<FF> perturbator_coeffs(CONST_PG_LOG_N + 1, 0);
85 for (size_t idx = 1; idx <= CONST_PG_LOG_N; idx++) {
86 perturbator_coeffs[idx] = transcript->template receive_from_prover<FF>("perturbator_" + std::to_string(idx));
87 }
88 const FF perturbator_challenge = transcript->template get_challenge<FF>("perturbator_challenge");
89
90 // Combiner quotient round
91 perturbator_coeffs[0] = accumulator->target_sum;
92 const Polynomial<FF> perturbator(perturbator_coeffs);
93 const FF perturbator_evaluation = perturbator.evaluate(perturbator_challenge);
94
95 std::array<FF, COMBINER_LENGTH> combiner_quotient_evals;
96 for (size_t idx = DeciderVerificationKeys::NUM; auto& val : combiner_quotient_evals) {
97 val = transcript->template receive_from_prover<FF>("combiner_quotient_" + std::to_string(idx++));
98 }
99
100 // Folding
101 const FF combiner_challenge = transcript->template get_challenge<FF>("combiner_quotient_challenge");
102 const Univariate<FF, BATCHED_EXTENDED_LENGTH, NUM_KEYS> combiner_quotient(combiner_quotient_evals);
103 const FF combiner_quotient_evaluation = combiner_quotient.evaluate(combiner_challenge);
104
105 // Set a constant virtual log circuit size in the accumulator
106 const size_t accumulator_log_circuit_size = CONST_PG_LOG_N;
107 accumulator->vk->log_circuit_size = accumulator_log_circuit_size;
108
109 // Compute next folding parameters
110 const auto [vanishing_polynomial_at_challenge, lagranges] =
111 compute_vanishing_polynomial_and_lagrange_evaluations<FF, NUM_KEYS>(combiner_challenge);
112 accumulator->target_sum =
113 perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_evaluation;
114 accumulator->gate_challenges = // note: known already in previous round
115 update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas);
116
117 // // Fold the commitments
118 for (auto [combination, to_combine] :
119 zip_view(accumulator->vk->get_all(), keys_to_fold.get_precomputed_commitments())) {
120 combination = batch_mul_native(to_combine, lagranges);
121 }
122 for (auto [combination, to_combine] :
123 zip_view(accumulator->witness_commitments.get_all(), keys_to_fold.get_witness_commitments())) {
124 combination = batch_mul_native(to_combine, lagranges);
125 }
126
127 // Fold the relation parameters
128 for (auto [combination, to_combine] : zip_view(accumulator->alphas, keys_to_fold.get_alphas())) {
129 combination = linear_combination(to_combine, lagranges);
130 }
131 for (auto [combination, to_combine] :
132 zip_view(accumulator->relation_parameters.get_to_fold(), keys_to_fold.get_relation_parameters())) {
133 combination = linear_combination(to_combine, lagranges);
134 }
135
136 return accumulator;
137}
138
140
141} // namespace bb
Verifier class for all the presumcheck rounds, which are shared between the folding verifier and ultr...
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Fr evaluate(const Fr &z, size_t target_size) const
void run_oink_verifier_on_each_incomplete_key(const std::vector< FF > &)
Instatiate the vks and the transcript.
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
Fr evaluate(const Fr &u) const
Evaluate a univariate at a point u not known at compile time and assumed not to be in the domain (els...
constexpr size_t NUM_KEYS
Entry point for Barretenberg command-line interface.
std::tuple< FF, std::vector< FF > > compute_vanishing_polynomial_and_lagrange_evaluations(const FF &combiner_challenge)
typename Flavor::FF FF
std::vector< FF > update_gate_challenges(const FF &perturbator_challenge, const std::vector< FF > &gate_challenges, const std::vector< FF > &init_challenges)
Compute the gate challenges used in the combiner calculation.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
constexpr field invert() const noexcept