Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
merge_verifier.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: d1307bdee7f2ee0e737c19b77a26204a8dbafafc}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#include "merge_verifier.hpp"
13
14namespace bb {
15
16template <typename Curve>
17bool MergeVerifier_<Curve>::check_concatenation_identities(std::vector<FF>& evals, const FF& pow_kappa) const
18{
19 bool concatenation_verified = true;
20 FF concatenation_diff(0);
21 for (size_t idx = 0; idx < NUM_WIRES; idx++) {
22 concatenation_diff = evals[idx] + (pow_kappa * evals[idx + NUM_WIRES]) - evals[idx + (2 * NUM_WIRES)];
23 if constexpr (IsRecursive) {
24 concatenation_verified &= concatenation_diff.get_value() == 0;
25 concatenation_diff.assert_equal(FF(0),
26 "assert_equal: merge concatenation identity failed in Merge Verifier");
27 } else {
28 concatenation_verified &= concatenation_diff == 0;
29 }
30 }
31 return concatenation_verified;
32}
33
34template <typename Curve>
36 const FF& pow_kappa_minus_one,
37 const std::vector<FF>& degree_check_challenges) const
38{
39 bool degree_check_verified = true;
40 FF degree_check_diff(0);
41 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
42 degree_check_diff += evals[idx] * degree_check_challenges[idx];
43 }
44 degree_check_diff -= evals.back() * pow_kappa_minus_one;
45 if constexpr (IsRecursive) {
46 degree_check_verified &= degree_check_diff.get_value() == 0;
47 degree_check_diff.assert_equal(FF(0), "assert_equal: merge degree identity failed in Merge Verifier");
48 } else {
49 degree_check_verified &= degree_check_diff == 0;
50 }
51
52 return degree_check_verified;
53}
54
55template <typename Curve>
57 const std::vector<Commitment>& table_commitments,
58 const Commitment& shplonk_batched_quotient,
59 const FF& shplonk_opening_challenge,
60 const std::vector<FF>& shplonk_batching_challenges,
61 const FF& kappa,
62 const FF& kappa_inv,
63 const std::vector<FF>& evals) const
64{
65 // Claim {Q', (z, 0)} where Q' = -Q·(z - κ) + Σᵢ βᵢLᵢ + Σᵢ βᵢRᵢ + Σᵢ βᵢMᵢ + (z - κ)/(z - κ⁻¹)·βG
66 // - Σᵢ βᵢlᵢ - Σᵢ βᵢrᵢ - Σᵢ βᵢmᵢ - (z - κ)/(z - κ⁻¹)·β·g
67 BatchOpeningClaim<Curve> batch_opening_claim;
68
69 // Commitment: [L_1], [L_2], ..., [L_n], [R_1], ..., [R_n], [M_1], ..., [M_n], [G], [1]
70 batch_opening_claim.commitments = { std::move(shplonk_batched_quotient) };
71 for (auto& commitment : table_commitments) {
72 batch_opening_claim.commitments.emplace_back(std::move(commitment));
73 }
74 if constexpr (IsRecursive) {
75 batch_opening_claim.commitments.emplace_back(Commitment::one(kappa.get_context()));
76 } else {
77 batch_opening_claim.commitments.emplace_back(Commitment::one());
78 }
79
80 // Scalars: -(z - κ), β₁...β₁₂, β₁₃·(z - κ)/(z - κ⁻¹), -(Σᵢ βᵢlᵢ + Σᵢ βᵢrᵢ + Σᵢ βᵢmᵢ + β₁₃·(z - κ)/(z - κ⁻¹)·g)
81 batch_opening_claim.scalars = { -(shplonk_opening_challenge - kappa) };
82 for (auto& scalar : shplonk_batching_challenges) {
83 batch_opening_claim.scalars.emplace_back(std::move(scalar));
84 }
85 batch_opening_claim.scalars.back() *=
86 (shplonk_opening_challenge - kappa) * (shplonk_opening_challenge - kappa_inv).invert();
87
88 batch_opening_claim.scalars.emplace_back(FF(0));
89 for (size_t idx = 0; idx < evals.size(); idx++) {
90 if (idx < evals.size() - 1) {
91 batch_opening_claim.scalars.back() -= evals[idx] * shplonk_batching_challenges[idx];
92 } else {
93 batch_opening_claim.scalars.back() -= shplonk_batching_challenges.back() * evals.back() *
94 (shplonk_opening_challenge - kappa) *
95 (shplonk_opening_challenge - kappa_inv).invert();
96 }
97 }
98
99 batch_opening_claim.evaluation_point = { shplonk_opening_challenge };
100
101 return batch_opening_claim;
102}
103
114template <typename Curve>
116 const Proof& proof, const InputCommitments& input_commitments)
117{
118 BB_BENCH_NAME("MergeVerifier::reduce");
119 transcript->load_proof(proof);
120
121 // Receive shift size from prover
122 // For native: shift_size is uint32_t
123 // For stdlib: shift_size is FF (we'll get the value later)
124 const FF shift_size = transcript->template receive_from_prover<FF>("shift_size");
125 ;
126 if constexpr (IsRecursive) {
127 BB_ASSERT_GT(uint32_t(shift_size.get_value()), 0U, "Shift size should always be bigger than 0");
128 } else {
129
130 BB_ASSERT_GT(shift_size, 0U, "Shift size should always be bigger than 0");
131 }
132
133 // Store T_commitments of the verifier
134 TableCommitments merged_table_commitments;
135
136 // Vector of commitments
137 // The vector is composed of: [L_1], .., [L_4], [R_1], .., [R_4], [M_1], .., [M_4], [G]
138 std::vector<Commitment> table_commitments;
139 table_commitments.reserve((3 * NUM_WIRES) + 1);
140 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
141 table_commitments.emplace_back(settings == MergeSettings::PREPEND ? input_commitments.t_commitments[idx]
142 : input_commitments.T_prev_commitments[idx]);
143 }
144 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
145 table_commitments.emplace_back(settings == MergeSettings::PREPEND ? input_commitments.T_prev_commitments[idx]
146 : input_commitments.t_commitments[idx]);
147 }
148 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
149 table_commitments.emplace_back(
150 transcript->template receive_from_prover<Commitment>("MERGED_TABLE_" + std::to_string(idx)));
151 merged_table_commitments[idx] = table_commitments.back();
152 }
153
154 // Generate degree check batching challenges
155 std::vector<FF> degree_check_challenges = transcript->template get_challenges<FF>(labels_degree_check);
156
157 // Receive commitment to reversed batched left table
158 table_commitments.emplace_back(
159 transcript->template receive_from_prover<Commitment>("REVERSED_BATCHED_LEFT_TABLES"));
160
161 // Compute batching challenges
162 std::vector<FF> shplonk_batching_challenges =
163 transcript->template get_challenges<FF>(labels_shplonk_batching_challenges);
164
165 // Evaluation challenge
166 const FF kappa = transcript->template get_challenge<FF>("kappa");
167 const FF kappa_inv = kappa.invert();
168 const FF pow_kappa = kappa.pow(shift_size);
169 const FF pow_kappa_minus_one = pow_kappa * kappa_inv;
170
171 // Receive evaluations of [Lᵢ], [Rᵢ], [Mᵢ] at κ
172 std::vector<FF> evals;
173 evals.reserve((3 * NUM_WIRES) + 1);
174 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
175 evals.emplace_back(transcript->template receive_from_prover<FF>("LEFT_TABLE_EVAL_" + std::to_string(idx)));
176 }
177 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
178 evals.emplace_back(transcript->template receive_from_prover<FF>("RIGHT_TABLE_EVAL_" + std::to_string(idx)));
179 }
180 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
181 evals.emplace_back(transcript->template receive_from_prover<FF>("MERGED_TABLE_EVAL_" + std::to_string(idx)));
182 }
183
184 // Receive evaluation of G at 1/κ
185 evals.emplace_back(transcript->template receive_from_prover<FF>("REVERSED_BATCHED_LEFT_TABLES_EVAL"));
186
187 // OriginTag false positive: The evaluations are PCS-bound - once the table commitments
188 // are fixed and kappa is derived, the correct evaluations are uniquely determined. Tag them
189 // with kappa to reflect this constraint. The last eval (G at 1/κ) is bound by degree_check_challenges.
190 if constexpr (IsRecursive) {
191 for (auto& eval : evals) {
192 eval.set_origin_tag(kappa.get_origin_tag());
193 }
194 evals.back().set_origin_tag(degree_check_challenges.back().get_origin_tag());
195 }
196
197 // Check concatenation identities
198 bool concatenation_verified = check_concatenation_identities(evals, pow_kappa);
199
200 // Check degree identity
201 bool degree_check_verified = check_degree_identity(evals, pow_kappa_minus_one, degree_check_challenges);
202
203 // Receive Shplonk batched quotient
204 Commitment shplonk_batched_quotient =
205 transcript->template receive_from_prover<Commitment>("SHPLONK_BATCHED_QUOTIENT");
206
207 // Generate Shplonk opening challenge
208 FF shplonk_opening_challenge = transcript->template get_challenge<FF>("shplonk_opening_challenge");
209
210 // Prepare batched opening claim to be passed to KZG
211 BatchOpeningClaim<Curve> batch_opening_claim = compute_shplonk_opening_claim(table_commitments,
212 shplonk_batched_quotient,
213 shplonk_opening_challenge,
214 shplonk_batching_challenges,
215 kappa,
216 kappa_inv,
217 evals);
218
219 BB_ASSERT(batch_opening_claim.commitments.size() == MERGE_BATCHED_CLAIM_SIZE);
220 BB_ASSERT(batch_opening_claim.scalars.size() == MERGE_BATCHED_CLAIM_SIZE);
221
222 // KZG verifier - returns PairingPoints directly
223 PairingPoints pairing_points = PCS::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), transcript);
224
225 vinfo("Merge Verifier: degree check passed: ", degree_check_verified ? "true" : "false");
226 vinfo("Merge Verifier: concatenation check passed: ", concatenation_verified ? "true" : "false");
227
228 return { pairing_points, merged_table_commitments, degree_check_verified && concatenation_verified };
229}
230
231// Explicit template instantiations
232template class MergeVerifier_<curve::BN254>;
235
236} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_GT(left, right,...)
Definition assert.hpp:113
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:225
Unified verifier class for the Goblin ECC op queue transcript merge protocol.
typename Curve::AffineElement Commitment
typename Curve::ScalarField FF
BatchOpeningClaim< Curve > compute_shplonk_opening_claim(const std::vector< Commitment > &table_commitments, const Commitment &shplonk_batched_quotient, const FF &shplonk_opening_challenge, const std::vector< FF > &shplonk_batching_challenges, const FF &kappa, const FF &kappa_inv, const std::vector< FF > &evals) const
std::vector< FF > Proof
bool check_concatenation_identities(std::vector< FF > &evals, const FF &pow_kappa) const
std::conditional_t< Curve::is_stdlib_type, stdlib::recursion::PairingPoints< Curve >, bb::PairingPoints< Curve > > PairingPoints
bool check_degree_identity(std::vector< FF > &evals, const FF &pow_kappa_minus_one, const std::vector< FF > &degree_check_challenges) const
ReductionResult reduce_to_pairing_check(const Proof &proof, const InputCommitments &input_commitments)
Reduce the merge proof to a pairing check.
std::array< Commitment, NUM_WIRES > TableCommitments
#define vinfo(...)
Definition log.hpp:94
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
An accumulator consisting of the Shplonk evaluation challenge and vectors of commitments and scalars.
Definition claim.hpp:155
std::vector< Commitment > commitments
Definition claim.hpp:160
std::vector< Scalar > scalars
Definition claim.hpp:161
Result of merge verification.