20 : trace_usage_tracker(trace_settings)
21 , num_circuits(num_circuits)
22 , trace_settings(trace_settings)
23 , goblin(bn254_commitment_key)
28 size_t commitment_key_size =
30 info(
"BN254 commitment key size: ", commitment_key_size);
45 ClientCircuit& circuit,
const std::vector<std::shared_ptr<RecursiveVKAndHash>>& input_keys)
47 bool vkeys_provided = !input_keys.empty();
51 "Incorrect number of verification keys provided in "
52 "stdlib verification queue instantiation.");
63 std::shared_ptr<RecursiveVKAndHash> stdlib_vk_and_hash;
65 stdlib_vk_and_hash = input_keys[key_idx++];
86 verifier_instance->target_sum = StdlibFF::from_witness_index(&circuit, circuit.
zero_idx());
88 verifier_instance->gate_challenges =
89 transcript->template get_powers_of_challenge<StdlibFF>(
"gate_challenge", CONST_PG_LOG_N);
91 return verifier_instance;
103 BB_ASSERT_NEQ(verifier_accumulator,
nullptr,
"verifier_accumulator cannot be null in PG recursive verification");
108 prev_accum_hash = verifier_accumulator->hash_through_transcript(
"", *
transcript);
109 transcript->add_to_hash_buffer(
"accum_hash", *prev_accum_hash);
110 info(
"Previous accumulator hash in PG rec verifier: ", *prev_accum_hash);
114 auto updated_verifier_accumulator = verifier.verify_folding_proof(proof);
116 return updated_verifier_accumulator;
151 MergeCommitments merge_commitments{ .T_prev_commitments = T_prev_commitments };
160 switch (verifier_inputs.
type) {
165 circuit, verifier_instance, accumulation_recursive_transcript, verifier_inputs.
proof);
174 input_verifier_accumulator,
176 accumulation_recursive_transcript,
177 verifier_inputs.
proof,
188 input_verifier_accumulator,
190 accumulation_recursive_transcript,
191 verifier_inputs.
proof,
196 decider_pairing_points = decider.verify_proof(
decider_proof);
202 throw_or_abort(
"Invalid queue type! Only OINK, PG, PG_TAIL and PG_FINAL are supported");
208 std::vector<StdlibFF> public_inputs =
std::move(verifier_instance->public_inputs);
218 kernel_input.
kernel_return_data.incomplete_assert_equal(witness_commitments.calldata);
219 kernel_input.
app_return_data.incomplete_assert_equal(witness_commitments.secondary_calldata);
229 "Kernel circuits should be folded.");
232 ASSERT(prev_accum_hash.has_value());
235 if (!is_hiding_kernel) {
250 merge_commitments.t_commitments = witness_commitments.
get_ecc_op_wires().get_copy();
253 auto [pairing_points, merged_table_commitments] =
256 pairing_points.aggregate(nested_pairing_points);
257 if (is_hiding_kernel) {
258 pairing_points.aggregate(decider_pairing_points);
264 return { output_verifier_accumulator, pairing_points, merged_table_commitments };
290 bool is_init_kernel =
293 bool is_tail_kernel =
296 bool is_hiding_kernel =
303 if (is_tail_kernel) {
306 "tail kernel ecc ops table should be empty at this point");
317 if (!is_init_kernel) {
318 current_stdlib_verifier_accumulator =
324 auto [output_stdlib_verifier_accumulator, pairing_points, merged_table_commitments] =
327 current_stdlib_verifier_accumulator,
329 accumulation_recursive_transcript);
330 points_accumulator.
aggregate(pairing_points);
332 T_prev_commitments = merged_table_commitments;
334 current_stdlib_verifier_accumulator = output_stdlib_verifier_accumulator;
339 if (is_hiding_kernel) {
340 BB_ASSERT_EQ(current_stdlib_verifier_accumulator,
nullptr);
341 HidingKernelIO hiding_output{ points_accumulator, T_prev_commitments };
356 current_stdlib_verifier_accumulator->hash_through_transcript(
"", hash_transcript);
364 const std::shared_ptr<Transcript>& transcript)
366 vinfo(
"computing oink proof...");
370 prover_instance->target_sum = 0;
372 prover_instance->gate_challenges =
377 HonkProof oink_proof = oink_prover.export_proof();
378 vinfo(
"oink proof constructed");
384 const std::shared_ptr<Transcript>& transcript,
387 vinfo(
"computing pg proof...");
394 info(
"Accumulator hash in PG prover: ", accum_hash);
401 auto output = folding_prover.
prove();
403 vinfo(
"pg proof constructed");
450 ASSERT(precomputed_vk !=
nullptr,
"ClientIVC::accumulate - VK expected for the provided circuit");
476 auto verifier_transcript =
481 switch (queue_type) {
483 vinfo(
"Accumulating first app circuit with OINK");
484 BB_ASSERT_EQ(is_kernel,
false,
"First circuit accumulated must always be an app");
527 Point random_point = Point::random_element();
645 auto [mega_verified, T_prev_commitments] = verifier.template verify_proof<bb::HidingKernelIO>(proof.
mega_proof);
646 vinfo(
"Mega verified: ", mega_verified);
648 TableCommitments t_commitments = verifier.verifier_instance->witness_commitments.get_ecc_op_wires().get_copy();
653 vinfo(
"Goblin verified: ", goblin_verified);
656 return goblin_verified && mega_verified;
666 vinfo(
"prove decider...");
683 proof.insert(proof.end(), mega_proof.begin(), mega_proof.end());
684 proof.insert(proof.end(), goblin_proof.merge_proof.begin(), goblin_proof.merge_proof.end());
686 proof.end(), goblin_proof.eccvm_proof.pre_ipa_proof.begin(), goblin_proof.eccvm_proof.pre_ipa_proof.end());
687 proof.insert(proof.end(), goblin_proof.eccvm_proof.ipa_proof.begin(), goblin_proof.eccvm_proof.ipa_proof.end());
688 proof.insert(proof.end(), goblin_proof.translator_proof.begin(), goblin_proof.translator_proof.end());
700 auto start_idx = fields.begin();
704 mega_proof.insert(mega_proof.end(), start_idx, end_idx);
726 return { mega_proof, goblin_proof };
732 msgpack::pack(
buffer, *
this);
738 msgpack::sbuffer
buffer = to_msgpack_buffer();
746 auto uint8_buffer = from_buffer<std::vector<uint8_t>>(
buffer);
748 msgpack::sbuffer sbuf;
749 sbuf.write(
reinterpret_cast<char*
>(uint8_buffer.data()), uint8_buffer.size());
751 return from_msgpack_buffer(sbuf);
756 msgpack::object_handle oh = msgpack::unpack(
buffer.data(),
buffer.size());
757 msgpack::object obj = oh.get();
765 msgpack::sbuffer
buffer = to_msgpack_buffer();
766 std::ofstream ofs(filename, std::ios::binary);
767 if (!ofs.is_open()) {
776 std::ifstream ifs(filename, std::ios::binary);
777 if (!ifs.is_open()) {
781 ifs.seekg(0, std::ios::end);
782 size_t file_size =
static_cast<size_t>(ifs.tellg());
783 ifs.seekg(0, std::ios::beg);
788 msgpack::sbuffer msgpack_buffer;
789 msgpack_buffer.write(
buffer.data(), file_size);
800 return { verification_key,
806 const std::shared_ptr<Transcript>& verifier_transcript)
810 verifier_transcript->load_proof(queue_entry.
proof);
817 verifier_transcript->template get_powers_of_challenge<FF>(
"gate_challenge", CONST_PG_LOG_N);
822 verifier_transcript->add_to_hash_buffer(
"accum_hash", accum_hash);
823 info(
"Accumulator hash in PG verifier: ", accum_hash);
#define BB_ASSERT_GT(left, right,...)
#define BB_ASSERT_NEQ(actual, expected,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LT(left, right,...)
#define ASSERT(expression,...)
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
static std::shared_ptr< BaseTranscript > convert_prover_transcript_to_verifier_transcript(const std::shared_ptr< BaseTranscript > &prover_transcript)
Convert a prover transcript to a verifier transcript.
uint32_t zero_idx() const
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::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::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
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)
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 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.
ClientIVC(size_t num_circuits, TraceSettings trace_settings={})
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::shared_ptr< VerifierInstance > native_verifier_accum
StdlibVerificationQueue stdlib_verification_queue
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.
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 𝔾₁.
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
static bool verify(const GoblinProof &proof, const MergeCommitments &merge_commitments, const std::shared_ptr< Transcript > &transcript, const MergeSettings merge_settings=MergeSettings::PREPEND)
Verify a full Goblin proof (ECCVM, Translator, merge)
std::pair< PairingPoints, RecursiveTableCommitments > recursively_verify_merge(MegaBuilder &builder, const RecursiveMergeCommitments &merge_commitments, const std::shared_ptr< RecursiveTranscript > &transcript, const MergeSettings merge_settings=MergeSettings::PREPEND)
Recursively verify the next merge proof in the merge verification queue.
MergeVerifier::TableCommitments TableCommitments
void prove_merge(const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >(), const MergeSettings merge_settings=MergeSettings::PREPEND)
Construct a merge proof for the goblin ECC ops in the provided circuit; append the proof to the merge...
GoblinProof prove(const MergeSettings merge_settings=MergeSettings::PREPEND)
Constuct a full Goblin proof (ECCVM, Translator, merge)
CommitmentKey< curve::BN254 > commitment_key
std::shared_ptr< Transcript > transcript
static constexpr size_t PUBLIC_INPUTS_SIZE
void queue_ecc_random_op()
Mechanism for populating two rows with randomness. This "operation" doesn't return a tuple representi...
ecc_op_tuple queue_ecc_mul_accum(const g1::affine_element &point, const FF &scalar, bool in_finalize=false)
Add point mul-then-accumulate operation to the op queue and add corresponding gates.
std::shared_ptr< ECCOpQueue > op_queue
ecc_op_tuple queue_ecc_eq(bool in_finalize=true)
Add point equality operation to the op queue based on the value of the internal accumulator and add c...
ecc_op_tuple queue_ecc_no_op()
Logic for a no-op operation.
Container for all witness polynomials used/constructed by the prover.
static constexpr size_t VIRTUAL_LOG_N
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=MegaFlavor::VIRTUAL_LOG_N)
Class for all the oink rounds, which are shared between the folding prover and ultra prover.
void prove()
Oink Prover function that runs all the rounds of the verifier.
Verifier class for all the presumcheck rounds, which are shared between the folding verifier and ultr...
void verify()
Oink Verifier function that runs all the rounds of the verifier.
BB_PROFILE FoldingResult< Flavor > prove()
Execute the folding prover.
std::shared_ptr< VerifierInstance > verify_folding_proof(const std::vector< FF > &)
Run the folding protocol on the verifier side to establish whether the public data ϕ of the new accum...
static constexpr size_t CONST_TRANSLATOR_LOG_N
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
Commitment get_kernel_return_data_commitment(Builder &builder)
Get the previously set kernel return data commitment if it exists, else a default one.
Commitment get_app_return_data_commitment(Builder &builder)
Get the previously set app return data commitment if it exists, else a default one.
void set_app_return_data_commitment(const Commitment &commitment)
void set_kernel_return_data_commitment(const Commitment &commitment)
Manages the data that is propagated on the public inputs of an application/function circuit.
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
PairingInputs pairing_inputs
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.
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
PairingInputs pairing_inputs
void set_public()
Set each IO component to be a public input of the underlying circuit.
TableCommitments ecc_op_tables
uint8_t buffer[RANDOM_BUFFER_SIZE]
std::array< typename bn254< Builder >::Group, Builder::NUM_WIRES > empty_ecc_op_tables(Builder &builder)
Construct commitments to empty subtables.
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
uint8_t * to_heap_buffer(T const &value)
A full proof for the IVC scheme containing a Mega proof showing correctness of the hiding circuit (wh...
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 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)
void update(const Builder &circuit)
HonkProof translator_proof
size_t dyadic_size() const
static field random_element(numeric::RNG *engine=nullptr) noexcept
An object storing two EC points that represent the inputs to a pairing check.
void aggregate(PairingPoints const &other)
Compute a linear combination of the present pairing points with an input set of pairing points.
uint32_t set_public()
Set the witness indices for the limbs of the pairing points to public.
void throw_or_abort(std::string const &err)