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"
12
13namespace bb {
14
15template <typename Curve>
16bool MergeVerifier_<Curve>::check_concatenation_identities(std::vector<FF>& evals, const FF& pow_kappa) const
17{
18 bool concatenation_verified = true;
19 FF concatenation_diff(0);
20 for (size_t idx = 0; idx < NUM_WIRES; idx++) {
21 concatenation_diff = evals[idx] + (pow_kappa * evals[idx + NUM_WIRES]) - evals[idx + (2 * NUM_WIRES)];
22 if constexpr (IsRecursive) {
23 concatenation_verified &= concatenation_diff.get_value() == 0;
24 concatenation_diff.assert_equal(FF(0),
25 "assert_equal: merge concatenation identity failed in Merge Verifier");
26 } else {
27 concatenation_verified &= concatenation_diff == 0;
28 }
29 }
30 return concatenation_verified;
31}
32
33template <typename Curve>
35 const FF& pow_kappa_minus_one,
36 const std::vector<FF>& degree_check_challenges) const
37{
38 bool degree_check_verified = true;
39 FF degree_check_diff(0);
40 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
41 degree_check_diff += evals[idx] * degree_check_challenges[idx];
42 }
43 degree_check_diff -= evals.back() * pow_kappa_minus_one;
44 if constexpr (IsRecursive) {
45 degree_check_verified &= degree_check_diff.get_value() == 0;
46 degree_check_diff.assert_equal(FF(0), "assert_equal: merge degree identity failed in Merge Verifier");
47 } else {
48 degree_check_verified &= degree_check_diff == 0;
49 }
50
51 return degree_check_verified;
52}
53
54template <typename Curve>
56 const std::vector<Commitment>& table_commitments,
57 const Commitment& shplonk_batched_quotient,
58 const FF& shplonk_opening_challenge,
59 const std::vector<FF>& shplonk_batching_challenges,
60 const FF& kappa,
61 const FF& kappa_inv,
62 const std::vector<FF>& evals) const
63{
64 // Claim {Q', (z, 0)} where Q' = -Q·(z - κ) + Σᵢ βᵢLᵢ + Σᵢ βᵢRᵢ + Σᵢ βᵢMᵢ + (z - κ)/(z - κ⁻¹)·βG
65 // - Σᵢ βᵢlᵢ - Σᵢ βᵢrᵢ - Σᵢ βᵢmᵢ - (z - κ)/(z - κ⁻¹)·β·g
66 BatchOpeningClaim<Curve> batch_opening_claim;
67
68 // Commitment: [L_1], [L_2], ..., [L_n], [R_1], ..., [R_n], [M_1], ..., [M_n], [G], [1]
69 batch_opening_claim.commitments = { std::move(shplonk_batched_quotient) };
70 for (auto& commitment : table_commitments) {
71 batch_opening_claim.commitments.emplace_back(std::move(commitment));
72 }
73 if constexpr (IsRecursive) {
74 batch_opening_claim.commitments.emplace_back(Commitment::one(kappa.get_context()));
75 } else {
76 batch_opening_claim.commitments.emplace_back(Commitment::one());
77 }
78
79 // Scalars: -(z - κ), β₁...β₁₂, β₁₃·(z - κ)/(z - κ⁻¹), -(Σᵢ βᵢlᵢ + Σᵢ βᵢrᵢ + Σᵢ βᵢmᵢ + β₁₃·(z - κ)/(z - κ⁻¹)·g)
80 batch_opening_claim.scalars = { -(shplonk_opening_challenge - kappa) };
81 for (auto& scalar : shplonk_batching_challenges) {
82 batch_opening_claim.scalars.emplace_back(std::move(scalar));
83 }
84 batch_opening_claim.scalars.back() *=
85 (shplonk_opening_challenge - kappa) * (shplonk_opening_challenge - kappa_inv).invert();
86
87 batch_opening_claim.scalars.emplace_back(FF(0));
88 for (size_t idx = 0; idx < evals.size(); idx++) {
89 if (idx < evals.size() - 1) {
90 batch_opening_claim.scalars.back() -= evals[idx] * shplonk_batching_challenges[idx];
91 } else {
92 batch_opening_claim.scalars.back() -= shplonk_batching_challenges.back() * evals.back() *
93 (shplonk_opening_challenge - kappa) *
94 (shplonk_opening_challenge - kappa_inv).invert();
95 }
96 }
97
98 batch_opening_claim.evaluation_point = { shplonk_opening_challenge };
99
100 return batch_opening_claim;
101}
102
113template <typename Curve>
115 const Proof& proof, const InputCommitments& input_commitments)
116{
117 transcript->load_proof(proof);
118
119 // Receive shift size from prover
120 // For native: shift_size is uint32_t
121 // For stdlib: shift_size is FF (we'll get the value later)
122 const FF shift_size = transcript->template receive_from_prover<FF>("shift_size");
123 ;
124 if constexpr (IsRecursive) {
125 BB_ASSERT_GT(uint32_t(shift_size.get_value()), 0U, "Shift size should always be bigger than 0");
126 } else {
127
128 BB_ASSERT_GT(shift_size, 0U, "Shift size should always be bigger than 0");
129 }
130
131 // Store T_commitments of the verifier
132 TableCommitments merged_table_commitments;
133
134 // Vector of commitments
135 // The vector is composed of: [L_1], .., [L_4], [R_1], .., [R_4], [M_1], .., [M_4], [G]
136 std::vector<Commitment> table_commitments;
137 table_commitments.reserve((3 * NUM_WIRES) + 1);
138 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
139 table_commitments.emplace_back(settings == MergeSettings::PREPEND ? input_commitments.t_commitments[idx]
140 : input_commitments.T_prev_commitments[idx]);
141 }
142 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
143 table_commitments.emplace_back(settings == MergeSettings::PREPEND ? input_commitments.T_prev_commitments[idx]
144 : input_commitments.t_commitments[idx]);
145 }
146 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
147 table_commitments.emplace_back(
148 transcript->template receive_from_prover<Commitment>("MERGED_TABLE_" + std::to_string(idx)));
149 merged_table_commitments[idx] = table_commitments.back();
150 }
151
152 // Generate degree check batching challenges
153 std::vector<FF> degree_check_challenges = transcript->template get_challenges<FF>(labels_degree_check);
154
155 // Receive commitment to reversed batched left table
156 table_commitments.emplace_back(
157 transcript->template receive_from_prover<Commitment>("REVERSED_BATCHED_LEFT_TABLES"));
158
159 // Compute batching challenges
160 std::vector<FF> shplonk_batching_challenges =
161 transcript->template get_challenges<FF>(labels_shplonk_batching_challenges);
162
163 // Evaluation challenge
164 const FF kappa = transcript->template get_challenge<FF>("kappa");
165 const FF kappa_inv = kappa.invert();
166 const FF pow_kappa = kappa.pow(shift_size);
167 const FF pow_kappa_minus_one = pow_kappa * kappa_inv;
168
169 // Receive evaluations of [Lᵢ], [Rᵢ], [Mᵢ] at κ
170 std::vector<FF> evals;
171 evals.reserve((3 * NUM_WIRES) + 1);
172 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
173 evals.emplace_back(transcript->template receive_from_prover<FF>("LEFT_TABLE_EVAL_" + std::to_string(idx)));
174 }
175 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
176 evals.emplace_back(transcript->template receive_from_prover<FF>("RIGHT_TABLE_EVAL_" + std::to_string(idx)));
177 }
178 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
179 evals.emplace_back(transcript->template receive_from_prover<FF>("MERGED_TABLE_EVAL_" + std::to_string(idx)));
180 }
181
182 // Receive evaluation of G at 1/κ
183 evals.emplace_back(transcript->template receive_from_prover<FF>("REVERSED_BATCHED_LEFT_TABLES_EVAL"));
184
185 // Check concatenation identities
186 bool concatenation_verified = check_concatenation_identities(evals, pow_kappa);
187
188 // Check degree identity
189 bool degree_check_verified = check_degree_identity(evals, pow_kappa_minus_one, degree_check_challenges);
190
191 // Receive Shplonk batched quotient
192 Commitment shplonk_batched_quotient =
193 transcript->template receive_from_prover<Commitment>("SHPLONK_BATCHED_QUOTIENT");
194
195 // Generate Shplonk opening challenge
196 FF shplonk_opening_challenge = transcript->template get_challenge<FF>("shplonk_opening_challenge");
197
198 // Prepare batched opening claim to be passed to KZG
199 BatchOpeningClaim<Curve> batch_opening_claim = compute_shplonk_opening_claim(table_commitments,
200 shplonk_batched_quotient,
201 shplonk_opening_challenge,
202 shplonk_batching_challenges,
203 kappa,
204 kappa_inv,
205 evals);
206
207 BB_ASSERT(batch_opening_claim.commitments.size() == MERGE_BATCHED_CLAIM_SIZE);
208 BB_ASSERT(batch_opening_claim.scalars.size() == MERGE_BATCHED_CLAIM_SIZE);
209
210 // KZG verifier - returns PairingPoints directly
211 PairingPoints pairing_points = PCS::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), transcript);
212
213 vinfo("Merge Verifier: degree check passed: ", degree_check_verified ? "true" : "false");
214 vinfo("Merge Verifier: concatenation check passed: ", concatenation_verified ? "true" : "false");
215
216 return { pairing_points, merged_table_commitments, degree_check_verified && concatenation_verified };
217}
218
219// Explicit template instantiations
220template class MergeVerifier_<curve::BN254>;
223
224} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:80
#define BB_ASSERT_GT(left, right,...)
Definition assert.hpp:123
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:22
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:151
std::vector< Commitment > commitments
Definition claim.hpp:156
std::vector< Scalar > scalars
Definition claim.hpp:157
Result of merge verification.