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
11
12namespace bb {
13
23class UltraZKFlavor : public UltraFlavor {
24 public:
25 // This flavor runs with ZK Sumcheck
26 static constexpr bool HasZK = true;
27 // Determine the number of evaluations of Prover and Libra Polynomials that the Prover sends to the Verifier in
28 // the rounds of ZK Sumcheck.
31 "LIBRA_UNIVARIATES_LENGTH must be equal to UltraZKFlavor::BATCHED_RELATION_PARTIAL_LENGTH");
32 static constexpr size_t num_frs_comm = bb::field_conversion::calc_num_bn254_frs<Commitment>();
33 static constexpr size_t num_frs_fr = bb::field_conversion::calc_num_bn254_frs<FF>();
34
35 // Proof length formula method
36 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N)
37 {
38 return /* 1. NUM_WITNESS_ENTITIES commitments */ (NUM_WITNESS_ENTITIES * num_frs_comm) +
39 /* 2. Libra concatenation commitment*/ (num_frs_comm) +
40 /* 3. Libra sum */ (num_frs_fr) +
41 /* 4. virtual_log_n sumcheck univariates */
43 /* 5. NUM_ALL_ENTITIES sumcheck evaluations*/ (NUM_ALL_ENTITIES * num_frs_fr) +
44 /* 6. Libra claimed evaluation */ (num_frs_fr) +
45 /* 7. Libra grand sum commitment */ (num_frs_comm) +
46 /* 8. Libra quotient commitment */ (num_frs_comm) +
47 /* 9. Gemini masking commitment */ (num_frs_comm) +
48 /* 10. Gemini masking evaluation */ (num_frs_fr) +
49 /* 11. virtual_log_n - 1 Gemini Fold commitments */
50 ((virtual_log_n - 1) * num_frs_comm) +
51 /* 12. virtual_log_n Gemini a evaluations */
52 (virtual_log_n * num_frs_fr) +
53 /* 13. NUM_SMALL_IPA_EVALUATIONS libra evals */ (NUM_SMALL_IPA_EVALUATIONS * num_frs_fr) +
54 /* 14. Shplonk Q commitment */ (num_frs_comm) +
55 /* 15. KZG W commitment */ (num_frs_comm);
56 }
57
63 template <typename Params> class Transcript_ : public UltraFlavor::Transcript_<Params> {
64 public:
66 // Note: we have a different vector of univariates because the degree for ZK flavors differs
79
80 Transcript_() = default;
81
83 {
84 auto transcript = Base::prover_init_empty();
86 };
87
89 {
90 auto verifier_transcript = Base::verifier_init_empty(transcript);
91 return std::static_pointer_cast<Transcript_>(verifier_transcript);
92 };
93
100 void deserialize_full_transcript(size_t num_public_inputs, size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N)
101 {
102 // take current proof and put them into the struct
103 size_t num_frs_read = 0;
104 auto& proof_data = this->proof_data;
105 for (size_t i = 0; i < num_public_inputs; ++i) {
106 this->public_inputs.push_back(Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read));
107 }
108 this->w_l_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
109 this->w_r_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
110 this->w_o_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
112 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
113 this->lookup_read_tags_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
114 this->w_4_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
115 this->lookup_inverses_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
116 this->z_perm_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
118 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
119 libra_sum = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
120
121 for (size_t i = 0; i < virtual_log_n; ++i) {
122 zk_sumcheck_univariates.push_back(
125 }
126 libra_claimed_evaluation = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
128 Base::template deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(proof_data, num_frs_read);
129 libra_grand_sum_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
130 libra_quotient_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
131 hiding_polynomial_commitment = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
132 hiding_polynomial_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
133 for (size_t i = 0; i < virtual_log_n - 1; ++i) {
134 this->gemini_fold_comms.push_back(
135 Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read));
136 }
137 for (size_t i = 0; i < virtual_log_n; ++i) {
138 this->gemini_fold_evals.push_back(Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read));
139 }
140 libra_concatenation_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
141 libra_shifted_grand_sum_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
142 libra_grand_sum_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
143 libra_quotient_eval = Base::template deserialize_from_buffer<FF>(proof_data, num_frs_read);
144 this->shplonk_q_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
145
146 this->kzg_w_comm = Base::template deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
147 }
148
155 void serialize_full_transcript(size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N)
156 {
157 auto& proof_data = this->proof_data;
158 size_t old_proof_length = proof_data.size();
159 proof_data.clear(); // clear proof_data so the rest of the function can replace it
160 for (const auto& input : this->public_inputs) {
162 }
171 Base::serialize_to_buffer(libra_concatenation_commitment, proof_data);
173
174 for (size_t i = 0; i < virtual_log_n; ++i) {
176 }
178
180 Base::serialize_to_buffer(libra_grand_sum_commitment, proof_data);
184 for (size_t i = 0; i < virtual_log_n - 1; ++i) {
186 }
187 for (size_t i = 0; i < virtual_log_n; ++i) {
189 }
196
197 BB_ASSERT_EQ(proof_data.size(), old_proof_length);
198 }
199 };
201};
202} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
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.
void serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
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...
static std::shared_ptr< BaseTranscript > prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
Derived class that defines proof structure for Ultra proofs, as well as supporting functions.
std::vector< FF > gemini_fold_evals
std::vector< Commitment > gemini_fold_comms
std::vector< FF > public_inputs
std::array< FF, NUM_ALL_ENTITIES > sumcheck_evaluations
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Curve::AffineElement Commitment
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES
Derived class that defines proof structure for Ultra zero knowledge proofs, as well as supporting fun...
static std::shared_ptr< Transcript_ > prover_init_empty()
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
static std::shared_ptr< Transcript_ > verifier_init_empty(const std::shared_ptr< Transcript_ > &transcript)
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...
Child class of UltraFlavor that runs with ZK Sumcheck.
static constexpr bool HasZK
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)
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH
Definition bn254.hpp:46
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13