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 : public IVCBase {
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
61
71
81
82 // Merge commitments
84
92 struct Proof {
95
102 static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n = MegaZKFlavor::VIRTUAL_LOG_N)
103 {
104 return /*mega_proof*/ MegaZKFlavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS(virtual_log_n) +
105 /*merge_proof*/ MERGE_PROOF_SIZE +
106 /*eccvm pre-ipa proof*/ (ECCVMFlavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS - IPA_PROOF_LENGTH) +
107 /*eccvm ipa proof*/ IPA_PROOF_LENGTH +
109 }
110
117 static constexpr size_t PROOF_LENGTH(size_t virtual_log_n = MegaZKFlavor::VIRTUAL_LOG_N)
118 {
119 return PROOF_LENGTH_WITHOUT_PUB_INPUTS(virtual_log_n) +
121 }
122
123 size_t size() const;
124
130 std::vector<FF> to_field_elements() const;
131
133
134 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1299): The following msgpack methods are generic
135 // and should leverage some kind of shared msgpack utility.
136 msgpack::sbuffer to_msgpack_buffer() const;
137
145 uint8_t* to_msgpack_heap_buffer() const;
146 static constexpr const char MSGPACK_SCHEMA_NAME[] = "ClientIVCProof";
147
148 class DeserializationError : public std::runtime_error {
149 public:
150 DeserializationError(const std::string& msg)
151 : std::runtime_error(std::string("Client IVC Proof deserialization error: ") + msg)
152 {}
153 };
154
155 static Proof from_msgpack_buffer(uint8_t const*& buffer);
156 static Proof from_msgpack_buffer(const msgpack::sbuffer& buffer);
157
158 void to_file_msgpack(const std::string& filename) const;
159 static Proof from_file_msgpack(const std::string& filename);
160
162 bool operator==(const Proof& other) const = default;
163 };
164
169
179
185 {
186 std::vector<bb::fr> elements;
187
188 auto mega_elements = mega->to_field_elements();
189 elements.insert(elements.end(), mega_elements.begin(), mega_elements.end());
190
191 auto eccvm_elements = eccvm->to_field_elements();
192 elements.insert(elements.end(), eccvm_elements.begin(), eccvm_elements.end());
193
194 auto translator_elements = translator->to_field_elements();
195 elements.insert(elements.end(), translator_elements.begin(), translator_elements.end());
196
197 return elements;
198 }
199
206 {
207 size_t read_idx = 0;
208
210 size_t mega_read = mega->from_field_elements(elements.subspan(read_idx));
211 read_idx += mega_read;
212
214 size_t eccvm_read = eccvm->from_field_elements(elements.subspan(read_idx));
215 read_idx += eccvm_read;
216
218 size_t translator_read = translator->from_field_elements(elements.subspan(read_idx));
219 read_idx += translator_read;
220
221 return read_idx;
222 }
223 };
224
225 // Specifies proof type or equivalently the type of recursive verification to be performed on a given proof
226 enum class QUEUE_TYPE {
227 OINK,
228 PG,
229 PG_FINAL, // the final PG verification, used in hiding kernel
230 PG_TAIL, // used in tail to indicate special handling of merge for ZK
231 MEGA
232 };
233
234 // An entry in the native verification queue
236 std::vector<FF> proof; // oink or PG
239 bool is_kernel = false;
240 };
241 using VerificationQueue = std::deque<VerifierInputs>;
242
243 // An entry in the stdlib verification queue
245 StdlibProof proof; // oink or PG
246 std::shared_ptr<RecursiveVKAndHash> honk_vk_and_hash;
248 bool is_kernel = false;
249 };
250 using StdlibVerificationQueue = std::deque<StdlibVerifierInputs>;
251
252 // Utility for tracking the max size of each block across the full IVC
254
255 private:
256 // Transcript for CIVC prover (shared between Hiding circuit, Merge, ECCVM, and Translator)
257 std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();
258
259 // Transcript to be shared across the folding of K_{i-1} (kernel), A_{i,1} (app), .., A_{i, n}
261
262 size_t num_circuits; // total number of circuits to be accumulated in the IVC
263 public:
264 size_t num_circuits_accumulated = 0; // number of circuits accumulated so far
265
266 std::shared_ptr<ProverInstance> prover_accumulator; // current PG prover accumulator instance
267 HonkProof decider_proof; // decider proof to be verified in the hiding circuit
268
269 std::shared_ptr<VerifierInstance>
270 recursive_verifier_native_accum; // native verifier accumulator used in recursive folding
271 std::shared_ptr<VerifierInstance> native_verifier_accum; // native verifier accumulator used in prover folding
272
273 // Set of tuples {proof, verification_key, type (Oink/PG)} to be recursively verified
275 // Set of tuples {stdlib_proof, stdlib_verification_key, type} corresponding to the native verification queue
277
278 // Management of linking databus commitments between circuits in the IVC
280
281 // Settings related to the use of fixed block sizes for each gate in the execution trace
283
285
287
288 size_t get_num_circuits() const { return num_circuits; }
289
290 // IVCBase interface
291 Goblin& get_goblin() override { return goblin; }
292 const Goblin& get_goblin() const override { return goblin; }
293
295
297 const std::vector<std::shared_ptr<RecursiveVKAndHash>>& input_keys = {});
298
299 [[nodiscard("Pairing points should be accumulated")]] std::
302 ClientCircuit& circuit,
303 const StdlibVerifierInputs& verifier_inputs,
304 const std::shared_ptr<RecursiveVerifierInstance>& input_verifier_accumulator,
305 const TableCommitments& T_prev_commitments,
306 const std::shared_ptr<RecursiveTranscript>& accumulation_recursive_transcript);
307
308 // Complete the logic of a kernel circuit (e.g. PG/merge recursive verification, databus consistency checks)
310
319 void accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVerificationKey>& precomputed_vk) override;
320
321 Proof prove();
322
324 static void hide_op_queue_content_in_tail(ClientCircuit& circuit);
326
327 static bool verify(const Proof& proof, const VerificationKey& vk);
328
329 HonkProof construct_decider_proof(const std::shared_ptr<Transcript>& transcript);
330
331 VerificationKey get_vk() const;
332
333 private:
340 void update_native_verifier_accumulator(const VerifierInputs& queue_entry,
341 const std::shared_ptr<Transcript>& verifier_transcript);
342
343 HonkProof construct_oink_proof(const std::shared_ptr<ProverInstance>& prover_instance,
345 const std::shared_ptr<Transcript>& transcript);
346
347 HonkProof construct_pg_proof(const std::shared_ptr<ProverInstance>& prover_instance,
349 const std::shared_ptr<Transcript>& transcript,
350 bool is_kernel);
351
353 const std::shared_ptr<MegaVerificationKey>& verification_key);
354
356
358 ClientCircuit& circuit,
359 const std::shared_ptr<RecursiveVerifierInstance>& verifier_instance,
361 const StdlibProof& proof);
362
364 ClientCircuit& circuit,
365 const std::shared_ptr<RecursiveVerifierInstance>& verifier_accumulator,
366 const std::shared_ptr<RecursiveVerifierInstance>& verifier_instance,
368 const StdlibProof& proof,
369 std::optional<StdlibFF>& prev_accum_hash,
370 bool is_kernel);
371};
372
373// Serialization methods for ClientIVC::VerificationKey
374inline void read(uint8_t const*& it, ClientIVC::VerificationKey& vk)
375{
376 using serialize::read;
377
378 size_t num_frs = ClientIVC::VerificationKey::calc_num_data_types();
379
380 // Read exactly num_frs field elements from the buffer
381 std::vector<bb::fr> field_elements(num_frs);
382 for (auto& element : field_elements) {
383 read(it, element);
384 }
385
386 // Then use from_field_elements to populate the verification key
387 vk.from_field_elements(field_elements);
388}
389
390inline void write(std::vector<uint8_t>& buf, ClientIVC::VerificationKey const& vk)
391{
392 using serialize::write;
393
394 // Convert to field elements and write them directly without length prefix
395 auto field_elements = vk.to_field_elements();
396 for (const auto& element : field_elements) {
397 write(buf, element);
398 }
399}
400
401} // 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 valid operation with random data to the op queue to prevent information leakage in Translator p...
static void hide_op_queue_content_in_tail(ClientCircuit &circuit)
Adds three random ops to the tail kernel.
MegaFlavor::CommitmentKey bn254_commitment_key
TraceSettings trace_settings
std::deque< VerifierInputs > VerificationQueue
std::shared_ptr< Transcript > prover_accumulation_transcript
ExecutionTraceUsageTracker trace_usage_tracker
HonkProof construct_honk_proof_for_hiding_kernel(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &verification_key)
Construct a zero-knowledge proof for the hiding circuit, which recursively verifies the last folding,...
std::deque< StdlibVerifierInputs > StdlibVerificationQueue
std::shared_ptr< VerifierInstance > recursive_verifier_native_accum
HonkProof construct_decider_proof(const std::shared_ptr< Transcript > &transcript)
Internal method for constructing a decider proof.
std::shared_ptr< ProverInstance > prover_accumulator
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
Goblin & get_goblin() override
std::tuple< std::shared_ptr< RecursiveVerifierInstance >, PairingPoints, TableCommitments > perform_recursive_verification_and_databus_consistency_checks(ClientCircuit &circuit, const StdlibVerifierInputs &verifier_inputs, const std::shared_ptr< RecursiveVerifierInstance > &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...
static void hide_op_queue_content_in_hiding(ClientCircuit &circuit)
Adds two random ops to the hiding kernel.
static std::shared_ptr< RecursiveVerifierInstance > perform_oink_recursive_verification(ClientCircuit &circuit, const std::shared_ptr< RecursiveVerifierInstance > &verifier_instance, const std::shared_ptr< RecursiveTranscript > &transcript, const StdlibProof &proof)
size_t num_circuits
void complete_kernel_circuit_logic(ClientCircuit &circuit)
Append logic to complete a kernel circuit.
Flavor::Curve::AffineElement Point
void accumulate(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &precomputed_vk) override
Perform prover work for accumulation (e.g. PG folding, merge proving)
HonkProof construct_pg_proof(const std::shared_ptr< ProverInstance > &prover_instance, 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.
const Goblin & get_goblin() const override
stdlib::Proof< ClientCircuit > StdlibProof
VerificationQueue verification_queue
HonkProof construct_oink_proof(const std::shared_ptr< ProverInstance > &prover_instance, const std::shared_ptr< MegaVerificationKey > &honk_vk, const std::shared_ptr< Transcript > &transcript)
std::vector< FF > FoldProof
std::shared_ptr< VerifierInstance > native_verifier_accum
StdlibVerificationQueue stdlib_verification_queue
MegaCircuitBuilder ClientCircuit
HonkProof decider_proof
std::array< RecursiveFlavor::Commitment, ClientCircuit::NUM_WIRES > TableCommitments
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.
RecursiveFlavor::FF StdlibFF
DataBusDepot bus_depot
stdlib::recursion::PairingPoints< ClientCircuit > PairingPoints
static std::shared_ptr< RecursiveVerifierInstance > perform_pg_recursive_verification(ClientCircuit &circuit, const std::shared_ptr< RecursiveVerifierInstance > &verifier_accumulator, const std::shared_ptr< RecursiveVerifierInstance > &verifier_instance, const std::shared_ptr< RecursiveTranscript > &transcript, const StdlibProof &proof, std::optional< StdlibFF > &prev_accum_hash, bool is_kernel)
CommitmentKey object over a pairing group 𝔾₁.
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
Base class interface for IVC schemes.
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.
StdlibTranscript< 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)
static size_t calc_num_data_types()
Calculate the number of field elements needed for serialization.
Definition flavor.hpp:181
Verifier class for all the presumcheck rounds, which are shared between the folding verifier and ultr...
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
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
The VerifierInstance encapsulates all the necessary information for a Mega Honk Verifier to verify a ...
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 VerifierInstance, used in recursive folding verification.
uint8_t const * buf
Definition data_store.hpp:9
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
void write(std::vector< uint8_t > &buf, ClientIVC::VerificationKey const &vk)
void read(uint8_t const *&it, ClientIVC::VerificationKey &vk)
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
VerifierCommitmentKey< Curve > vk
void read(auto &it, msgpack_concepts::HasMsgPack auto &obj)
Automatically derived read for any object that defines .msgpack() (implicitly defined by MSGPACK_FIEL...
void write(auto &buf, const msgpack_concepts::HasMsgPack auto &obj)
Automatically derived write for any object that defines .msgpack() (implicitly defined by MSGPACK_FIE...
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
static Proof from_field_elements(const std::vector< ClientIVC::FF > &fields)
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
std::vector< bb::fr > to_field_elements() const
Serialize verification key to field elements.
size_t from_field_elements(std::span< const bb::fr > elements)
Deserialize verification key from field elements.
std::shared_ptr< MegaVerificationKey > mega
static size_t calc_num_data_types()
Calculate the number of field elements needed for serialization.
std::shared_ptr< TranslatorVerificationKey > translator
std::shared_ptr< MegaVerificationKey > honk_vk
Tracks the cumulative usage of the execution trace across a series of circuits.
An object storing two EC points that represent the inputs to a pairing check.