Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
client_ivc.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
26#include <algorithm>
27
28namespace bb {
29
39class ClientIVC {
40
41 public:
45 using FF = Flavor::FF;
46 using Point = Flavor::Curve::AffineElement;
47 using FoldProof = std::vector<FF>;
51 using ClientCircuit = MegaCircuitBuilder; // can only be Mega
63
75
85
86 // Merge commitments
88
96 struct Proof {
99
106 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n = MegaZKFlavor::VIRTUAL_LOG_N)
107 {
108 return /*mega_proof*/ MegaZKFlavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS(virtual_log_n) +
109 /*merge_proof*/ MERGE_PROOF_SIZE +
110 /*eccvm pre-ipa proof*/ (ECCVMFlavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS - IPA_PROOF_LENGTH) +
111 /*eccvm ipa proof*/ IPA_PROOF_LENGTH +
113 }
114
121 static constexpr size_t PROOF_LENGTH(size_t virtual_log_n = MegaZKFlavor::VIRTUAL_LOG_N)
122 {
123 return PROOF_LENGTH_WITHOUT_PUB_INPUTS(virtual_log_n) +
125 }
126
127 size_t size() const;
128
134 std::vector<FF> to_field_elements() const;
135
136 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1299): The following msgpack methods are generic
137 // and should leverage some kind of shared msgpack utility.
138 msgpack::sbuffer to_msgpack_buffer() const;
139
147 uint8_t* to_msgpack_heap_buffer() const;
148 static constexpr const char* MSGPACK_SCHEMA_NAME = "ClientIVCProof";
149
150 class DeserializationError : public std::runtime_error {
151 public:
152 DeserializationError(const std::string& msg)
153 : std::runtime_error(std::string("Client IVC Proof deserialization error: ") + msg)
154 {}
155 };
156
157 static Proof from_msgpack_buffer(uint8_t const*& buffer);
158 static Proof from_msgpack_buffer(const msgpack::sbuffer& buffer);
159
160 void to_file_msgpack(const std::string& filename) const;
161 static Proof from_file_msgpack(const std::string& filename);
162
164 bool operator==(const Proof& other) const = default;
165 };
166
174
175 // Specifies proof type or equivalently the type of recursive verification to be performed on a given proof
176 enum class QUEUE_TYPE {
177 OINK,
178 PG,
179 PG_FINAL, // the final PG verification, used in hiding kernel
180 PG_TAIL, // used in tail to indicate special handling of merge for ZK
181 MEGA
182 };
183
184 // An entry in the native verification queue
186 std::vector<FF> proof; // oink or PG
189 bool is_kernel = false;
190 };
191 using VerificationQueue = std::deque<VerifierInputs>;
192
193 // An entry in the stdlib verification queue
195 StdlibProof proof; // oink or PG
196 std::shared_ptr<RecursiveVKAndHash> honk_vk_and_hash;
198 bool is_kernel = false;
199 };
200 using StdlibVerificationQueue = std::deque<StdlibVerifierInputs>;
201
202 // Utility for tracking the max size of each block across the full IVC
204
205 private:
207
208 // Transcript for CIVC prover (shared between Hiding circuit, Merge, ECCVM, and Translator)
209 std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();
210
211 // Transcript to be shared across the folding of K_{i-1} (kernel), A_{i,1} (app), .., A_{i, n}
213
214 size_t num_circuits; // total number of circuits to be accumulated in the IVC
215 public:
216 size_t num_circuits_accumulated = 0; // number of circuits accumulated so far
217
218 ProverFoldOutput fold_output; // prover accumulator and fold proof
219 HonkProof decider_proof; // decider proof to be verified in the hiding circuit
220
222 recursive_verifier_native_accum; // native verifier accumulator used in recursive folding
224 native_verifier_accum; // native verifier accumulator used in prover folding
225 std::shared_ptr<MegaVerificationKey> honk_vk; // honk vk to be completed and folded into the accumulator
226
227 // Set of tuples {proof, verification_key, type (Oink/PG)} to be recursively verified
229 // Set of tuples {stdlib_proof, stdlib_verification_key, type} corresponding to the native verification queue
231
232 // Management of linking databus commitments between circuits in the IVC
234
235 // Settings related to the use of fixed block sizes for each gate in the execution trace
237
239
241
242 size_t get_num_circuits() const { return num_circuits; }
243
245
247 const std::vector<std::shared_ptr<RecursiveVKAndHash>>& input_keys = {});
248
249 [[nodiscard("Pairing points should be accumulated")]] std::
252 ClientCircuit& circuit,
253 const StdlibVerifierInputs& verifier_inputs,
254 const std::shared_ptr<RecursiveDeciderVerificationKey>& input_verifier_accumulator,
255 const TableCommitments& T_prev_commitments,
256 const std::shared_ptr<RecursiveTranscript>& accumulation_recursive_transcript);
257
258 // Complete the logic of a kernel circuit (e.g. PG/merge recursive verification, databus consistency checks)
260
269 void accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVerificationKey>& precomputed_vk);
270
271 Proof prove();
272
275
276 static bool verify(const Proof& proof, const VerificationKey& vk);
277
278 bool verify(const Proof& proof) const;
279
280 bool prove_and_verify();
281
282 HonkProof construct_decider_proof(const std::shared_ptr<Transcript>& transcript);
283
284 VerificationKey get_vk() const;
285
286 private:
293 void update_native_verifier_accumulator(const VerifierInputs& queue_entry,
294 const std::shared_ptr<Transcript>& verifier_transcript);
295
298 const std::shared_ptr<Transcript>& transcript);
299
302 const std::shared_ptr<Transcript>& transcript,
303 bool is_kernel);
304
306
308 ClientCircuit& circuit,
311 const StdlibProof& proof);
312
314 ClientCircuit& circuit,
315 const std::shared_ptr<RecursiveDeciderVerificationKey>& verifier_accumulator,
318 const StdlibProof& proof,
319 std::optional<StdlibFF>& prev_accum_hash,
320 bool is_kernel);
321};
322
323} // namespace bb
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
DeserializationError(const std::string &msg)
The IVC scheme used by the aztec client for private function execution.
Proof prove()
Construct a proof for the IVC, which, if verified, fully establishes its correctness.
static void hide_op_queue_accumulation_result(ClientCircuit &circuit)
Add a random operation to the op queue to hide its content in Translator computation.
MegaFlavor::CommitmentKey bn254_commitment_key
HonkProof construct_oink_proof(const std::shared_ptr< DeciderProvingKey > &proving_key, const std::shared_ptr< MegaVerificationKey > &honk_vk, const std::shared_ptr< Transcript > &transcript)
TraceSettings trace_settings
std::deque< VerifierInputs > VerificationQueue
std::shared_ptr< Transcript > prover_accumulation_transcript
ExecutionTraceUsageTracker trace_usage_tracker
std::deque< StdlibVerifierInputs > StdlibVerificationQueue
HonkProof construct_decider_proof(const std::shared_ptr< Transcript > &transcript)
Internal method for constructing a decider proof.
std::shared_ptr< DeciderVerificationKey > recursive_verifier_native_accum
bool prove_and_verify()
Construct and verify a proof for the IVC.
QUEUE_TYPE get_queue_type() const
Get queue type for the proof of a circuit about to be accumulated based on num circuits accumulated s...
VerificationKey get_vk() const
size_t num_circuits
void accumulate(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &precomputed_vk)
Perform prover work for accumulation (e.g. PG folding, merge proving)
void complete_kernel_circuit_logic(ClientCircuit &circuit)
Append logic to complete a kernel circuit.
Flavor::Curve::AffineElement Point
HonkProof construct_pg_proof(const std::shared_ptr< DeciderProvingKey > &proving_key, const std::shared_ptr< MegaVerificationKey > &honk_vk, const std::shared_ptr< Transcript > &transcript, bool is_kernel)
size_t get_num_circuits() const
size_t num_circuits_accumulated
void update_native_verifier_accumulator(const VerifierInputs &queue_entry, const std::shared_ptr< Transcript > &verifier_transcript)
Runs either Oink or PG native verifier to update the native verifier accumulator.
static std::shared_ptr< RecursiveDeciderVerificationKey > perform_pg_recursive_verification(ClientCircuit &circuit, const std::shared_ptr< RecursiveDeciderVerificationKey > &verifier_accumulator, const std::shared_ptr< RecursiveDeciderVerificationKey > &verifier_instance, const std::shared_ptr< RecursiveTranscript > &transcript, const StdlibProof &proof, std::optional< StdlibFF > &prev_accum_hash, bool is_kernel)
stdlib::Proof< ClientCircuit > StdlibProof
static std::shared_ptr< RecursiveDeciderVerificationKey > perform_oink_recursive_verification(ClientCircuit &circuit, const std::shared_ptr< RecursiveDeciderVerificationKey > &verifier_instance, const std::shared_ptr< RecursiveTranscript > &transcript, const StdlibProof &proof)
VerificationQueue verification_queue
std::vector< FF > FoldProof
std::tuple< std::shared_ptr< RecursiveDeciderVerificationKey >, PairingPoints, TableCommitments > perform_recursive_verification_and_databus_consistency_checks(ClientCircuit &circuit, const StdlibVerifierInputs &verifier_inputs, const std::shared_ptr< RecursiveDeciderVerificationKey > &input_verifier_accumulator, const TableCommitments &T_prev_commitments, const std::shared_ptr< RecursiveTranscript > &accumulation_recursive_transcript)
Populate the provided circuit with constraints for (1) recursive verification of the provided accumul...
StdlibVerificationQueue stdlib_verification_queue
MegaCircuitBuilder ClientCircuit
HonkProof decider_proof
ProverFoldOutput fold_output
std::array< RecursiveFlavor::Commitment, ClientCircuit::NUM_WIRES > TableCommitments
std::shared_ptr< DeciderVerificationKey > native_verifier_accum
std::shared_ptr< Transcript > transcript
static bool verify(const Proof &proof, const VerificationKey &vk)
void instantiate_stdlib_verification_queue(ClientCircuit &circuit, const std::vector< std::shared_ptr< RecursiveVKAndHash > > &input_keys={})
Instantiate a stdlib verification queue for use in the kernel completion logic.
HonkProof construct_mega_proof_for_hiding_kernel(ClientCircuit &circuit)
Construct a zero-knowledge proof for the hiding circuit, which recursively verifies the last folding,...
RecursiveFlavor::FF StdlibFF
std::shared_ptr< MegaVerificationKey > honk_vk
DataBusDepot bus_depot
stdlib::recursion::PairingPoints< ClientCircuit > PairingPoints
CommitmentKey object over a pairing group 𝔾₁.
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
The DeciderVerificationKey encapsulates all the necessary information for a Mega Honk Verifier to ver...
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
static constexpr size_t PUBLIC_INPUTS_SIZE
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
Container for all witness polynomials used/constructed by the prover.
Curve::ScalarField FF
static constexpr size_t VIRTUAL_LOG_N
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
The recursive counterpart to the "native" Mega flavor.
bb::BaseTranscript< bb::stdlib::recursion::honk::StdlibTranscriptParams< CircuitBuilder > > Transcript
typename Curve::ScalarField FF
VKAndHash_< FF, VerificationKey > VKAndHash
MegaFlavor::WitnessEntities< Commitment > WitnessCommitments
A container for the witness commitments.
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=MegaFlavor::VIRTUAL_LOG_N)
A wrapper class for deserializing objects from the public inputs of a circuit.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
Manages the data that is propagated on the public inputs of an application/function circuit.
Manages the data that is propagated on the public inputs of a hiding kernel circuit.
Manages the data that is propagated on the public inputs of a kernel circuit.
The stdlib counterpart of DeciderVerificationKey, used in recursive folding verification.
uint8_t buffer[RANDOM_BUFFER_SIZE]
Definition engine.cpp:34
UltraKeccakFlavor::VerificationKey VerificationKey
DefaultIO< MegaCircuitBuilder > AppIO
The data that is propagated on the public inputs of an application/function circuit.
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
Definition proof.hpp:15
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
BaseTranscript< NativeTranscriptParams > NativeTranscript
VerifierCommitmentKey< Curve > vk
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
A full proof for the IVC scheme containing a Mega proof showing correctness of the hiding circuit (wh...
static constexpr const char * MSGPACK_SCHEMA_NAME
void to_file_msgpack(const std::string &filename) const
static Proof from_msgpack_buffer(uint8_t const *&buffer)
std::vector< FF > to_field_elements() const
Serialize proof to field elements.
uint8_t * to_msgpack_heap_buffer() const
Very quirky method to convert a msgpack buffer to a "heap" buffer.
static constexpr size_t PROOF_LENGTH(size_t virtual_log_n=MegaZKFlavor::VIRTUAL_LOG_N)
The size of a ClientIVC proof with backend-added public inputs: HidingKernelIO.
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=MegaZKFlavor::VIRTUAL_LOG_N)
The size of a ClientIVC proof without backend-added public inputs.
size_t size() const
static Proof from_file_msgpack(const std::string &filename)
msgpack::sbuffer to_msgpack_buffer() const
GoblinProof goblin_proof
bool operator==(const Proof &other) const =default
MSGPACK_FIELDS(mega_proof, goblin_proof)
std::shared_ptr< RecursiveVKAndHash > honk_vk_and_hash
std::shared_ptr< ECCVMVerificationKey > eccvm
MSGPACK_FIELDS(mega, eccvm, translator)
std::shared_ptr< MegaVerificationKey > mega
std::shared_ptr< TranslatorVerificationKey > translator
std::shared_ptr< MegaVerificationKey > honk_vk
Tracks the cumulative usage of the execution trace across a series of circuits.
The result of running the Protogalaxy prover containing a new accumulator as well as the proof data t...
An object storing two EC points that represent the inputs to a pairing check.