22 : num_circuits(num_circuits)
23 , goblin(bn254_commitment_key)
29 info(
"BN254 commitment key size: ", commitment_key_size);
44 const std::vector<std::shared_ptr<RecursiveVKAndHash>>& input_keys)
46 bool vkeys_provided = !input_keys.empty();
50 "Incorrect number of verification keys provided in "
51 "stdlib verification queue instantiation.");
62 std::shared_ptr<RecursiveVKAndHash> stdlib_vk_and_hash;
64 stdlib_vk_and_hash = input_keys[key_idx++];
118 prev_accum_hash = input_verifier_accumulator->hash_with_origin_tagging(
"", *accumulation_recursive_transcript);
122 switch (verifier_inputs.
type) {
124 vinfo(
"Recursively verifying accumulation of the first app circuit.");
125 BB_ASSERT_EQ(input_verifier_accumulator.has_value(),
false);
127 auto [_, new_verifier_accumulator] =
129 output_verifier_accumulator =
std::move(new_verifier_accumulator);
137 vinfo(
"Recursively verifying inner accumulation.");
138 auto [_first_verified, _second_verified, new_verifier_accumulator] =
140 output_verifier_accumulator =
std::move(new_verifier_accumulator);
144 vinfo(
"Recursively verifying accumulation of the tail kernel.");
147 auto [_first_verified, _second_verified, final_verifier_accumulator] =
152 pairing_points.emplace_back(decider_verifier.
verify_proof(final_verifier_accumulator, stdlib_decider_proof));
154 BB_ASSERT_EQ(output_verifier_accumulator.has_value(),
false);
158 throw_or_abort(
"Invalid queue type! Only OINK, HN, HN_TAIL and HN_FINAL are supported");
173 kernel_input.
kernel_return_data.incomplete_assert_equal(witness_commitments.calldata);
174 kernel_input.
app_return_data.incomplete_assert_equal(witness_commitments.secondary_calldata);
183 "Kernel circuits should be folded.");
203 merge_commitments.t_commitments = witness_commitments.
get_ecc_op_wires().get_copy();
206 auto [merge_pairing_points, merged_table_commitments] =
208 pairing_points.emplace_back(merge_pairing_points);
210 return { output_verifier_accumulator, pairing_points, merged_table_commitments };
234 bool is_init_kernel =
237 bool is_tail_kernel =
240 bool is_hiding_kernel =
247 if (is_tail_kernel) {
250 "tail kernel ecc ops table should be empty at this point");
264 if (!is_init_kernel) {
265 current_stdlib_verifier_accumulator = RecursiveVerifierAccumulator::stdlib_from_native<RecursiveFlavor::Curve>(
271 auto [output_stdlib_verifier_accumulator, pairing_points, merged_table_commitments] =
274 current_stdlib_verifier_accumulator,
276 accumulation_recursive_transcript);
277 points_accumulator.insert(points_accumulator.end(), pairing_points.begin(), pairing_points.end());
279 T_prev_commitments = merged_table_commitments;
281 current_stdlib_verifier_accumulator = output_stdlib_verifier_accumulator;
290 if (is_hiding_kernel) {
291 BB_ASSERT_EQ(current_stdlib_verifier_accumulator.has_value(),
false);
298 T_prev_commitments };
299 hiding_output.set_public();
301 BB_ASSERT_NEQ(current_stdlib_verifier_accumulator.has_value(),
false);
309 kernel_output.ecc_op_tables = T_prev_commitments;
311 kernel_output.output_hn_accum_hash =
312 current_stdlib_verifier_accumulator->hash_with_origin_tagging(
"", hash_transcript);
313 info(
"Kernel output accumulator hash: ", kernel_output.output_hn_accum_hash);
315 info(
"Chonk recursive verification: accumulator hash set in the public inputs matches the one "
316 "computed natively: ",
319 kernel_output.set_public();
366 BB_ASSERT(precomputed_vk !=
nullptr,
"Chonk::accumulate - VK expected for the provided circuit");
397 auto verifier_transcript =
405 switch (queue_type) {
407 vinfo(
"Accumulating first app circuit");
408 BB_ASSERT_EQ(is_kernel,
false,
"First circuit accumulated must always be an app");
419 vinfo(
"Accumulating tail kernel");
426 vinfo(
"Generating proof for hiding kernel");
430 prover_instance.reset();
535 auto [mega_verified, kernel_return_data, T_prev_commitments] =
536 verifier.template verify_proof<bb::HidingKernelIO>(proof.
mega_proof);
537 vinfo(
"Mega verified: ", mega_verified);
539 bool databus_consistency_verified = kernel_return_data == verifier.verifier_instance->witness_commitments.calldata;
540 vinfo(
"Databus consistency verified: ", databus_consistency_verified);
542 TableCommitments t_commitments = verifier.verifier_instance->witness_commitments.get_ecc_op_wires().get_copy();
547 vinfo(
"Goblin verified: ", goblin_verified);
550 return goblin_verified && mega_verified && databus_consistency_verified;
563 proof.insert(proof.end(), mega_proof.begin(), mega_proof.end());
564 proof.insert(proof.end(), goblin_proof.merge_proof.begin(), goblin_proof.merge_proof.end());
565 proof.insert(proof.end(), goblin_proof.eccvm_proof.begin(), goblin_proof.eccvm_proof.end());
566 proof.insert(proof.end(), goblin_proof.ipa_proof.begin(), goblin_proof.ipa_proof.end());
567 proof.insert(proof.end(), goblin_proof.translator_proof.begin(), goblin_proof.translator_proof.end());
579 auto start_idx = fields.begin();
583 mega_proof.insert(mega_proof.end(), start_idx, end_idx);
605 return { mega_proof, goblin_proof };
611 msgpack::pack(
buffer, *
this);
617 msgpack::sbuffer
buffer = to_msgpack_buffer();
625 auto uint8_buffer = from_buffer<std::vector<uint8_t>>(
buffer);
627 msgpack::sbuffer sbuf;
628 sbuf.write(
reinterpret_cast<char*
>(uint8_buffer.data()), uint8_buffer.size());
630 return from_msgpack_buffer(sbuf);
635 msgpack::object_handle oh = msgpack::unpack(
buffer.data(),
buffer.size());
636 msgpack::object obj = oh.get();
644 msgpack::sbuffer
buffer = to_msgpack_buffer();
645 std::ofstream ofs(filename, std::ios::binary);
646 if (!ofs.is_open()) {
655 std::ifstream ifs(filename, std::ios::binary);
656 if (!ifs.is_open()) {
660 ifs.seekg(0, std::ios::end);
661 size_t file_size =
static_cast<size_t>(ifs.tellg());
662 ifs.seekg(0, std::ios::beg);
667 msgpack::sbuffer msgpack_buffer;
668 msgpack_buffer.write(
buffer.data(), file_size);
679 return { verification_key,
686 const std::shared_ptr<Transcript>& verifier_transcript)
688 info(
"======= DEBUGGING INFO FOR NATIVE FOLDING STEP =======");
694 auto [_first_verified, new_accumulator] =
698 info(
"Sumcheck: instance to accumulator verified: ", _first_verified ?
"true" :
"false");
700 auto [_first_verified, _second_verified, new_accumulator] =
704 info(
"Sumcheck: instance to accumulator verified: ", _first_verified ?
"true" :
"false");
705 info(
"Sumcheck: batch two accumulators verified: ", _second_verified ?
"true" :
"false");
712 info(
"Decider: pairing points verified? ", pairing_points.
check() ?
"true" :
"false");
720 info(
"Chonk accumulate: prover and verifier accumulators match: ",
724 info(
"======= END OF DEBUGGING INFO FOR NATIVE FOLDING STEP =======");
731 info(
"======= DEBUGGING INFO FOR INCOMING CIRCUIT =======");
735 info(
"Did we find a failure? ", circuit.
failed() ?
"true" :
"false");
737 info(
"\t\t\tError message? ", circuit.
err());
742 info(
"Does the precomputed vk match with the one generated during accumulation? ",
743 vk->compare(*precomputed_vk) ?
"true" :
"false");
745 info(
"======= END OF DEBUGGING INFO FOR INCOMING CIRCUIT =======");
#define BB_ASSERT(expression,...)
#define BB_ASSERT_GT(left, right,...)
#define BB_ASSERT_NEQ(actual, expected,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LT(left, right,...)
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.
ProverAccumulator prover_accumulator
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_honk_proof_for_hiding_kernel(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &verification_key)
Construct a zero-knowledge proof for the Hiding kernel, which recursively verifies the last folding,...
void complete_kernel_circuit_logic(ClientCircuit &circuit)
Append logic to complete a kernel circuit.
std::tuple< std::optional< RecursiveVerifierAccumulator >, std::vector< PairingPoints >, TableCommitments > perform_recursive_verification_and_databus_consistency_checks(ClientCircuit &circuit, const StdlibVerifierInputs &verifier_inputs, const std::optional< RecursiveVerifierAccumulator > &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...
VerifierAccumulator native_verifier_accum
Chonk(size_t num_circuits)
void update_native_verifier_accumulator(const VerifierInputs &queue_entry, const std::shared_ptr< Transcript > &verifier_transcript)
Update native verifier accumulator. Useful for debugging.
Proof prove()
Construct a proof for the IVC, which, if verified, fully establishes its correctness.
static void hide_op_queue_content_in_hiding(ClientCircuit &circuit)
Adds two random non-ops to the hiding kernel for zero-knowledge.
std::array< RecursiveFlavor::Commitment, ClientCircuit::NUM_WIRES > TableCommitments
std::shared_ptr< Transcript > transcript
size_t num_circuits_accumulated
void debug_incoming_circuit(ClientCircuit &circuit, const std::shared_ptr< ProverInstance > &prover_instance, const std::shared_ptr< MegaVerificationKey > &precomputed_vk)
FF native_verifier_accum_hash
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...
static void hide_op_queue_content_in_tail(ClientCircuit &circuit)
Adds three random non-ops to the tail kernel for zero-knowledge.
FoldingProver::Accumulator ProverAccumulator
VerifierAccumulator recursive_verifier_native_accum
static void hide_op_queue_accumulation_result(ClientCircuit &circuit)
Add a hiding op with fully random Px, Py field elements to prevent information leakage in Translator ...
MegaFlavor::CommitmentKey bn254_commitment_key
void accumulate(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &precomputed_vk) override
Perform prover work for accumulation (e.g. HN folding, merge proving)
VerificationKey get_vk() const
VerificationQueue verification_queue
std::shared_ptr< Transcript > prover_accumulation_transcript
static bool verify(const Proof &proof, const VerificationKey &vk)
StdlibVerificationQueue stdlib_verification_queue
const std::string & err() const
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
HonkProof construct_proof(const CommitmentKey &ck, Accumulator &accumulator)
PairingPoints verify_proof(Accumulator &accumulator, const Proof &proof)
HonkProof export_proof()
Export the proof contained in the transcript.
std::pair< HonkProof, Accumulator > fold(const Accumulator &accumulator, const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Fold an instance into an accumulator. Folding happens in place.
Accumulator instance_to_accumulator(const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Turn an instance into an accumulator by running Sumcheck.
std::tuple< bool, bool, Accumulator > verify_folding_proof(const std::shared_ptr< typename HypernovaFoldingVerifier::VerifierInstance > &instance, const Proof &proof)
Verify folding proof. Return the new accumulator and the results of the two sumchecks.
std::pair< bool, Accumulator > instance_to_accumulator(const std::shared_ptr< VerifierInstance > &instance, const Proof &proof)
Turn an instance into an accumulator by executing sumcheck.
void queue_ecc_random_op()
Mechanism for populating two rows with randomness. This "operation" doesn't return a tuple representi...
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.
void queue_ecc_hiding_op(const curve::BN254::BaseField &Px, const curve::BN254::BaseField &Py)
Add a hiding op with random (possibly non-curve) Px, Py values to the op queue and circuit.
Container for all witness polynomials used/constructed by the prover.
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=VIRTUAL_LOG_N)
static constexpr size_t VIRTUAL_LOG_N
An object storing two EC points that represent the inputs to a pairing check.
bool check() const
Perform the pairing check.
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
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
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 kernel (whi...
void to_file_msgpack(const std::string &filename) const
static Proof from_msgpack_buffer(uint8_t const *&buffer)
static Proof from_file_msgpack(const std::string &filename)
static constexpr size_t PROOF_LENGTH(size_t virtual_log_n=MegaZKFlavor::VIRTUAL_LOG_N)
The size of a Chonk proof with backend-added public inputs: HidingKernelIO.
static Proof from_field_elements(const std::vector< Chonk::FF > &fields)
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.
msgpack::sbuffer to_msgpack_buffer() const
HonkProof translator_proof
bool compare_with_verifier_claim(const MultilinearBatchingVerifierClaim< curve::BN254 > &verifier_claim)
An object storing two EC points that represent the inputs to a pairing check.
static PairingPoints aggregate_multiple(std::vector< PairingPoints > &pairing_points)
Aggregate multiple PairingPoints.
void throw_or_abort(std::string const &err)
curve::BN254::BaseField Fq