Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
small_subgroup_ipa_utils.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Planned, auditors: [Khashayar], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
12
13#include <algorithm>
14#include <array>
15#include <memory>
16#include <string>
17#include <string_view>
18
19namespace bb {
20
27enum class SmallIpaEvalPoint : uint8_t {
28 Challenge, // r
29 ChallengeShifted, // g * r
30 One, // 1 (used for the A(1) = 0 boundary opening)
31};
32
47
59 { 0, SmallIpaEvalPoint::Challenge, true, "concatenation_eval" },
60 { 1, SmallIpaEvalPoint::ChallengeShifted, true, "shifted_grand_sum_eval" },
61 { 1, SmallIpaEvalPoint::Challenge, true, "grand_sum_eval" },
62 { 1, SmallIpaEvalPoint::One, false, "grand_sum_at_one_eval" },
63 { 2, SmallIpaEvalPoint::Challenge, true, "quotient_eval" },
64});
65
66// Total number of opening claims
67inline constexpr size_t NUM_SMALL_IPA_OPENING_CLAIMS = SMALL_IPA_CLAIMS.size();
68
69// Number of small-IPA scalar evaluations transmitted on the wire (boundary openings excluded.
70inline constexpr size_t NUM_SMALL_IPA_TRANSCRIPT_EVALS = [] {
71 size_t n = 0;
72 for (const auto& c : SMALL_IPA_CLAIMS) {
73 if (c.transmitted) {
74 ++n;
75 }
76 }
77 return n;
78}();
79
80// Number of underlying SmallSubgroupIPA commitments (max commitment_index + 1).
81inline constexpr size_t NUM_SMALL_IPA_COMMITMENTS = [] {
82 size_t m = 0;
83 for (const auto& c : SMALL_IPA_CLAIMS) {
84 m = std::max(c.commitment_index + 1, m);
85 }
86 return m;
87}();
88
92template <typename FF>
94 const FF& subgroup_generator)
95{
97 for (size_t i = 0; i < NUM_SMALL_IPA_OPENING_CLAIMS; ++i) {
98 switch (SMALL_IPA_CLAIMS[i].eval_point) {
100 result[i] = challenge;
101 break;
103 result[i] = challenge * subgroup_generator;
104 break;
106 result[i] = FF(1);
107 break;
108 }
109 }
110 return result;
111}
112
116template <typename Curve>
118 const typename Curve::ScalarField& shplonk_evaluation_challenge,
119 const typename Curve::ScalarField& small_ipa_evaluation_challenge)
120{
121 using FF = typename Curve::ScalarField;
122 const FF inv_z_minus_challenge = FF(1) / (shplonk_evaluation_challenge - small_ipa_evaluation_challenge);
123 const FF inv_z_minus_shifted =
124 FF(1) / (shplonk_evaluation_challenge - FF(Curve::subgroup_generator) * small_ipa_evaluation_challenge);
125 const FF inv_z_minus_one = FF(1) / (shplonk_evaluation_challenge - FF(1));
126
128 for (size_t i = 0; i < NUM_SMALL_IPA_OPENING_CLAIMS; ++i) {
129 switch (SMALL_IPA_CLAIMS[i].eval_point) {
131 result[i] = inv_z_minus_challenge;
132 break;
134 result[i] = inv_z_minus_shifted;
135 break;
137 result[i] = inv_z_minus_one;
138 break;
139 }
140 }
141 return result;
142}
143
148{
150 for (size_t i = 0; i < NUM_SMALL_IPA_OPENING_CLAIMS; ++i) {
151 result[i] = std::string(prefix) + std::string(SMALL_IPA_CLAIMS[i].label_suffix);
152 }
153 return result;
154}
155
160template <typename Commitment> struct SmallSubgroupIPACommitments {
162 std::array<Commitment, NUM_SMALL_IPA_COMMITMENTS> as_array() const { return { concatenated, grand_sum, quotient }; }
163};
164
171template <typename Curve, typename Transcript>
174 const typename Curve::ScalarField& challenge,
175 std::string_view label_prefix,
176 const std::shared_ptr<Transcript>& transcript)
177{
178 using FF = typename Curve::ScalarField;
179 const auto labels = get_evaluation_labels(label_prefix);
180 const auto points = compute_evaluation_points(challenge, FF(Curve::subgroup_generator));
181
183 for (size_t i = 0; i < NUM_SMALL_IPA_OPENING_CLAIMS; ++i) {
184 const auto& poly = polynomials[SMALL_IPA_CLAIMS[i].commitment_index];
185 FF evaluation = FF(0);
186 if (SMALL_IPA_CLAIMS[i].transmitted) {
187 evaluation = poly.evaluate(points[i]);
188 transcript->send_to_verifier(labels[i], evaluation);
189 }
190 claims[i] = { poly, { points[i], evaluation } };
191 }
192 return claims;
193}
194
205template <typename Curve, typename Transcript>
207 std::string_view label_prefix, const std::shared_ptr<Transcript>& transcript)
208{
209 using FF = typename Curve::ScalarField;
210 const auto labels = get_evaluation_labels(label_prefix);
212 for (size_t i = 0; i < NUM_SMALL_IPA_OPENING_CLAIMS; ++i) {
213 if (SMALL_IPA_CLAIMS[i].transmitted) {
214 evaluations[i] = transcript->template receive_from_prover<FF>(labels[i]);
215 }
216 }
217 if constexpr (Curve::is_stdlib_type) {
218 for (auto& eval : evaluations) {
219 eval.clear_round_provenance();
220 }
221 }
222 return evaluations;
223}
224
229template <typename Curve, typename Transcript>
232 const typename Curve::ScalarField& challenge,
233 std::string_view label_prefix,
234 const std::shared_ptr<Transcript>& transcript)
235{
236 using FF = typename Curve::ScalarField;
237 const auto evaluations = receive_small_ipa_evaluations<Curve>(label_prefix, transcript);
238 const auto points = compute_evaluation_points(challenge, FF(Curve::subgroup_generator));
239
241 for (size_t i = 0; i < NUM_SMALL_IPA_OPENING_CLAIMS; ++i) {
242 claims[i] = { { points[i], evaluations[i] }, commitments[SMALL_IPA_CLAIMS[i].commitment_index] };
243 }
244 return claims;
245}
246} // namespace bb
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
static constexpr bool is_stdlib_type
Definition grumpkin.hpp:67
static constexpr ScalarField subgroup_generator
Definition grumpkin.hpp:79
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::array< typename Curve::ScalarField, NUM_SMALL_IPA_OPENING_CLAIMS > receive_small_ipa_evaluations(std::string_view label_prefix, const std::shared_ptr< Transcript > &transcript)
Receive the five SmallSubgroupIPA evaluations on the verifier side.
constexpr size_t NUM_SMALL_IPA_COMMITMENTS
constexpr size_t NUM_SMALL_IPA_TRANSCRIPT_EVALS
constexpr auto SMALL_IPA_CLAIMS
The five SmallSubgroupIPA opening claims, in transcript order.
SmallIpaEvalPoint
Recipe for the evaluation point of a single SmallSubgroupIPA opening claim.
std::array< ProverOpeningClaim< Curve >, NUM_SMALL_IPA_OPENING_CLAIMS > make_small_ipa_prover_opening_claims(const std::array< bb::Polynomial< typename Curve::ScalarField >, NUM_SMALL_IPA_COMMITMENTS > &polynomials, const typename Curve::ScalarField &challenge, std::string_view label_prefix, const std::shared_ptr< Transcript > &transcript)
Build the five SmallSubgroupIPA prover opening claims.
std::array< typename Curve::ScalarField, NUM_SMALL_IPA_OPENING_CLAIMS > compute_shplonk_denominators_for_small_ipa(const typename Curve::ScalarField &shplonk_evaluation_challenge, const typename Curve::ScalarField &small_ipa_evaluation_challenge)
Compute Shplonk denominators 1 / (z - x_i), where x_i are the SmallSubgroupIPA opening points.
std::array< FF, NUM_SMALL_IPA_OPENING_CLAIMS > compute_evaluation_points(const FF &challenge, const FF &subgroup_generator)
Compute the evaluation points {r, g*r, r, 1, r} for the five opening claims by walking SMALL_IPA_CLAI...
std::array< OpeningClaim< Curve >, NUM_SMALL_IPA_OPENING_CLAIMS > make_small_ipa_verifier_opening_claims(const std::array< typename Curve::AffineElement, NUM_SMALL_IPA_COMMITMENTS > &commitments, const typename Curve::ScalarField &challenge, std::string_view label_prefix, const std::shared_ptr< Transcript > &transcript)
Build the five SmallSubgroupIPA verifier opening claims, pairing each evaluation with the commitment ...
constexpr size_t NUM_SMALL_IPA_OPENING_CLAIMS
std::array< std::string, NUM_SMALL_IPA_OPENING_CLAIMS > get_evaluation_labels(std::string_view prefix)
Build the wire labels {prefix + suffix} for the five opening claims. prefix is "Libra:" or "Translati...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Static specification of one SmallSubgroupIPA opening claim.
Holds commitments to [G], [A], [Q]. Code that needs a per-claim commitment must index as_array() via ...
std::array< Commitment, NUM_SMALL_IPA_COMMITMENTS > as_array() const
VectorField result