Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_keccak_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
16 public:
17 // This flavor runs with ZK Sumcheck
18 static constexpr bool HasZK = true;
19
20 // The number of entities added for ZK (gemini_masking_poly)
21 static constexpr size_t NUM_MASKING_POLYNOMIALS = 1;
22
23 // Determine the number of evaluations of Prover and Libra Polynomials that the Prover sends to the Verifier in
24 // the rounds of ZK Sumcheck.
27 "LIBRA_UNIVARIATES_LENGTH must be equal to UltraKeccakZKFlavor::BATCHED_RELATION_PARTIAL_LENGTH");
28
29 // Override AllEntities to use ZK version (this automatically updates ProverPolynomials and AllValues)
30 template <typename DataType> using AllEntities = UltraFlavor::AllEntities_<DataType, HasZK>;
31
32 // NUM_WITNESS_ENTITIES includes gemini_masking_poly
34 // NUM_ALL_ENTITIES includes gemini_masking_poly
36 // NUM_UNSHIFTED_ENTITIES includes gemini_masking_poly
37 static constexpr size_t NUM_UNSHIFTED_ENTITIES =
39
40 // Size of the final PCS MSM for ZK = non-ZK size + NUM_LIBRA_COMMITMENTS (3)
41 static constexpr size_t FINAL_PCS_MSM_SIZE(size_t log_n = VIRTUAL_LOG_N)
42 {
43 return NUM_UNSHIFTED_ENTITIES + log_n + 2 + NUM_LIBRA_COMMITMENTS;
44 }
45
46 // Override OINK_PROOF_LENGTH to include gemini_masking_poly commitment (sent via commit_to_masking_poly)
47 static constexpr size_t OINK_PROOF_LENGTH_WITHOUT_PUB_INPUTS =
48 /* 1. NUM_WITNESS_ENTITIES commitments (includes gemini_masking_poly) */ (NUM_WITNESS_ENTITIES *
50
55
56 // Override ProverUnivariates and ExtendedEdges to include gemini_masking_poly
59
60 // Proof length formula method
61 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n = VIRTUAL_LOG_N)
62 {
63 return /* 1. NUM_WITNESS_ENTITIES commitments */ (NUM_WITNESS_ENTITIES * num_elements_comm) +
64 /* 2. Libra concatenation commitment*/ (num_elements_comm) +
65 /* 3. Libra sum */ (num_elements_fr) +
66 /* 4. virtual_log_n sumcheck univariates */
68 /* 5. NUM_ALL_ENTITIES sumcheck evaluations*/ (NUM_ALL_ENTITIES * num_elements_fr) +
69 /* 6. Libra claimed evaluation */ (num_elements_fr) +
70 /* 7. Libra grand sum commitment */ (num_elements_comm) +
71 /* 8. Libra quotient commitment */ (num_elements_comm) +
72 /* 9. virtual_log_n - 1 Gemini Fold commitments */
73 ((virtual_log_n - 1) * num_elements_comm) +
74 /* 10. virtual_log_n Gemini a evaluations */
75 (virtual_log_n * num_elements_fr) +
76 /* 11. NUM_SMALL_IPA_EVALUATIONS libra evals */ (NUM_SMALL_IPA_EVALUATIONS * num_elements_fr) +
77 /* 12. Shplonk Q commitment */ (num_elements_comm) +
78 /* 13. KZG W commitment */ (num_elements_comm);
79 }
80
87 public:
89 // Override sumcheck_evaluations to use the correct size for ZK flavor
90 std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
91 // Note: we have a different vector of univariates because the degree for ZK flavors differs
104
105 Transcript() = default;
106
107 static std::shared_ptr<Transcript> prover_init_empty()
108 {
109 auto transcript = Base::prover_init_empty();
110 return std::static_pointer_cast<Transcript>(transcript);
111 };
112
113 static std::shared_ptr<Transcript> verifier_init_empty(const std::shared_ptr<Transcript>& transcript)
114 {
115 auto verifier_transcript = Base::verifier_init_empty(transcript);
116 return std::static_pointer_cast<Transcript>(verifier_transcript);
117 };
118
125 void deserialize_full_transcript(size_t public_input_size, size_t virtual_log_n = VIRTUAL_LOG_N)
126 {
127 // take current proof and put them into the struct
128 size_t num_frs_read = 0;
129 auto& proof_data = this->proof_data;
130 for (size_t i = 0; i < public_input_size; ++i) {
131 this->public_inputs.push_back(Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read));
132 }
133 hiding_polynomial_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
134 this->w_l_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
135 this->w_r_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
136 this->w_o_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
137 this->lookup_read_counts_comm =
138 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
139 this->lookup_read_tags_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
140 this->w_4_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
141 this->lookup_inverses_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
142 this->z_perm_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
144 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
145 libra_sum = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
146
147 for (size_t i = 0; i < virtual_log_n; ++i) {
148 zk_sumcheck_univariates.push_back(
149 Base::template deserialize_from_buffer<bb::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>>(
150 proof_data, num_frs_read));
151 }
152 libra_claimed_evaluation = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
153 this->sumcheck_evaluations =
154 Base::template deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(proof_data, num_frs_read);
155 libra_grand_sum_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
156 libra_quotient_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
157 for (size_t i = 0; i < virtual_log_n - 1; ++i) {
158 this->gemini_fold_comms.push_back(
159 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read));
160 }
161 for (size_t i = 0; i < virtual_log_n; ++i) {
162 this->gemini_fold_evals.push_back(Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read));
163 }
164 libra_concatenation_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
165 libra_shifted_grand_sum_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
166 libra_grand_sum_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
167 libra_quotient_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
168 this->shplonk_q_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
169
170 this->kzg_w_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
171 }
172
179 void serialize_full_transcript(size_t virtual_log_n = VIRTUAL_LOG_N)
180 {
181 auto& proof_data = this->proof_data;
182 size_t old_proof_length = proof_data.size();
183 proof_data.clear(); // clear proof_data so the rest of the function can replace it
184 for (const auto& public_input : this->public_inputs) {
185 Base::serialize_to_buffer(public_input, proof_data);
186 }
188 Base::serialize_to_buffer(this->w_l_comm, proof_data);
189 Base::serialize_to_buffer(this->w_r_comm, proof_data);
190 Base::serialize_to_buffer(this->w_o_comm, proof_data);
191 Base::serialize_to_buffer(this->lookup_read_counts_comm, proof_data);
192 Base::serialize_to_buffer(this->lookup_read_tags_comm, proof_data);
193 Base::serialize_to_buffer(this->w_4_comm, proof_data);
194 Base::serialize_to_buffer(this->lookup_inverses_comm, proof_data);
195 Base::serialize_to_buffer(this->z_perm_comm, proof_data);
198
199 for (size_t i = 0; i < virtual_log_n; ++i) {
201 }
203
204 Base::serialize_to_buffer(this->sumcheck_evaluations, proof_data);
207 for (size_t i = 0; i < virtual_log_n - 1; ++i) {
208 Base::serialize_to_buffer(this->gemini_fold_comms[i], proof_data);
209 }
210 for (size_t i = 0; i < virtual_log_n; ++i) {
211 Base::serialize_to_buffer(this->gemini_fold_evals[i], proof_data);
212 }
217 Base::serialize_to_buffer(this->shplonk_q_comm, proof_data);
218 Base::serialize_to_buffer(this->kzg_w_comm, proof_data);
219
220 BB_ASSERT_EQ(proof_data.size(), old_proof_length);
221 }
222 };
223};
224} // 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...
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.
BaseTranscript< Codec, HashFunction > Base
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 VIRTUAL_LOG_N
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_UNSHIFTED_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES
static constexpr size_t num_elements_comm
UltraKeccakFlavor::Transcript_< U256Codec, bb::crypto::Keccak > Transcript
static constexpr size_t num_elements_fr
Derived class that defines proof structure for Ultra zero knowledge proofs, as well as supporting fun...
std::array< FF, NUM_ALL_ENTITIES > sumcheck_evaluations
void deserialize_full_transcript(size_t public_input_size, size_t virtual_log_n=VIRTUAL_LOG_N)
Takes a FULL Ultra proof and deserializes it into the public member variables that compose the struct...
static std::shared_ptr< Transcript > verifier_init_empty(const std::shared_ptr< Transcript > &transcript)
static std::shared_ptr< Transcript > prover_init_empty()
std::vector< bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > > zk_sumcheck_univariates
void serialize_full_transcript(size_t virtual_log_n=VIRTUAL_LOG_N)
Serializes the structure variables into a FULL Ultra proof. Should be called only if deserialize_full...
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=VIRTUAL_LOG_N)
static constexpr size_t FINAL_PCS_MSM_SIZE(size_t log_n=VIRTUAL_LOG_N)
static constexpr size_t NUM_MASKING_POLYNOMIALS
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_UNSHIFTED_ENTITIES
static constexpr size_t OINK_PROOF_LENGTH_WITHOUT_PUB_INPUTS
static constexpr size_t NUM_WITNESS_ENTITIES
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH
Definition grumpkin.hpp:86
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13