-
Notifications
You must be signed in to change notification settings - Fork 599
chore: Merge is part of verification queue #12612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b7779a
Rough moving of merge in main verification queue
ledwards2225 1b8ca24
bug fix and reinstate tests
ledwards2225 6093938
Merge branch 'master' into lde/incorporate_merge_in_queue
ledwards2225 0fd2222
uncommment test suite
ledwards2225 3a8b0c1
dont run nonsensical ivc tests
ledwards2225 f74245e
clean out goblin a bit
ledwards2225 f4e92eb
store merge proof in goblin for use in tests
ledwards2225 c93e6e2
clean out stuff related to one_circuit functionality
ledwards2225 60f68c2
minor cleanup and tagging todos
ledwards2225 2c18450
use verifier inputs directly
ledwards2225 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,15 +23,16 @@ void ClientIVC::instantiate_stdlib_verification_queue( | |
| } | ||
|
|
||
| size_t key_idx = 0; | ||
| for (auto& [proof, vkey, type] : verification_queue) { | ||
| for (auto& [proof, merge_proof, vkey, type] : verification_queue) { | ||
ledwards2225 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Construct stdlib proof directly from the internal native queue data | ||
| auto stdlib_proof = bb::convert_native_proof_to_stdlib(&circuit, proof); | ||
| auto stdlib_merge_proof = bb::convert_native_proof_to_stdlib(&circuit, merge_proof); | ||
|
|
||
| // Use the provided stdlib vkey if present, otherwise construct one from the internal native queue | ||
| auto stdlib_vkey = | ||
| vkeys_provided ? input_keys[key_idx++] : std::make_shared<RecursiveVerificationKey>(&circuit, vkey); | ||
|
|
||
| stdlib_verification_queue.push_back({ stdlib_proof, stdlib_vkey, type }); | ||
| stdlib_verification_queue.push_back({ stdlib_proof, stdlib_merge_proof, stdlib_vkey, type }); | ||
| } | ||
| verification_queue.clear(); // the native data is not needed beyond this point | ||
| } | ||
|
|
@@ -43,28 +44,23 @@ void ClientIVC::instantiate_stdlib_verification_queue( | |
| * case, the verifier accumulator is updated in place via the verification algorithm. Databus commitment consistency | ||
| * checks are performed on the witness commitments and public inputs extracted from the proof by the verifier. | ||
| * | ||
| * @param circuit The circuit to which the constraints are appended | ||
| * @param proof A stdlib proof to be recursively verified (either oink or PG) | ||
| * @param vkey The stdlib verification key associated with the proof | ||
| * @param type The type of the proof (equivalently, the type of the verifier) | ||
| * @param circuit | ||
| * @param verifier_inputs {proof, merge_proof, vkey, type (Oink/PG)} A set of inputs for recursive verification | ||
| */ | ||
| void ClientIVC::perform_recursive_verification_and_databus_consistency_checks( | ||
| ClientCircuit& circuit, | ||
| const StdlibProof<ClientCircuit>& proof, | ||
| const std::shared_ptr<RecursiveVerificationKey>& vkey, | ||
| const QUEUE_TYPE type) | ||
| ClientCircuit& circuit, const StdlibVerifierInputs& verifier_inputs) | ||
| { | ||
| // Store the decider vk for the incoming circuit; its data is used in the databus consistency checks below | ||
| std::shared_ptr<RecursiveDeciderVerificationKey> decider_vk; | ||
|
|
||
| switch (type) { | ||
| switch (verifier_inputs.type) { | ||
| case QUEUE_TYPE::PG: { | ||
| // Construct stdlib verifier accumulator from the native counterpart computed on a previous round | ||
| auto stdlib_verifier_accum = std::make_shared<RecursiveDeciderVerificationKey>(&circuit, verifier_accumulator); | ||
|
|
||
| // Perform folding recursive verification to update the verifier accumulator | ||
| FoldingRecursiveVerifier verifier{ &circuit, stdlib_verifier_accum, { vkey } }; | ||
| auto verifier_accum = verifier.verify_folding_proof(proof); | ||
| FoldingRecursiveVerifier verifier{ &circuit, stdlib_verifier_accum, { verifier_inputs.honk_verification_key } }; | ||
| auto verifier_accum = verifier.verify_folding_proof(verifier_inputs.proof); | ||
|
|
||
| // Extract native verifier accumulator from the stdlib accum for use on the next round | ||
| verifier_accumulator = std::make_shared<DeciderVerificationKey>(verifier_accum->get_value()); | ||
|
|
@@ -75,11 +71,12 @@ void ClientIVC::perform_recursive_verification_and_databus_consistency_checks( | |
| } | ||
| case QUEUE_TYPE::OINK: { | ||
| // Construct an incomplete stdlib verifier accumulator from the corresponding stdlib verification key | ||
| auto verifier_accum = std::make_shared<RecursiveDeciderVerificationKey>(&circuit, vkey); | ||
| auto verifier_accum = | ||
| std::make_shared<RecursiveDeciderVerificationKey>(&circuit, verifier_inputs.honk_verification_key); | ||
|
|
||
| // Perform oink recursive verification to complete the initial verifier accumulator | ||
| OinkRecursiveVerifier oink{ &circuit, verifier_accum }; | ||
| oink.verify_proof(proof); | ||
| oink.verify_proof(verifier_inputs.proof); | ||
| verifier_accum->is_accumulator = true; // indicate to PG that it should not run oink | ||
|
|
||
| // Extract native verifier accumulator from the stdlib accum for use on the next round | ||
|
|
@@ -93,6 +90,10 @@ void ClientIVC::perform_recursive_verification_and_databus_consistency_checks( | |
| } | ||
| } | ||
|
|
||
| // Recursively verify the merge proof for the circuit being recursively verified | ||
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/950): handle pairing point accumulation | ||
| [[maybe_unused]] auto pairing_points = GoblinVerifier::recursive_verify_merge(circuit, verifier_inputs.merge_proof); | ||
|
|
||
| // Set the return data commitment to be propagated on the public inputs of the present kernel and perform | ||
| // consistency checks between the calldata commitments and the return data commitments contained within the public | ||
| // inputs | ||
|
|
@@ -104,20 +105,6 @@ void ClientIVC::perform_recursive_verification_and_databus_consistency_checks( | |
| decider_vk->verification_key->databus_propagation_data); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Perform recursive merge verification for each merge proof in the queue | ||
| * | ||
| * @param circuit | ||
| */ | ||
| void ClientIVC::process_recursive_merge_verification_queue(ClientCircuit& circuit) | ||
| { | ||
| // Recusively verify all merge proofs in queue | ||
| for (auto& proof : merge_verification_queue) { | ||
| goblin.verify_merge(circuit, proof); | ||
| } | ||
| merge_verification_queue.clear(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Append logic to complete a kernel circuit | ||
| * @details A kernel circuit may contain some combination of PG recursive verification, merge recursive | ||
|
|
@@ -135,17 +122,14 @@ void ClientIVC::complete_kernel_circuit_logic(ClientCircuit& circuit) | |
| instantiate_stdlib_verification_queue(circuit); | ||
| } | ||
|
|
||
| // Peform recursive verification and databus consistency checks for each entry in the verification queue | ||
| for (auto& [proof, vkey, type] : stdlib_verification_queue) { | ||
| perform_recursive_verification_and_databus_consistency_checks(circuit, proof, vkey, type); | ||
| // Perform recursive verification and databus consistency checks for each entry in the verification queue | ||
| for (auto& verifier_input : stdlib_verification_queue) { | ||
ledwards2225 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| perform_recursive_verification_and_databus_consistency_checks(circuit, verifier_input); | ||
| } | ||
| stdlib_verification_queue.clear(); | ||
|
|
||
| // Propagate return data commitments via the public inputs for use in databus consistency checks | ||
| bus_depot.propagate_return_data_commitments(circuit); | ||
|
|
||
| // Perform recursive merge verification for every merge proof in the queue | ||
| process_recursive_merge_verification_queue(circuit); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -160,13 +144,12 @@ void ClientIVC::complete_kernel_circuit_logic(ClientCircuit& circuit) | |
| * @param precomputed_vk | ||
| */ | ||
| void ClientIVC::accumulate(ClientCircuit& circuit, | ||
| const bool _one_circuit, | ||
| [[maybe_unused]] const bool _one_circuit, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last remnants of this mechanism will be cleaned out by the aforementioned PR from Cody/Adam |
||
| const std::shared_ptr<MegaVerificationKey>& precomputed_vk, | ||
| const bool mock_vk) | ||
| { | ||
| // Construct merge proof for the present circuit and add to merge verification queue | ||
| MergeProof merge_proof = goblin.prove_merge(circuit); | ||
| merge_verification_queue.emplace_back(merge_proof); | ||
|
|
||
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/1069): Do proper aggregation with merge recursive | ||
| // verifier. | ||
|
|
@@ -194,25 +177,12 @@ void ClientIVC::accumulate(ClientCircuit& circuit, | |
| vinfo("set honk vk metadata"); | ||
| } | ||
|
|
||
| if (_one_circuit) { | ||
| // The initial stack consisted of only one circuit, so construct a proof for it. | ||
| one_circuit = _one_circuit; | ||
| MegaProver prover{ proving_key }; | ||
| vinfo("computing mega proof..."); | ||
| mega_proof = prover.prove(); | ||
| vinfo("mega proof computed"); | ||
|
|
||
| proving_key->is_accumulator = true; // indicate to PG that it should not run oink on this key | ||
| // Initialize the gate challenges to zero for use in first round of folding | ||
| proving_key->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0); | ||
|
|
||
| fold_output.accumulator = proving_key; | ||
| } else if (!initialized) { | ||
| if (!initialized) { | ||
| // If this is the first circuit in the IVC, use oink to complete the decider proving key and generate an oink | ||
| // proof | ||
| MegaOinkProver oink_prover{ proving_key }; | ||
| vinfo("computing oink proof..."); | ||
| oink_prover.prove(); | ||
| HonkProof oink_proof = oink_prover.prove(); | ||
| vinfo("oink proof constructed"); | ||
| proving_key->is_accumulator = true; // indicate to PG that it should not run oink on this key | ||
| // Initialize the gate challenges to zero for use in first round of folding | ||
|
|
@@ -221,8 +191,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, | |
| fold_output.accumulator = proving_key; // initialize the prover accum with the completed key | ||
|
|
||
| // Add oink proof and corresponding verification key to the verification queue | ||
| verification_queue.push_back( | ||
| bb::ClientIVC::VerifierInputs{ oink_prover.transcript->proof_data, honk_vk, QUEUE_TYPE::OINK }); | ||
| verification_queue.push_back(VerifierInputs{ oink_proof, merge_proof, honk_vk, QUEUE_TYPE::OINK }); | ||
|
|
||
| initialized = true; | ||
| } else { // Otherwise, fold the new key into the accumulator | ||
|
|
@@ -232,7 +201,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, | |
| vinfo("constructed folding proof"); | ||
|
|
||
| // Add fold proof and corresponding verification key to the verification queue | ||
| verification_queue.push_back(bb::ClientIVC::VerifierInputs{ fold_output.proof, honk_vk, QUEUE_TYPE::PG }); | ||
| verification_queue.push_back(VerifierInputs{ fold_output.proof, merge_proof, honk_vk, QUEUE_TYPE::PG }); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -242,12 +211,12 @@ void ClientIVC::accumulate(ClientCircuit& circuit, | |
| * | ||
| * @details The aim of this intermediate stage is to reduce the cost of producing a zero-knowledge ClientIVCProof. | ||
| * @return HonkProof - a Mega proof | ||
| * @return MergeProof - a Merge proof | ||
| */ | ||
| HonkProof ClientIVC::construct_and_prove_hiding_circuit() | ||
| std::pair<HonkProof, ClientIVC::MergeProof> ClientIVC::construct_and_prove_hiding_circuit() | ||
| { | ||
| trace_usage_tracker.print(); // print minimum structured sizes for each block | ||
| ASSERT(verification_queue.size() == 1); | ||
| ASSERT(merge_verification_queue.size() == 1); // ensure only a single merge proof remains in the queue | ||
|
|
||
| FoldProof& fold_proof = verification_queue[0].proof; | ||
| HonkProof decider_proof = decider_prove(); | ||
|
|
@@ -267,7 +236,11 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() | |
| builder.add_public_variable(fold_proof[i + offset]); | ||
| } | ||
|
|
||
| process_recursive_merge_verification_queue(builder); | ||
| const StdlibProof<ClientCircuit> stdlib_merge_proof = | ||
| bb::convert_native_proof_to_stdlib(&builder, verification_queue[0].merge_proof); | ||
|
|
||
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/950): handle pairing point accumulation | ||
| [[maybe_unused]] auto pairing_points = GoblinVerifier::recursive_verify_merge(builder, stdlib_merge_proof); | ||
|
|
||
| // Construct stdlib accumulator, decider vkey and folding proof | ||
| auto stdlib_verifier_accumulator = | ||
|
|
@@ -291,15 +264,14 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() | |
|
|
||
| // Construct the last merge proof for the present circuit and add to merge verification queue | ||
| MergeProof merge_proof = goblin.prove_merge(builder); | ||
| merge_verification_queue.emplace_back(merge_proof); | ||
|
|
||
| auto decider_pk = std::make_shared<DeciderProvingKey>(builder, TraceSettings(), bn254_commitment_key); | ||
| honk_vk = std::make_shared<MegaVerificationKey>(decider_pk->proving_key); | ||
| MegaProver prover(decider_pk); | ||
|
|
||
| HonkProof proof = prover.construct_proof(); | ||
|
|
||
| return proof; | ||
| return { proof, merge_proof }; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -309,12 +281,8 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() | |
| */ | ||
| ClientIVC::Proof ClientIVC::prove() | ||
| { | ||
| if (!one_circuit) { | ||
| mega_proof = construct_and_prove_hiding_circuit(); | ||
| ASSERT(merge_verification_queue.size() == 1); // ensure only a single merge proof remains in the queue | ||
| } | ||
| auto [mega_proof, merge_proof] = construct_and_prove_hiding_circuit(); | ||
|
|
||
| MergeProof& merge_proof = merge_verification_queue[0]; | ||
| return { mega_proof, goblin.prove(merge_proof) }; | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are going to be removed by this PR from Cody/Adam. They represent test-only functionality that we never had plans to support. (Creating a CIVC proof for a single circuit).