Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_zk_flavor.hpp
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
7#pragma once
8
12
13namespace bb {
14
24class UltraZKFlavor : public UltraFlavor {
25 public:
26 // This flavor runs with ZK Sumcheck
27 static constexpr bool HasZK = true;
28
29 // The number of entities added for ZK (gemini_masking_poly)
30 static constexpr size_t NUM_MASKING_POLYNOMIALS = 1;
31
32 // Determine the number of evaluations of Prover and Libra Polynomials that the Prover sends to the Verifier in
33 // the rounds of ZK Sumcheck.
36 "LIBRA_UNIVARIATES_LENGTH must be equal to UltraZKFlavor::BATCHED_RELATION_PARTIAL_LENGTH");
37 static constexpr size_t num_frs_comm = FrCodec::calc_num_fields<Commitment>();
38 static constexpr size_t num_frs_fr = FrCodec::calc_num_fields<FF>();
39
40 // Override AllEntities to use ZK version (includes gemini_masking_poly via MaskingEntities)
41 template <typename DataType> using AllEntities = UltraFlavor::AllEntities_<DataType, HasZK>;
42
43 // NUM_WITNESS_ENTITIES includes gemini_masking_poly
45 // NUM_ALL_ENTITIES includes gemini_masking_poly
47 // NUM_UNSHIFTED_ENTITIES includes gemini_masking_poly
49
50 // Size of the final PCS MSM for ZK = non-ZK size + NUM_LIBRA_COMMITMENTS (3)
51 static constexpr size_t FINAL_PCS_MSM_SIZE(size_t log_n = CONST_PROOF_SIZE_LOG_N)
52 {
53 return NUM_UNSHIFTED_ENTITIES + log_n + 2 + NUM_LIBRA_COMMITMENTS;
54 }
55
56 // Override OINK_PROOF_LENGTH to include gemini_masking_poly commitment (sent via commit_to_masking_poly)
57 static constexpr size_t OINK_PROOF_LENGTH_WITHOUT_PUB_INPUTS =
58 /* 1. NUM_WITNESS_ENTITIES commitments (includes gemini_masking_poly) */ (NUM_WITNESS_ENTITIES * num_frs_comm);
59
64
65 // Override ProverUnivariates and ExtendedEdges to include gemini_masking_poly
68
69 // Proof length formula method
70 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N)
71 {
72 return /* 1. NUM_WITNESS_ENTITIES commitments */ (NUM_WITNESS_ENTITIES * num_frs_comm) +
73 /* 2. Libra concatenation commitment*/ (num_frs_comm) +
74 /* 3. Libra sum */ (num_frs_fr) +
75 /* 4. virtual_log_n sumcheck univariates */
77 /* 5. NUM_ALL_ENTITIES sumcheck evaluations*/ (NUM_ALL_ENTITIES * num_frs_fr) +
78 /* 6. Libra claimed evaluation */ (num_frs_fr) +
79 /* 7. Libra grand sum commitment */ (num_frs_comm) +
80 /* 8. Libra quotient commitment */ (num_frs_comm) +
81 /* 9. virtual_log_n - 1 Gemini Fold commitments */
82 ((virtual_log_n - 1) * num_frs_comm) +
83 /* 10. virtual_log_n Gemini a evaluations */
84 (virtual_log_n * num_frs_fr) +
85 /* 11. NUM_SMALL_IPA_EVALUATIONS libra evals */ (NUM_SMALL_IPA_EVALUATIONS * num_frs_fr) +
86 /* 12. Shplonk Q commitment */ (num_frs_comm) +
87 /* 13. KZG W commitment */ (num_frs_comm);
88 }
89
96 public:
98 // Override sumcheck_evaluations to use the correct size for ZK flavor
99 std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
100 // Note: we have a different vector of univariates because the degree for ZK flavors differs
113
114 Transcript_() = default;
115
117 {
118 auto transcript = Base::prover_init_empty();
119 return std::static_pointer_cast<Transcript_>(transcript);
120 };
121
123 {
124 auto verifier_transcript = Base::verifier_init_empty(transcript);
125 return std::static_pointer_cast<Transcript_>(verifier_transcript);
126 };
127
134 void deserialize_full_transcript(size_t num_public_inputs, size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N)
135 {
136 // take current proof and put them into the struct
137 size_t num_frs_read = 0;
138 auto& proof_data = this->proof_data;
139 for (size_t i = 0; i < num_public_inputs; ++i) {
140 this->public_inputs.push_back(Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read));
141 }
142 hiding_polynomial_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
143 this->w_l_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
144 this->w_r_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
145 this->w_o_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
147 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
148 this->lookup_read_tags_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
149 this->w_4_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
150 this->lookup_inverses_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
151 this->z_perm_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
153 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
154 libra_sum = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
155
156 for (size_t i = 0; i < virtual_log_n; ++i) {
157 zk_sumcheck_univariates.push_back(
160 }
161 libra_claimed_evaluation = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
162 this->sumcheck_evaluations =
163 Base::template deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(proof_data, num_frs_read);
164 libra_grand_sum_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
165 libra_quotient_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
166 for (size_t i = 0; i < virtual_log_n - 1; ++i) {
167 this->gemini_fold_comms.push_back(
168 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read));
169 }
170 for (size_t i = 0; i < virtual_log_n; ++i) {
171 this->gemini_fold_evals.push_back(Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read));
172 }
173 libra_concatenation_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
174 libra_shifted_grand_sum_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
175 libra_grand_sum_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
176 libra_quotient_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
177 this->shplonk_q_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
178
179 this->kzg_w_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
180 }
181
188 void serialize_full_transcript(size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N)
189 {
190 auto& proof_data = this->proof_data;
191 size_t old_proof_length = proof_data.size();
192 proof_data.clear(); // clear proof_data so the rest of the function can replace it
193 for (const auto& input : this->public_inputs) {
195 }
205 Base::serialize_to_buffer(libra_concatenation_commitment, proof_data);
207
208 for (size_t i = 0; i < virtual_log_n; ++i) {
210 }
212
213 Base::serialize_to_buffer(this->sumcheck_evaluations, proof_data);
216 for (size_t i = 0; i < virtual_log_n - 1; ++i) {
218 }
219 for (size_t i = 0; i < virtual_log_n; ++i) {
221 }
228
229 BB_ASSERT_EQ(proof_data.size(), old_proof_length);
230 }
231 };
233};
234} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:77
void serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
static std::shared_ptr< BaseTranscript > prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
T deserialize_from_buffer(const Proof &proof_data, size_t &offset) const
Deserializes the frs starting at offset into the typed element and returns that element.
static std::shared_ptr< BaseTranscript > verifier_init_empty(const std::shared_ptr< BaseTranscript > &transcript)
For testing: initializes transcript based on proof data then receives junk data produced by BaseTrans...
A base class labelling all entities (for instance, all of the polynomials used by the prover during s...
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
A container for storing the partially evaluated multivariates produced by sumcheck.
A container for polynomials handles.
Derived class that defines proof structure for Ultra proofs, as well as supporting functions.
std::vector< FF > public_inputs
std::vector< FF > gemini_fold_evals
BaseTranscript< Codec, HashFunction > Base
std::vector< Commitment > gemini_fold_comms
A container encapsulating all the commitments that the verifier receives (to precomputed polynomials ...
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Curve::AffineElement Commitment
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_UNSHIFTED_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES
Derived class that defines proof structure for Ultra zero knowledge proofs, as well as supporting fun...
void deserialize_full_transcript(size_t num_public_inputs, size_t virtual_log_n=CONST_PROOF_SIZE_LOG_N)
Takes a FULL Ultra proof and deserializes it into the public member variables that compose the struct...
std::vector< bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > > zk_sumcheck_univariates
std::array< FF, NUM_ALL_ENTITIES > sumcheck_evaluations
static std::shared_ptr< Transcript_ > prover_init_empty()
void serialize_full_transcript(size_t virtual_log_n=CONST_PROOF_SIZE_LOG_N)
Serializes the structure variables into a FULL Ultra proof. Should be called only if deserialize_full...
static std::shared_ptr< Transcript_ > verifier_init_empty(const std::shared_ptr< Transcript_ > &transcript)
Child class of UltraFlavor that runs with ZK Sumcheck.
static constexpr size_t OINK_PROOF_LENGTH_WITHOUT_PUB_INPUTS
static constexpr bool HasZK
static constexpr size_t NUM_UNSHIFTED_ENTITIES
static constexpr size_t FINAL_PCS_MSM_SIZE(size_t log_n=CONST_PROOF_SIZE_LOG_N)
static constexpr size_t NUM_WITNESS_ENTITIES
static constexpr size_t num_frs_comm
static constexpr size_t num_frs_fr
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=CONST_PROOF_SIZE_LOG_N)
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_MASKING_POLYNOMIALS
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH
Definition bn254.hpp:46
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13