diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad4c485e1dc..6588dd5fb2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,6 +78,7 @@ jobs: - barretenberg/cpp/pil/** - barretenberg/cpp/src/barretenberg/vm/** - barretenberg/cpp/src/barretenberg/**/generated/* + - barretenberg/cpp/src/barretenberg/client_ivc.{hpp,cpp} non-docs: - '!(docs/**)' non-misc-ci: diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp index e498f348143..a0414baa0f7 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp @@ -17,9 +17,15 @@ void AztecIVC::complete_kernel_circuit_logic(ClientCircuit& circuit) ASSERT(verification_queue.empty() || verification_queue.size() == 2); for (auto& [proof, vkey] : verification_queue) { + + // Construct stdlib accumulator, vkey and proof + auto stdlib_verifier_accum = std::make_shared(&circuit, verifier_accumulator); + auto stdlib_vkey = std::make_shared(&circuit, vkey); + auto stdlib_proof = bb::convert_proof_to_witness(&circuit, proof); + // Perform folding recursive verification - FoldingRecursiveVerifier verifier{ &circuit, { verifier_accumulator, { vkey } } }; - auto verifier_accum = verifier.verify_folding_proof(proof); + FoldingRecursiveVerifier verifier{ &circuit, stdlib_verifier_accum, { stdlib_vkey } }; + auto verifier_accum = verifier.verify_folding_proof(stdlib_proof); verifier_accumulator = std::make_shared(verifier_accum->get_value()); // Perform databus commitment consistency checks and propagate return data commitments via public inputs diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp index eafb711549d..89f29976278 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp @@ -44,6 +44,8 @@ class AztecIVC { using GURecursiveFlavor = MegaRecursiveFlavor_; using RecursiveVerifierInstances = bb::stdlib::recursion::honk::RecursiveVerifierInstances_; + using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; + using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; using FoldingRecursiveVerifier = bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_; diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 6f6bd69f6dc..3dfe90d88d1 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -18,8 +18,14 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(&circuit, verifier_accumulator); + auto stdlib_instance_vk = std::make_shared(&circuit, instance_vk); + auto stdlib_proof = bb::convert_proof_to_witness(&circuit, fold_output.proof); + + FoldingRecursiveVerifier verifier{ &circuit, stdlib_verifier_accum, { stdlib_instance_vk } }; + auto verifier_accum = verifier.verify_folding_proof(stdlib_proof); verifier_accumulator = std::make_shared(verifier_accum->get_value()); } diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index 3f5d27f92bb..dfa059586ef 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -39,6 +39,8 @@ class ClientIVC { using GURecursiveFlavor = MegaRecursiveFlavor_; using RecursiveVerifierInstances = bb::stdlib::recursion::honk::RecursiveVerifierInstances_; + using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; + using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; using FoldingRecursiveVerifier = bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.cpp index 055fa5ca299..3ad6689aa12 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.cpp @@ -10,9 +10,16 @@ namespace bb::stdlib::recursion::honk { */ void ClientIVCRecursiveVerifier::verify(const ClientIVC::Proof& proof) { + // Construct stdlib accumulator, vkey and proof + auto stdlib_verifier_accum = + std::make_shared(builder.get(), verifier_input.fold_input.accumulator); + auto stdlib_instance_vk = + std::make_shared(builder.get(), verifier_input.fold_input.instance_vks[0]); + auto stdlib_proof = bb::convert_proof_to_witness(builder.get(), proof.folding_proof); + // Perform recursive folding verification - FoldingVerifier folding_verifier{ builder.get(), verifier_input.fold_input }; - auto recursive_verifier_accumulator = folding_verifier.verify_folding_proof(proof.folding_proof); + FoldingVerifier folding_verifier{ builder.get(), stdlib_verifier_accum, { stdlib_instance_vk } }; + auto recursive_verifier_accumulator = folding_verifier.verify_folding_proof(stdlib_proof); auto native_verifier_acc = std::make_shared(recursive_verifier_accumulator->get_value()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp index 43c86f7c24f..4f9f006a06d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp @@ -8,6 +8,8 @@ class ClientIVCRecursiveVerifier { using Builder = UltraCircuitBuilder; // The circuit will be an Ultra circuit using RecursiveFlavor = MegaRecursiveFlavor_; // The verifier algorithms are Mega using RecursiveVerifierInstances = RecursiveVerifierInstances_; + using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; + using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; using DeciderVerifier = DeciderRecursiveVerifier_; using FoldingVerifier = ProtoGalaxyRecursiveVerifier_; using GoblinVerifier = GoblinRecursiveVerifier; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index efdbfeb132d..4fd6335ef31 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -116,12 +116,11 @@ template void ProtoGalaxyRecursiveVerifier_ std::shared_ptr ProtoGalaxyRecursiveVerifier_< - VerifierInstances>::verify_folding_proof(const HonkProof& proof) + VerifierInstances>::verify_folding_proof(const StdlibProof& proof) { using Transcript = typename Flavor::Transcript; - StdlibProof stdlib_proof = bb::convert_proof_to_witness(builder, proof); - transcript = std::make_shared(stdlib_proof); + transcript = std::make_shared(proof); prepare_for_folding(); auto delta = transcript->template get_challenge("delta"); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp index 938fd8787e5..6a0d8d55996 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp @@ -42,9 +42,11 @@ template class ProtoGalaxyRecursiveVerifier_ { std::shared_ptr transcript; VerifierInstances instances; - ProtoGalaxyRecursiveVerifier_(Builder* builder, const VerifierInput& input_data) + ProtoGalaxyRecursiveVerifier_(Builder* builder, + const std::shared_ptr& accumulator, + const std::vector>& instance_vks) : builder(builder) - , instances(VerifierInstances(builder, input_data.accumulator, input_data.instance_vks)){}; + , instances(VerifierInstances(builder, accumulator, instance_vks)){}; /** * @brief Given a new round challenge δ for each iteration of the full ProtoGalaxy protocol, compute the vector @@ -101,9 +103,9 @@ template class ProtoGalaxyRecursiveVerifier_ { * @details In the recursive setting this function doesn't return anything because the equality checks performed by * the recursive verifier, ensuring the folded ϕ*, e* and β* on the verifier side correspond to what has been sent * by the prover, are expressed as constraints. - + * */ - std::shared_ptr verify_folding_proof(const HonkProof&); + std::shared_ptr verify_folding_proof(const StdlibProof&); /** * @brief Evaluates the perturbator at a given scalar, in a sequential manner for the recursive setting. diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp index e166bd0dd5e..3ac38a01115 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp @@ -37,6 +37,8 @@ template class ProtoGalaxyRecursiveTests : public tes using OuterProverInstance = ProverInstance_; using RecursiveVerifierInstances = ::bb::stdlib::recursion::honk::RecursiveVerifierInstances_; + using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; + using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; using FoldingRecursiveVerifier = ProtoGalaxyRecursiveVerifier_; using DeciderRecursiveVerifier = DeciderRecursiveVerifier_; using InnerDeciderProver = DeciderProver_; @@ -193,9 +195,17 @@ template class ProtoGalaxyRecursiveTests : public tes // Create a recursive folding verifier circuit for the folding proof of the two instances OuterBuilder folding_circuit; - auto verifier = FoldingRecursiveVerifier(&folding_circuit, - { verifier_instance_1, { verifier_instance_2->verification_key } }); - verifier.verify_folding_proof(folding_proof.proof); + + auto recursive_verifier_instance_1 = + std::make_shared(&folding_circuit, verifier_instance_1); + auto recursive_verification_key_2 = + std::make_shared(&folding_circuit, verifier_instance_2->verification_key); + StdlibProof stdlib_proof = bb::convert_proof_to_witness(&folding_circuit, folding_proof.proof); + + auto verifier = FoldingRecursiveVerifier{ &folding_circuit, + recursive_verifier_instance_1, + { recursive_verification_key_2 } }; + verifier.verify_folding_proof(stdlib_proof); info("Folding Recursive Verifier: num gates = ", folding_circuit.num_gates); EXPECT_EQ(folding_circuit.failed(), false) << folding_circuit.err(); @@ -257,9 +267,16 @@ template class ProtoGalaxyRecursiveTests : public tes // Create a recursive folding verifier circuit for the folding proof of the two instances OuterBuilder folding_circuit; - auto verifier = FoldingRecursiveVerifier(&folding_circuit, - { verifier_instance_1, { verifier_instance_2->verification_key } }); - auto recursive_verifier_accumulator = verifier.verify_folding_proof(folding_proof.proof); + auto recursive_verifier_instance_1 = + std::make_shared(&folding_circuit, verifier_instance_1); + auto recursive_verification_key_2 = + std::make_shared(&folding_circuit, verifier_instance_2->verification_key); + StdlibProof stdlib_proof = bb::convert_proof_to_witness(&folding_circuit, folding_proof.proof); + + auto verifier = FoldingRecursiveVerifier{ &folding_circuit, + recursive_verifier_instance_1, + { recursive_verification_key_2 } }; + auto recursive_verifier_accumulator = verifier.verify_folding_proof(stdlib_proof); auto native_verifier_acc = std::make_shared(recursive_verifier_accumulator->get_value()); info("Folding Recursive Verifier: num gates = ", folding_circuit.num_gates); @@ -356,9 +373,17 @@ template class ProtoGalaxyRecursiveTests : public tes // Create a recursive folding verifier circuit for the folding proof of the two instances with the untampered // commitments OuterBuilder folding_circuit; - FoldingRecursiveVerifier verifier{ &folding_circuit, - { verifier_accumulator, { verifier_inst->verification_key } } }; - auto recursive_verifier_acc = verifier.verify_folding_proof(folding_proof.proof); + auto recursive_verifier_instance_1 = + std::make_shared(&folding_circuit, verifier_accumulator); + auto recursive_verification_key_2 = + std::make_shared(&folding_circuit, verifier_inst->verification_key); + StdlibProof stdlib_proof = bb::convert_proof_to_witness(&folding_circuit, folding_proof.proof); + + auto verifier = FoldingRecursiveVerifier{ &folding_circuit, + recursive_verifier_instance_1, + { recursive_verification_key_2 } }; + auto recursive_verifier_acc = verifier.verify_folding_proof(stdlib_proof); + // Validate that the target sum between prover and verifier is now different EXPECT_FALSE(folding_proof.accumulator->target_sum == recursive_verifier_acc->target_sum.get_value()); }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_instances.hpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_instances.hpp index 63957ed97bc..e47e739ef3e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_instances.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_instances.hpp @@ -8,9 +8,7 @@ template struct RecursiveVerifierInstan using Flavor = Flavor_; using Builder = typename Flavor::CircuitBuilder; using VerificationKey = typename Flavor::VerificationKey; - using NativeVerificationKey = typename Flavor::NativeVerificationKey; using Instance = RecursiveVerifierInstance_; - using NativeInstance = bb::VerifierInstance_; using ArrayType = std::array, NUM_>; public: @@ -23,13 +21,13 @@ template struct RecursiveVerifierInstan Builder* builder; RecursiveVerifierInstances_(Builder* builder, - const std::shared_ptr& accumulator, - const std::vector>& vks) + const std::shared_ptr& accumulator, + const std::vector>& vks) : builder(builder) { ASSERT(vks.size() == NUM - 1); - _data[0] = std::make_shared(builder, accumulator); + _data[0] = accumulator; size_t idx = 1; for (auto& vk : vks) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_verifier_instance.hpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_verifier_instance.hpp index c7b63abced9..d0029756f43 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_verifier_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_verifier_instance.hpp @@ -40,9 +40,15 @@ template class RecursiveVerifierInstance_ { RecursiveVerifierInstance_(Builder* builder) : builder(builder){}; + RecursiveVerifierInstance_(Builder* builder, std::shared_ptr vk) : builder(builder) - , verification_key(std::make_shared(builder, vk)) + , verification_key(std::make_shared(builder, vk)){}; + + // Constructor from stdlib vkey + RecursiveVerifierInstance_(Builder* builder, std::shared_ptr vk) + : builder(builder) + , verification_key(vk) {} RecursiveVerifierInstance_(Builder* builder, const std::shared_ptr& instance)