From aae675e64365589b6e0420ab5e422fbd64c2574d Mon Sep 17 00:00:00 2001 From: maramihali Date: Mon, 4 Mar 2024 11:00:33 +0000 Subject: [PATCH 1/4] remove vk from prover instance --- .../barretenberg/client_ivc/client_ivc.cpp | 11 +- .../client_ivc/client_ivc.test.cpp | 8 +- .../cpp/src/barretenberg/goblin/goblin.hpp | 7 +- .../honk/verifier/goblin_verifier.test.cpp | 564 +++++++++--------- .../honk/verifier/merge_verifier.test.cpp | 3 +- .../protogalaxy_recursive_verifier.test.cpp | 7 +- .../recursion/honk/verifier/verifier.test.cpp | 23 +- .../sumcheck/instance/prover_instance.hpp | 2 - .../ultra_honk/databus_composer.test.cpp | 3 +- .../ultra_honk/goblin_ultra_composer.test.cpp | 4 +- .../goblin_ultra_transcript.test.cpp | 7 +- .../ultra_honk/ultra_composer.cpp | 3 +- .../ultra_honk/ultra_composer.hpp | 1 - .../ultra_honk/ultra_composer.test.cpp | 8 +- .../ultra_honk/ultra_transcript.test.cpp | 7 +- 15 files changed, 346 insertions(+), 312 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 911c802ebf8..edf398f6174 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -91,13 +91,14 @@ HonkProof ClientIVC::decider_prove() const void ClientIVC::precompute_folding_verification_keys() { using VerifierInstance = VerifierInstance_; + using VerificationKey = Flavor::VerificationKey; ClientCircuit initial_function_circuit{ goblin.op_queue }; GoblinMockCircuits::construct_mock_function_circuit(initial_function_circuit); // Initialise both the first prover and verifier accumulator from the inital function circuit initialize(initial_function_circuit); - vks.first_func_vk = prover_fold_output.accumulator->verification_key; + vks.first_func_vk = std::make_shared(prover_fold_output.accumulator->proving_key); auto initial_verifier_acc = std::make_shared(vks.first_func_vk); // Accumulate the next function circuit @@ -106,14 +107,15 @@ void ClientIVC::precompute_folding_verification_keys() auto function_fold_proof = accumulate(function_circuit); // Create its verification key (we have called accumulate so it includes the recursive merge verifier) - vks.func_vk = prover_instance->verification_key; + vks.func_vk = std::make_shared(prover_instance->proving_key); // Create the initial kernel iteration and precompute its verification key ClientCircuit kernel_circuit{ goblin.op_queue }; auto kernel_acc = GoblinMockCircuits::construct_mock_folding_kernel( kernel_circuit, { function_fold_proof, vks.func_vk }, {}, initial_verifier_acc); auto kernel_fold_proof = accumulate(kernel_circuit); - vks.first_kernel_vk = prover_instance->verification_key; + vks.first_kernel_vk = std::make_shared(prover_instance->proving_key); + ; // Create another mock function circuit to run the full kernel function_circuit = ClientCircuit{ goblin.op_queue }; @@ -126,7 +128,8 @@ void ClientIVC::precompute_folding_verification_keys() kernel_circuit, { function_fold_proof, vks.func_vk }, { kernel_fold_proof, vks.first_kernel_vk }, kernel_acc); kernel_fold_proof = accumulate(kernel_circuit); - vks.kernel_vk = prover_instance->verification_key; + vks.kernel_vk = std::make_shared(prover_instance->proving_key); + ; // Clean the ivc state goblin.op_queue = std::make_shared(); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 45e594f47a9..1f985351bbf 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -105,18 +105,20 @@ class ClientIVCTests : public ::testing::Test { */ TEST_F(ClientIVCTests, Full) { + using VerificationKey = Flavor::VerificationKey; + ClientIVC ivc; // Initialize IVC with function circuit Builder function_circuit = create_mock_circuit(ivc); ivc.initialize(function_circuit); - auto function_vk = ivc.prover_fold_output.accumulator->verification_key; + auto function_vk = std::make_shared(ivc.prover_fold_output.accumulator->proving_key); auto foo_verifier_instance = std::make_shared(function_vk); // Accumulate kernel circuit (first kernel mocked as simple circuit since no folding proofs yet) Builder kernel_circuit = create_mock_circuit(ivc); FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit); // This will have a different verification key because we added the recursive merge verification to the circuit - auto function_vk_with_merge = ivc.prover_instance->verification_key; + auto function_vk_with_merge = std::make_shared(ivc.prover_instance->proving_key); auto kernel_vk = function_vk_with_merge; auto intermediary_acc = update_accumulator_and_decide_native( ivc.prover_fold_output.accumulator, kernel_fold_proof, foo_verifier_instance, kernel_vk); @@ -137,7 +139,7 @@ TEST_F(ClientIVCTests, Full) foo_verifier_instance = construct_mock_folding_kernel( kernel_circuit, kernel_fold_output, function_fold_output, foo_verifier_instance); FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit); - kernel_vk = ivc.prover_instance->verification_key; + kernel_vk = std::make_shared(ivc.prover_instance->proving_key); intermediary_acc = update_accumulator_and_decide_native( ivc.prover_fold_output.accumulator, kernel_fold_proof, intermediary_acc, kernel_vk); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 3b055844b2f..1dece4eed0e 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -36,6 +36,7 @@ class Goblin { using RecursiveMergeVerifier = bb::stdlib::recursion::goblin::MergeRecursiveVerifier_; using MergeProver = bb::MergeProver_; using MergeVerifier = bb::MergeVerifier_; + using VerificationKey = GoblinUltraFlavor::VerificationKey; /** * @brief Output of goblin::accumulate; an Ultra proof and the corresponding verification key * @@ -105,6 +106,7 @@ class Goblin { // Construct a Honk proof for the main circuit GoblinUltraComposer composer; auto instance = composer.create_prover_instance(circuit_builder); + auto verification_key = std::make_shared(instance->proving_key); auto prover = composer.create_prover(instance); auto ultra_proof = prover.construct_proof(); @@ -116,7 +118,7 @@ class Goblin { merge_proof_exists = true; } - return { ultra_proof, instance->verification_key }; + return { ultra_proof, verification_key }; }; /** @@ -231,10 +233,11 @@ class Goblin { // Construct a Honk proof for the main circuit GoblinUltraComposer composer; auto instance = composer.create_prover_instance(circuit_builder); + auto verification_key = std::make_shared(instance->proving_key); auto prover = composer.create_prover(instance); auto ultra_proof = prover.construct_proof(); - accumulator = { ultra_proof, instance->verification_key }; + accumulator = { ultra_proof, verification_key }; // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): no merge prover for now since we're not // mocking the first set of ecc ops diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp index 1a37b1fa092..0cbdeaf7164 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp @@ -1,279 +1,285 @@ -#include "barretenberg/common/test.hpp" -#include "barretenberg/flavor/ultra_recursive.hpp" -#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" -#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" -#include "barretenberg/stdlib/primitives/curves/bn254.hpp" -#include "barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" -#include "barretenberg/ultra_honk/ultra_verifier.hpp" - -namespace bb::stdlib::recursion::honk { - -/** - * @brief Test suite for recursive verification of Goblin Ultra Honk proofs - * @details The recursive verification circuit is arithmetized in two different ways: 1) using the conventional Ultra - * arithmetization (UltraCircuitBuilder), or 2) a Goblin-style Ultra arithmetization (GoblinUltraCircuitBuilder). - * - * @tparam Builder Circuit builder for the recursive verifier circuit - */ -template class GoblinRecursiveVerifierTest : public testing::Test { - - using UltraComposer = UltraComposer_; - using GoblinUltraComposer = UltraComposer_; - - // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified - using InnerFlavor = GoblinUltraFlavor; - using InnerComposer = GoblinUltraComposer; - using InnerBuilder = typename InnerComposer::CircuitBuilder; - using InnerCurve = bn254; - using InnerCommitment = InnerFlavor::Commitment; - using InnerFF = InnerFlavor::FF; - - // Types for recursive verifier circuit - using OuterBuilder = BuilderType; - using RecursiveFlavor = GoblinUltraRecursiveFlavor_; - using RecursiveVerifier = UltraRecursiveVerifier_; - using VerificationKey = typename RecursiveVerifier::VerificationKey; - - // Helper for getting composer for prover/verifier of recursive (outer) circuit - template static auto get_outer_composer() - { - if constexpr (IsGoblinBuilder) { - return GoblinUltraComposer(); - } else { - return UltraComposer(); - } - } - - /** - * @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified - * - * @param builder - * @param public_inputs - * @param log_num_gates - */ - static InnerBuilder create_inner_circuit(size_t log_num_gates = 10) - { - using fr_ct = InnerCurve::ScalarField; - using fq_ct = InnerCurve::BaseField; - using point_ct = InnerCurve::AffineElement; - using public_witness_ct = InnerCurve::public_witness_ct; - using witness_ct = InnerCurve::witness_ct; - using byte_array_ct = InnerCurve::byte_array_ct; - using fr = typename InnerCurve::ScalarFieldNative; - using point = typename InnerCurve::GroupNative::affine_element; - - // Instantiate ECC op queue and add mock data to simulate interaction with a previous circuit - auto op_queue = std::make_shared(); - op_queue->populate_with_mock_initital_data(); - - InnerBuilder builder(op_queue); - - // Create 2^log_n many add gates based on input log num gates - const size_t num_gates = 1 << log_num_gates; - for (size_t i = 0; i < num_gates; ++i) { - fr a = fr::random_element(); - uint32_t a_idx = builder.add_variable(a); - - fr b = fr::random_element(); - fr c = fr::random_element(); - fr d = a + b + c; - uint32_t b_idx = builder.add_variable(b); - uint32_t c_idx = builder.add_variable(c); - uint32_t d_idx = builder.add_variable(d); - - builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); - } - - // Add some arbitrary goblin-style ECC op gates via a batch mul - size_t num_points = 5; - std::vector circuit_points; - std::vector circuit_scalars; - for (size_t i = 0; i < num_points; ++i) { - circuit_points.push_back(point_ct::from_witness(&builder, point::random_element())); - circuit_scalars.push_back(fr_ct::from_witness(&builder, fr::random_element())); - } - point_ct::batch_mul(circuit_points, circuit_scalars); - - // Define some additional arbitrary convetional circuit logic - fr_ct a(public_witness_ct(&builder, fr::random_element())); - fr_ct b(public_witness_ct(&builder, fr::random_element())); - fr_ct c(public_witness_ct(&builder, fr::random_element())); - - for (size_t i = 0; i < 32; ++i) { - a = (a * b) + b + a; - a = a.madd(b, c); - } - pedersen_hash::hash({ a, b }); - byte_array_ct to_hash(&builder, "nonsense test data"); - blake3s(to_hash); - - fr bigfield_data = fr::random_element(); - fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; - fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - - fq_ct big_a(fr_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), fr_ct(witness_ct(&builder, 0))); - fq_ct big_b(fr_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), fr_ct(witness_ct(&builder, 0))); - - big_a* big_b; - - return builder; - }; - - public: - static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } - - /** - * @brief Create inner circuit and call check_circuit on it - * - */ - static void test_inner_circuit() - { - auto inner_circuit = create_inner_circuit(); - - bool result = inner_circuit.check_circuit(); - EXPECT_EQ(result, true); - } - - /** - * @brief Instantiate a recursive verification key from the native verification key produced by the inner cicuit - * builder. Check consistency beteen the native and stdlib types. - * - */ - static void test_recursive_verification_key_creation() - { - // Create an arbitrary inner circuit - auto inner_circuit = create_inner_circuit(); - OuterBuilder outer_circuit; - - // Compute native verification key - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); - auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK - auto verification_key = instance->verification_key; - // Instantiate the recursive verifier using the native verification key - RecursiveVerifier verifier{ &outer_circuit, verification_key }; - - // Spot check some values in the recursive VK to ensure it was constructed correctly - EXPECT_EQ(verifier.key->circuit_size, verification_key->circuit_size); - EXPECT_EQ(verifier.key->log_circuit_size, verification_key->log_circuit_size); - EXPECT_EQ(verifier.key->num_public_inputs, verification_key->num_public_inputs); - EXPECT_EQ(verifier.key->q_m.get_value(), verification_key->q_m); - EXPECT_EQ(verifier.key->q_r.get_value(), verification_key->q_r); - EXPECT_EQ(verifier.key->sigma_1.get_value(), verification_key->sigma_1); - EXPECT_EQ(verifier.key->id_3.get_value(), verification_key->id_3); - EXPECT_EQ(verifier.key->lagrange_ecc_op.get_value(), verification_key->lagrange_ecc_op); - } - - /** - * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on it - * - */ - static void test_recursive_verification() - { - // Create an arbitrary inner circuit - auto inner_circuit = create_inner_circuit(); - - // Generate a proof over the inner circuit - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); - auto inner_prover = inner_composer.create_prover(instance); - auto inner_proof = inner_prover.construct_proof(); - - // Create a recursive verification circuit for the proof of the inner circuit - OuterBuilder outer_circuit; - RecursiveVerifier verifier{ &outer_circuit, instance->verification_key }; - auto pairing_points = verifier.verify_proof(inner_proof); - info("Recursive Verifier Goblin: num gates = ", outer_circuit.num_gates); - - // Check for a failure flag in the recursive verifier circuit - EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err(); - - // Check 1: Perform native verification then perform the pairing on the outputs of the recursive - // verifier and check that the result agrees. - auto native_verifier = inner_composer.create_verifier(instance->verification_key); - auto native_result = native_verifier.verify_proof(inner_proof); - auto recursive_result = native_verifier.pcs_verification_key->pairing_check(pairing_points[0].get_value(), - pairing_points[1].get_value()); - EXPECT_EQ(recursive_result, native_result); - - // Check 2: Ensure that the underlying native and recursive verification algorithms agree by ensuring - // the manifests produced by each agree. - auto recursive_manifest = verifier.transcript->get_manifest(); - auto native_manifest = native_verifier.transcript->get_manifest(); - for (size_t i = 0; i < recursive_manifest.size(); ++i) { - EXPECT_EQ(recursive_manifest[i], native_manifest[i]); - } - - // Check 3: Construct and verify a proof of the recursive verifier circuit - { - auto composer = get_outer_composer(); - auto instance = composer.create_prover_instance(outer_circuit); - auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); - auto proof = prover.construct_proof(); - bool verified = verifier.verify_proof(proof); - - ASSERT(verified); - } - } - - /** - * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure - * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would be - * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is - * wrong. This is difficult now but should be straightforward if the proof is a struct. - */ - static void test_recursive_verification_fails() - { - // Create an arbitrary inner circuit - auto inner_circuit = create_inner_circuit(); - - // Generate a proof over the inner circuit - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); - auto inner_prover = inner_composer.create_prover(instance); - auto inner_proof = inner_prover.construct_proof(); - - // Arbitrarily tamper with the proof to be verified - inner_prover.transcript->deserialize_full_transcript(); - inner_prover.transcript->sorted_accum_comm = InnerCommitment::one() * InnerFF::random_element(); - inner_prover.transcript->serialize_full_transcript(); - inner_proof = inner_prover.export_proof(); - - // Create a recursive verification circuit for the proof of the inner circuit - OuterBuilder outer_circuit; - RecursiveVerifier verifier{ &outer_circuit, instance->verification_key }; - verifier.verify_proof(inner_proof); - - // We expect the circuit check to fail due to the bad proof - EXPECT_FALSE(outer_circuit.check_circuit()); - } -}; - -// Run the recursive verifier tests with conventional Ultra builder and Goblin builder -using BuilderTypes = testing::Types; - -TYPED_TEST_SUITE(GoblinRecursiveVerifierTest, BuilderTypes); - -HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, InnerCircuit) -{ - TestFixture::test_inner_circuit(); -} - -HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, RecursiveVerificationKey) -{ - TestFixture::test_recursive_verification_key_creation(); -} - -HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerification) -{ - TestFixture::test_recursive_verification(); -}; - -HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerificationFailure) -{ - TestFixture::test_recursive_verification_fails(); -}; - -} // namespace bb::stdlib::recursion::honk \ No newline at end of file +// #include "barretenberg/common/test.hpp" +// #include "barretenberg/flavor/ultra_recursive.hpp" +// #include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" +// #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" +// #include "barretenberg/stdlib/primitives/curves/bn254.hpp" +// #include "barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.hpp" +// #include "barretenberg/ultra_honk/ultra_composer.hpp" +// #include "barretenberg/ultra_honk/ultra_verifier.hpp" + +// namespace bb::stdlib::recursion::honk { + +// /** +// * @brief Test suite for recursive verification of Goblin Ultra Honk proofs +// * @details The recursive verification circuit is arithmetized in two different ways: 1) using the conventional Ultra +// * arithmetization (UltraCircuitBuilder), or 2) a Goblin-style Ultra arithmetization (GoblinUltraCircuitBuilder). +// * +// * @tparam Builder Circuit builder for the recursive verifier circuit +// */ +// template class GoblinRecursiveVerifierTest : public testing::Test { + +// using UltraComposer = UltraComposer_; +// using GoblinUltraComposer = UltraComposer_; + +// // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified +// using InnerFlavor = GoblinUltraFlavor; +// using InnerComposer = GoblinUltraComposer; +// using InnerBuilder = typename InnerComposer::CircuitBuilder; +// using InnerCurve = bn254; +// using InnerCommitment = InnerFlavor::Commitment; +// using InnerFF = InnerFlavor::FF; + +// // Types for recursive verifier circuit +// using OuterBuilder = BuilderType; +// using RecursiveFlavor = GoblinUltraRecursiveFlavor_; +// using RecursiveVerifier = UltraRecursiveVerifier_; +// using VerificationKey = typename RecursiveVerifier::VerificationKey; + +// // Helper for getting composer for prover/verifier of recursive (outer) circuit +// template static auto get_outer_composer() +// { +// if constexpr (IsGoblinBuilder) { +// return GoblinUltraComposer(); +// } else { +// return UltraComposer(); +// } +// } + +// /** +// * @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified +// * +// * @param builder +// * @param public_inputs +// * @param log_num_gates +// */ +// static InnerBuilder create_inner_circuit(size_t log_num_gates = 10) +// { +// using fr_ct = InnerCurve::ScalarField; +// using fq_ct = InnerCurve::BaseField; +// using point_ct = InnerCurve::AffineElement; +// using public_witness_ct = InnerCurve::public_witness_ct; +// using witness_ct = InnerCurve::witness_ct; +// using byte_array_ct = InnerCurve::byte_array_ct; +// using fr = typename InnerCurve::ScalarFieldNative; +// using point = typename InnerCurve::GroupNative::affine_element; + +// // Instantiate ECC op queue and add mock data to simulate interaction with a previous circuit +// auto op_queue = std::make_shared(); +// op_queue->populate_with_mock_initital_data(); + +// InnerBuilder builder(op_queue); + +// // Create 2^log_n many add gates based on input log num gates +// const size_t num_gates = 1 << log_num_gates; +// for (size_t i = 0; i < num_gates; ++i) { +// fr a = fr::random_element(); +// uint32_t a_idx = builder.add_variable(a); + +// fr b = fr::random_element(); +// fr c = fr::random_element(); +// fr d = a + b + c; +// uint32_t b_idx = builder.add_variable(b); +// uint32_t c_idx = builder.add_variable(c); +// uint32_t d_idx = builder.add_variable(d); + +// builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); +// } + +// // Add some arbitrary goblin-style ECC op gates via a batch mul +// size_t num_points = 5; +// std::vector circuit_points; +// std::vector circuit_scalars; +// for (size_t i = 0; i < num_points; ++i) { +// circuit_points.push_back(point_ct::from_witness(&builder, point::random_element())); +// circuit_scalars.push_back(fr_ct::from_witness(&builder, fr::random_element())); +// } +// point_ct::batch_mul(circuit_points, circuit_scalars); + +// // Define some additional arbitrary convetional circuit logic +// fr_ct a(public_witness_ct(&builder, fr::random_element())); +// fr_ct b(public_witness_ct(&builder, fr::random_element())); +// fr_ct c(public_witness_ct(&builder, fr::random_element())); + +// for (size_t i = 0; i < 32; ++i) { +// a = (a * b) + b + a; +// a = a.madd(b, c); +// } +// pedersen_hash::hash({ a, b }); +// byte_array_ct to_hash(&builder, "nonsense test data"); +// blake3s(to_hash); + +// fr bigfield_data = fr::random_element(); +// fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; +// fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; + +// fq_ct big_a(fr_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), fr_ct(witness_ct(&builder, +// 0))); fq_ct big_b(fr_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), +// fr_ct(witness_ct(&builder, 0))); + +// big_a* big_b; + +// return builder; +// }; + +// public: +// static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } + +// /** +// * @brief Create inner circuit and call check_circuit on it +// * +// */ +// static void test_inner_circuit() +// { +// auto inner_circuit = create_inner_circuit(); + +// bool result = inner_circuit.check_circuit(); +// EXPECT_EQ(result, true); +// } + +// /** +// * @brief Instantiate a recursive verification key from the native verification key produced by the inner cicuit +// * builder. Check consistency beteen the native and stdlib types. +// * +// */ +// static void test_recursive_verification_key_creation() +// { +// // Create an arbitrary inner circuit +// auto inner_circuit = create_inner_circuit(); +// OuterBuilder outer_circuit; + +// // Compute native verification key +// InnerComposer inner_composer; +// auto instance = inner_composer.create_prover_instance(inner_circuit); +// // auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK +// auto verification_key = std::make_shared(instance->proving_key); +// // Instantiate the recursive verifier using the native verification key +// RecursiveVerifier verifier{ &outer_circuit, verification_key }; + +// // Spot check some values in the recursive VK to ensure it was constructed correctly +// EXPECT_EQ(verifier.key->circuit_size, verification_key->circuit_size); +// EXPECT_EQ(verifier.key->log_circuit_size, verification_key->log_circuit_size); +// EXPECT_EQ(verifier.key->num_public_inputs, verification_key->num_public_inputs); +// EXPECT_EQ(verifier.key->q_m.get_value(), verification_key->q_m); +// EXPECT_EQ(verifier.key->q_r.get_value(), verification_key->q_r); +// EXPECT_EQ(verifier.key->sigma_1.get_value(), verification_key->sigma_1); +// EXPECT_EQ(verifier.key->id_3.get_value(), verification_key->id_3); +// EXPECT_EQ(verifier.key->lagrange_ecc_op.get_value(), verification_key->lagrange_ecc_op); +// } + +// /** +// * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on +// it +// * +// */ +// static void test_recursive_verification() +// { +// // Create an arbitrary inner circuit +// auto inner_circuit = create_inner_circuit(); + +// // Generate a proof over the inner circuit +// InnerComposer inner_composer; +// auto instance = inner_composer.create_prover_instance(inner_circuit); +// auto verification_key = std::make_shared(instance->proving_key); +// auto inner_prover = inner_composer.create_prover(instance); +// auto inner_proof = inner_prover.construct_proof(); + +// // Create a recursive verification circuit for the proof of the inner circuit +// OuterBuilder outer_circuit; +// RecursiveVerifier verifier{ &outer_circuit, verification_key }; +// auto pairing_points = verifier.verify_proof(inner_proof); +// info("Recursive Verifier Goblin: num gates = ", outer_circuit.num_gates); + +// // Check for a failure flag in the recursive verifier circuit +// EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err(); + +// // Check 1: Perform native verification then perform the pairing on the outputs of the recursive +// // verifier and check that the result agrees. +// auto native_verifier = inner_composer.create_verifier(verification_key); +// auto native_result = native_verifier.verify_proof(inner_proof); +// auto recursive_result = native_verifier.pcs_verification_key->pairing_check(pairing_points[0].get_value(), +// pairing_points[1].get_value()); +// EXPECT_EQ(recursive_result, native_result); + +// // Check 2: Ensure that the underlying native and recursive verification algorithms agree by ensuring +// // the manifests produced by each agree. +// auto recursive_manifest = verifier.transcript->get_manifest(); +// auto native_manifest = native_verifier.transcript->get_manifest(); +// for (size_t i = 0; i < recursive_manifest.size(); ++i) { +// EXPECT_EQ(recursive_manifest[i], native_manifest[i]); +// } + +// // Check 3: Construct and verify a proof of the recursive verifier circuit +// { +// auto composer = get_outer_composer(); +// auto instance = composer.create_prover_instance(outer_circuit); +// auto prover = composer.create_prover(instance); +// auto verification_key = std::make_shared(instance->proving_key); +// auto verifier = composer.create_verifier(verification_key); +// auto proof = prover.construct_proof(); +// bool verified = verifier.verify_proof(proof); + +// ASSERT(verified); +// } +// } + +// /** +// * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure +// * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would +// be +// * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is +// * wrong. This is difficult now but should be straightforward if the proof is a struct. +// */ +// static void test_recursive_verification_fails() +// { +// // Create an arbitrary inner circuit +// auto inner_circuit = create_inner_circuit(); + +// // Generate a proof over the inner circuit +// InnerComposer inner_composer; +// auto instance = inner_composer.create_prover_instance(inner_circuit); +// auto inner_prover = inner_composer.create_prover(instance); +// auto inner_proof = inner_prover.construct_proof(); + +// // Arbitrarily tamper with the proof to be verified +// inner_prover.transcript->deserialize_full_transcript(); +// inner_prover.transcript->sorted_accum_comm = InnerCommitment::one() * InnerFF::random_element(); +// inner_prover.transcript->serialize_full_transcript(); +// inner_proof = inner_prover.export_proof(); + +// // Create a recursive verification circuit for the proof of the inner circuit +// OuterBuilder outer_circuit; +// auto verification_key = std::make_shared(instance->proving_key); +// RecursiveVerifier verifier{ &outer_circuit, verification_key }; +// verifier.verify_proof(inner_proof); + +// // We expect the circuit check to fail due to the bad proof +// EXPECT_FALSE(outer_circuit.check_circuit()); +// } +// }; + +// // Run the recursive verifier tests with conventional Ultra builder and Goblin builder +// using BuilderTypes = testing::Types; + +// TYPED_TEST_SUITE(GoblinRecursiveVerifierTest, BuilderTypes); + +// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, InnerCircuit) +// { +// TestFixture::test_inner_circuit(); +// } + +// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, RecursiveVerificationKey) +// { +// TestFixture::test_recursive_verification_key_creation(); +// } + +// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerification) +// { +// TestFixture::test_recursive_verification(); +// }; + +// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerificationFailure) +// { +// TestFixture::test_recursive_verification_fails(); +// }; + +// } // namespace bb::stdlib::recursion::honk \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp index cd603ed1c85..2e3a90195ec 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp @@ -84,7 +84,8 @@ class RecursiveMergeVerifierTest : public testing::Test { GoblinUltraComposer composer; auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verifier_instance = composer.create_verifier_instance(instance); + auto verifier = composer.create_verifier(verifier_instance->verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp index 6e2f1f5f3ce..30e2ede47d7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp @@ -19,6 +19,7 @@ template class ProtoGalaxyRecursiveTests : public tes using Curve = bn254; using Commitment = typename NativeFlavor::Commitment; using FF = typename NativeFlavor::FF; + using VerificationKey = typename NativeFlavor::VerificationKey; using RecursiveVerifierInstances = ::bb::stdlib::recursion::honk::RecursiveVerifierInstances_; using FoldingRecursiveVerifier = ProtoGalaxyRecursiveVerifier_; @@ -205,7 +206,8 @@ template class ProtoGalaxyRecursiveTests : public tes auto composer = Composer(); auto instance = composer.create_prover_instance(folding_circuit); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -295,7 +297,8 @@ template class ProtoGalaxyRecursiveTests : public tes auto composer = Composer(); auto instance = composer.create_prover_instance(decider_circuit); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp index 384405d1272..c1aa5f0cab6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp @@ -33,7 +33,6 @@ template class RecursiveVerifierTest : public testing::Te using RecursiveFlavor = UltraRecursiveFlavor_; using RecursiveVerifier = UltraRecursiveVerifier_; using OuterBuilder = BuilderType; - using VerificationKey = typename RecursiveVerifier::VerificationKey; // Helper for getting composer for prover/verifier of recursive (outer) circuit template static auto get_outer_composer() @@ -133,8 +132,7 @@ template class RecursiveVerifierTest : public testing::Te // Compute native verification key InnerComposer inner_composer; auto instance = inner_composer.create_prover_instance(inner_circuit); - auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK - auto verification_key = instance->verification_key; + auto verification_key = std::make_shared(instance->proving_key); // Instantiate the recursive verifier using the native verification key RecursiveVerifier verifier{ &outer_circuit, verification_key }; @@ -149,7 +147,8 @@ template class RecursiveVerifierTest : public testing::Te } /** - * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on it + * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on + it * */ static void test_recursive_verification() @@ -164,9 +163,11 @@ template class RecursiveVerifierTest : public testing::Te auto inner_prover = inner_composer.create_prover(instance); auto inner_proof = inner_prover.construct_proof(); + auto verification_key = std::make_shared(instance->proving_key); + // Create a recursive verification circuit for the proof of the inner circuit OuterBuilder outer_circuit; - RecursiveVerifier verifier{ &outer_circuit, instance->verification_key }; + RecursiveVerifier verifier{ &outer_circuit, verification_key }; auto pairing_points = verifier.verify_proof(inner_proof); info("Recursive Verifier Ultra: num gates = ", outer_circuit.num_gates); @@ -175,7 +176,7 @@ template class RecursiveVerifierTest : public testing::Te // Check 1: Perform native verification then perform the pairing on the outputs of the recursive // verifier and check that the result agrees. - auto native_verifier = inner_composer.create_verifier(instance->verification_key); + auto native_verifier = inner_composer.create_verifier(verification_key); auto native_result = native_verifier.verify_proof(inner_proof); auto recursive_result = native_verifier.pcs_verification_key->pairing_check(pairing_points[0].get_value(), pairing_points[1].get_value()); @@ -194,7 +195,8 @@ template class RecursiveVerifierTest : public testing::Te auto composer = get_outer_composer(); auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verifier_instance = composer.create_verifier_instance(instance); + auto verifier = composer.create_verifier(verifier_instance->verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -204,7 +206,8 @@ template class RecursiveVerifierTest : public testing::Te /** * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure - * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would be + * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would + be * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is * wrong. This is difficult now but should be straightforward if the proof is a struct. */ @@ -226,9 +229,11 @@ template class RecursiveVerifierTest : public testing::Te inner_prover.transcript->serialize_full_transcript(); inner_proof = inner_prover.export_proof(); + auto verification_key = std::make_shared(instance->proving_key); + // Create a recursive verification circuit for the proof of the inner circuit OuterBuilder outer_circuit; - RecursiveVerifier verifier{ &outer_circuit, instance->verification_key }; + RecursiveVerifier verifier{ &outer_circuit, verification_key }; verifier.verify_proof(inner_proof); // We expect the circuit check to fail due to the bad proof diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index a4196abfd95..8b20a327b8d 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -88,8 +88,6 @@ template class ProverInstance_ { proving_key->contains_recursive_proof = contains_recursive_proof; sorted_polynomials = construct_sorted_list_polynomials(circuit, dyadic_circuit_size); - - verification_key = std::make_shared(proving_key); } ProverInstance_() = default; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp index 6af08ef87f7..a073c1f1aba 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp @@ -87,7 +87,8 @@ TEST_F(DataBusComposerTests, CallDataRead) auto instance = composer.create_prover_instance(builder); // For debugging, use "instance_inspector::print_databus_info(instance)" auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); EXPECT_TRUE(verified); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp index 8e8ed2876fb..9f383263a21 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp @@ -25,6 +25,7 @@ class GoblinUltraHonkComposerTests : public ::testing::Test { using CommitmentKey = bb::CommitmentKey; using MergeProver = MergeProver_; using MergeVerifier = MergeVerifier_; + using VerificationKey = GoblinUltraFlavor::VerificationKey; /** * @brief Generate a simple test circuit with some ECC op gates and conventional arithmetic gates @@ -64,7 +65,8 @@ class GoblinUltraHonkComposerTests : public ::testing::Test { { auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp index 12ae627a62f..91c5afbb36a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp @@ -14,6 +14,7 @@ class GoblinUltraTranscriptTests : public ::testing::Test { using Flavor = GoblinUltraFlavor; using FF = Flavor::FF; + using VerificationKey = Flavor::VerificationKey; /** * @brief Construct a manifest for a GoblinUltra Honk proof @@ -177,7 +178,8 @@ TEST_F(GoblinUltraTranscriptTests, VerifierManifestConsistency) auto proof = prover.construct_proof(); // Automatically generate a transcript manifest in the verifier by verifying a proof - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); verifier.verify_proof(proof); // Check consistency between the manifests generated by the prover and verifier @@ -226,7 +228,8 @@ TEST_F(GoblinUltraTranscriptTests, StructureTest) auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); EXPECT_TRUE(verifier.verify_proof(proof)); // try deserializing and serializing with no changes and check proof is still valid diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp index e8da52f540b..09f4c782247 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp @@ -16,7 +16,8 @@ template std::shared_ptr> UltraComposer_::create_verifier_instance( std::shared_ptr>& prover_instance) { - auto instance = std::make_shared(prover_instance->verification_key); + auto verification_key = std::make_shared(prover_instance->proving_key); + auto instance = std::make_shared(verification_key); return instance; } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp index 0805d0e35f6..af1f7564e43 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp @@ -85,7 +85,6 @@ template class UltraComposer_ { DeciderVerifier_ create_decider_verifier( const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); - UltraVerifier_ create_verifier(CircuitBuilder& circuit); UltraVerifier_ create_ultra_with_keccak_verifier(CircuitBuilder& circuit); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp index c8f0a1667ca..01eab86b59f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -22,6 +22,8 @@ namespace { auto& engine = numeric::get_debug_randomness(); } +using VerificationKey = UltraFlavor::VerificationKey; + std::vector add_variables(auto& circuit_builder, std::vector variables) { std::vector res; @@ -35,7 +37,8 @@ void prove_and_verify(auto& circuit_builder, auto& composer, bool expected_resul { auto instance = composer.create_prover_instance(circuit_builder); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); EXPECT_EQ(verified, expected_result); @@ -200,7 +203,8 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) auto composer = UltraComposer(); auto instance = composer.create_prover_instance(circuit_builder); auto prover = composer.create_prover(instance); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp index bb05c2588ba..14afc28f05b 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -13,6 +13,7 @@ class UltraTranscriptTests : public ::testing::Test { static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } using Flavor = UltraFlavor; + using VerificationKey = Flavor::VerificationKey; using FF = Flavor::FF; /** @@ -163,7 +164,8 @@ TEST_F(UltraTranscriptTests, VerifierManifestConsistency) auto proof = prover.construct_proof(); // Automatically generate a transcript manifest in the verifier by verifying a proof - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); verifier.verify_proof(proof); // Check consistency between the manifests generated by the prover and verifier @@ -212,7 +214,8 @@ TEST_F(UltraTranscriptTests, StructureTest) auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(instance->verification_key); + auto verification_key = std::make_shared(instance->proving_key); + auto verifier = composer.create_verifier(verification_key); EXPECT_TRUE(verifier.verify_proof(proof)); // try deserializing and serializing with no changes and check proof is still valid From abb67f15945820ffd9a513ee9e27901ac16fb031 Mon Sep 17 00:00:00 2001 From: maramihali Date: Mon, 4 Mar 2024 11:07:37 +0000 Subject: [PATCH 2/4] uncomment last files --- .../honk/verifier/goblin_verifier.test.cpp | 571 +++++++++--------- 1 file changed, 286 insertions(+), 285 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp index 0cbdeaf7164..a28f4141d57 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp @@ -1,285 +1,286 @@ -// #include "barretenberg/common/test.hpp" -// #include "barretenberg/flavor/ultra_recursive.hpp" -// #include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" -// #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" -// #include "barretenberg/stdlib/primitives/curves/bn254.hpp" -// #include "barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.hpp" -// #include "barretenberg/ultra_honk/ultra_composer.hpp" -// #include "barretenberg/ultra_honk/ultra_verifier.hpp" - -// namespace bb::stdlib::recursion::honk { - -// /** -// * @brief Test suite for recursive verification of Goblin Ultra Honk proofs -// * @details The recursive verification circuit is arithmetized in two different ways: 1) using the conventional Ultra -// * arithmetization (UltraCircuitBuilder), or 2) a Goblin-style Ultra arithmetization (GoblinUltraCircuitBuilder). -// * -// * @tparam Builder Circuit builder for the recursive verifier circuit -// */ -// template class GoblinRecursiveVerifierTest : public testing::Test { - -// using UltraComposer = UltraComposer_; -// using GoblinUltraComposer = UltraComposer_; - -// // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified -// using InnerFlavor = GoblinUltraFlavor; -// using InnerComposer = GoblinUltraComposer; -// using InnerBuilder = typename InnerComposer::CircuitBuilder; -// using InnerCurve = bn254; -// using InnerCommitment = InnerFlavor::Commitment; -// using InnerFF = InnerFlavor::FF; - -// // Types for recursive verifier circuit -// using OuterBuilder = BuilderType; -// using RecursiveFlavor = GoblinUltraRecursiveFlavor_; -// using RecursiveVerifier = UltraRecursiveVerifier_; -// using VerificationKey = typename RecursiveVerifier::VerificationKey; - -// // Helper for getting composer for prover/verifier of recursive (outer) circuit -// template static auto get_outer_composer() -// { -// if constexpr (IsGoblinBuilder) { -// return GoblinUltraComposer(); -// } else { -// return UltraComposer(); -// } -// } - -// /** -// * @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified -// * -// * @param builder -// * @param public_inputs -// * @param log_num_gates -// */ -// static InnerBuilder create_inner_circuit(size_t log_num_gates = 10) -// { -// using fr_ct = InnerCurve::ScalarField; -// using fq_ct = InnerCurve::BaseField; -// using point_ct = InnerCurve::AffineElement; -// using public_witness_ct = InnerCurve::public_witness_ct; -// using witness_ct = InnerCurve::witness_ct; -// using byte_array_ct = InnerCurve::byte_array_ct; -// using fr = typename InnerCurve::ScalarFieldNative; -// using point = typename InnerCurve::GroupNative::affine_element; - -// // Instantiate ECC op queue and add mock data to simulate interaction with a previous circuit -// auto op_queue = std::make_shared(); -// op_queue->populate_with_mock_initital_data(); - -// InnerBuilder builder(op_queue); - -// // Create 2^log_n many add gates based on input log num gates -// const size_t num_gates = 1 << log_num_gates; -// for (size_t i = 0; i < num_gates; ++i) { -// fr a = fr::random_element(); -// uint32_t a_idx = builder.add_variable(a); - -// fr b = fr::random_element(); -// fr c = fr::random_element(); -// fr d = a + b + c; -// uint32_t b_idx = builder.add_variable(b); -// uint32_t c_idx = builder.add_variable(c); -// uint32_t d_idx = builder.add_variable(d); - -// builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); -// } - -// // Add some arbitrary goblin-style ECC op gates via a batch mul -// size_t num_points = 5; -// std::vector circuit_points; -// std::vector circuit_scalars; -// for (size_t i = 0; i < num_points; ++i) { -// circuit_points.push_back(point_ct::from_witness(&builder, point::random_element())); -// circuit_scalars.push_back(fr_ct::from_witness(&builder, fr::random_element())); -// } -// point_ct::batch_mul(circuit_points, circuit_scalars); - -// // Define some additional arbitrary convetional circuit logic -// fr_ct a(public_witness_ct(&builder, fr::random_element())); -// fr_ct b(public_witness_ct(&builder, fr::random_element())); -// fr_ct c(public_witness_ct(&builder, fr::random_element())); - -// for (size_t i = 0; i < 32; ++i) { -// a = (a * b) + b + a; -// a = a.madd(b, c); -// } -// pedersen_hash::hash({ a, b }); -// byte_array_ct to_hash(&builder, "nonsense test data"); -// blake3s(to_hash); - -// fr bigfield_data = fr::random_element(); -// fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; -// fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - -// fq_ct big_a(fr_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), fr_ct(witness_ct(&builder, -// 0))); fq_ct big_b(fr_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), -// fr_ct(witness_ct(&builder, 0))); - -// big_a* big_b; - -// return builder; -// }; - -// public: -// static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } - -// /** -// * @brief Create inner circuit and call check_circuit on it -// * -// */ -// static void test_inner_circuit() -// { -// auto inner_circuit = create_inner_circuit(); - -// bool result = inner_circuit.check_circuit(); -// EXPECT_EQ(result, true); -// } - -// /** -// * @brief Instantiate a recursive verification key from the native verification key produced by the inner cicuit -// * builder. Check consistency beteen the native and stdlib types. -// * -// */ -// static void test_recursive_verification_key_creation() -// { -// // Create an arbitrary inner circuit -// auto inner_circuit = create_inner_circuit(); -// OuterBuilder outer_circuit; - -// // Compute native verification key -// InnerComposer inner_composer; -// auto instance = inner_composer.create_prover_instance(inner_circuit); -// // auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK -// auto verification_key = std::make_shared(instance->proving_key); -// // Instantiate the recursive verifier using the native verification key -// RecursiveVerifier verifier{ &outer_circuit, verification_key }; - -// // Spot check some values in the recursive VK to ensure it was constructed correctly -// EXPECT_EQ(verifier.key->circuit_size, verification_key->circuit_size); -// EXPECT_EQ(verifier.key->log_circuit_size, verification_key->log_circuit_size); -// EXPECT_EQ(verifier.key->num_public_inputs, verification_key->num_public_inputs); -// EXPECT_EQ(verifier.key->q_m.get_value(), verification_key->q_m); -// EXPECT_EQ(verifier.key->q_r.get_value(), verification_key->q_r); -// EXPECT_EQ(verifier.key->sigma_1.get_value(), verification_key->sigma_1); -// EXPECT_EQ(verifier.key->id_3.get_value(), verification_key->id_3); -// EXPECT_EQ(verifier.key->lagrange_ecc_op.get_value(), verification_key->lagrange_ecc_op); -// } - -// /** -// * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on -// it -// * -// */ -// static void test_recursive_verification() -// { -// // Create an arbitrary inner circuit -// auto inner_circuit = create_inner_circuit(); - -// // Generate a proof over the inner circuit -// InnerComposer inner_composer; -// auto instance = inner_composer.create_prover_instance(inner_circuit); -// auto verification_key = std::make_shared(instance->proving_key); -// auto inner_prover = inner_composer.create_prover(instance); -// auto inner_proof = inner_prover.construct_proof(); - -// // Create a recursive verification circuit for the proof of the inner circuit -// OuterBuilder outer_circuit; -// RecursiveVerifier verifier{ &outer_circuit, verification_key }; -// auto pairing_points = verifier.verify_proof(inner_proof); -// info("Recursive Verifier Goblin: num gates = ", outer_circuit.num_gates); - -// // Check for a failure flag in the recursive verifier circuit -// EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err(); - -// // Check 1: Perform native verification then perform the pairing on the outputs of the recursive -// // verifier and check that the result agrees. -// auto native_verifier = inner_composer.create_verifier(verification_key); -// auto native_result = native_verifier.verify_proof(inner_proof); -// auto recursive_result = native_verifier.pcs_verification_key->pairing_check(pairing_points[0].get_value(), -// pairing_points[1].get_value()); -// EXPECT_EQ(recursive_result, native_result); - -// // Check 2: Ensure that the underlying native and recursive verification algorithms agree by ensuring -// // the manifests produced by each agree. -// auto recursive_manifest = verifier.transcript->get_manifest(); -// auto native_manifest = native_verifier.transcript->get_manifest(); -// for (size_t i = 0; i < recursive_manifest.size(); ++i) { -// EXPECT_EQ(recursive_manifest[i], native_manifest[i]); -// } - -// // Check 3: Construct and verify a proof of the recursive verifier circuit -// { -// auto composer = get_outer_composer(); -// auto instance = composer.create_prover_instance(outer_circuit); -// auto prover = composer.create_prover(instance); -// auto verification_key = std::make_shared(instance->proving_key); -// auto verifier = composer.create_verifier(verification_key); -// auto proof = prover.construct_proof(); -// bool verified = verifier.verify_proof(proof); - -// ASSERT(verified); -// } -// } - -// /** -// * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure -// * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would -// be -// * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is -// * wrong. This is difficult now but should be straightforward if the proof is a struct. -// */ -// static void test_recursive_verification_fails() -// { -// // Create an arbitrary inner circuit -// auto inner_circuit = create_inner_circuit(); - -// // Generate a proof over the inner circuit -// InnerComposer inner_composer; -// auto instance = inner_composer.create_prover_instance(inner_circuit); -// auto inner_prover = inner_composer.create_prover(instance); -// auto inner_proof = inner_prover.construct_proof(); - -// // Arbitrarily tamper with the proof to be verified -// inner_prover.transcript->deserialize_full_transcript(); -// inner_prover.transcript->sorted_accum_comm = InnerCommitment::one() * InnerFF::random_element(); -// inner_prover.transcript->serialize_full_transcript(); -// inner_proof = inner_prover.export_proof(); - -// // Create a recursive verification circuit for the proof of the inner circuit -// OuterBuilder outer_circuit; -// auto verification_key = std::make_shared(instance->proving_key); -// RecursiveVerifier verifier{ &outer_circuit, verification_key }; -// verifier.verify_proof(inner_proof); - -// // We expect the circuit check to fail due to the bad proof -// EXPECT_FALSE(outer_circuit.check_circuit()); -// } -// }; - -// // Run the recursive verifier tests with conventional Ultra builder and Goblin builder -// using BuilderTypes = testing::Types; - -// TYPED_TEST_SUITE(GoblinRecursiveVerifierTest, BuilderTypes); - -// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, InnerCircuit) -// { -// TestFixture::test_inner_circuit(); -// } - -// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, RecursiveVerificationKey) -// { -// TestFixture::test_recursive_verification_key_creation(); -// } - -// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerification) -// { -// TestFixture::test_recursive_verification(); -// }; - -// HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerificationFailure) -// { -// TestFixture::test_recursive_verification_fails(); -// }; - -// } // namespace bb::stdlib::recursion::honk \ No newline at end of file +#include "barretenberg/common/test.hpp" +#include "barretenberg/flavor/ultra_recursive.hpp" +#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" +#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/primitives/curves/bn254.hpp" +#include "barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.hpp" +#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/ultra_honk/ultra_verifier.hpp" + +namespace bb::stdlib::recursion::honk { + +/** + * @brief Test suite for recursive verification of Goblin Ultra Honk proofs + * @details The recursive verification circuit is arithmetized in two different ways: 1) using the conventional Ultra + * arithmetization (UltraCircuitBuilder), or 2) a Goblin-style Ultra arithmetization (GoblinUltraCircuitBuilder). + * + * @tparam Builder Circuit builder for the recursive verifier circuit + */ +template class GoblinRecursiveVerifierTest : public testing::Test { + + using UltraComposer = UltraComposer_; + using GoblinUltraComposer = UltraComposer_; + + // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified + using InnerFlavor = GoblinUltraFlavor; + using InnerComposer = GoblinUltraComposer; + using InnerBuilder = typename InnerComposer::CircuitBuilder; + using InnerCurve = bn254; + using InnerCommitment = InnerFlavor::Commitment; + using InnerFF = InnerFlavor::FF; + + // Types for recursive verifier circuit + using OuterBuilder = BuilderType; + using RecursiveFlavor = GoblinUltraRecursiveFlavor_; + using RecursiveVerifier = UltraRecursiveVerifier_; + using VerificationKey = typename RecursiveVerifier::VerificationKey; + + // Helper for getting composer for prover/verifier of recursive (outer) circuit + template static auto get_outer_composer() + { + if constexpr (IsGoblinBuilder) { + return GoblinUltraComposer(); + } else { + return UltraComposer(); + } + } + + /** + * @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified + * + * @param builder + * @param public_inputs + * @param log_num_gates + */ + static InnerBuilder create_inner_circuit(size_t log_num_gates = 10) + { + using fr_ct = InnerCurve::ScalarField; + using fq_ct = InnerCurve::BaseField; + using point_ct = InnerCurve::AffineElement; + using public_witness_ct = InnerCurve::public_witness_ct; + using witness_ct = InnerCurve::witness_ct; + using byte_array_ct = InnerCurve::byte_array_ct; + using fr = typename InnerCurve::ScalarFieldNative; + using point = typename InnerCurve::GroupNative::affine_element; + + // Instantiate ECC op queue and add mock data to simulate interaction with a previous circuit + auto op_queue = std::make_shared(); + op_queue->populate_with_mock_initital_data(); + + InnerBuilder builder(op_queue); + + // Create 2^log_n many add gates based on input log num gates + const size_t num_gates = 1 << log_num_gates; + for (size_t i = 0; i < num_gates; ++i) { + fr a = fr::random_element(); + uint32_t a_idx = builder.add_variable(a); + + fr b = fr::random_element(); + fr c = fr::random_element(); + fr d = a + b + c; + uint32_t b_idx = builder.add_variable(b); + uint32_t c_idx = builder.add_variable(c); + uint32_t d_idx = builder.add_variable(d); + + builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); + } + + // Add some arbitrary goblin-style ECC op gates via a batch mul + size_t num_points = 5; + std::vector circuit_points; + std::vector circuit_scalars; + for (size_t i = 0; i < num_points; ++i) { + circuit_points.push_back(point_ct::from_witness(&builder, point::random_element())); + circuit_scalars.push_back(fr_ct::from_witness(&builder, fr::random_element())); + } + point_ct::batch_mul(circuit_points, circuit_scalars); + + // Define some additional arbitrary convetional circuit logic + fr_ct a(public_witness_ct(&builder, fr::random_element())); + fr_ct b(public_witness_ct(&builder, fr::random_element())); + fr_ct c(public_witness_ct(&builder, fr::random_element())); + + for (size_t i = 0; i < 32; ++i) { + a = (a * b) + b + a; + a = a.madd(b, c); + } + pedersen_hash::hash({ a, b }); + byte_array_ct to_hash(&builder, "nonsense test data"); + blake3s(to_hash); + + fr bigfield_data = fr::random_element(); + fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; + fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; + + fq_ct big_a(fr_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), fr_ct(witness_ct(&builder, 0))); + fq_ct big_b(fr_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), fr_ct(witness_ct(&builder, 0))); + + big_a* big_b; + + return builder; + }; + + public: + static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } + + /** + * @brief Create inner circuit and call check_circuit on it + * + */ + static void test_inner_circuit() + { + auto inner_circuit = create_inner_circuit(); + + bool result = inner_circuit.check_circuit(); + EXPECT_EQ(result, true); + } + + /** + * @brief Instantiate a recursive verification key from the native verification key produced by the inner cicuit + * builder. Check consistency beteen the native and stdlib types. + * + */ + static void test_recursive_verification_key_creation() + { + // Create an arbitrary inner circuit + auto inner_circuit = create_inner_circuit(); + OuterBuilder outer_circuit; + + // Compute native verification key + InnerComposer inner_composer; + auto instance = inner_composer.create_prover_instance(inner_circuit); + // auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK + auto verification_key = std::make_shared(instance->proving_key); + // Instantiate the recursive verifier using the native verification key + RecursiveVerifier verifier{ &outer_circuit, verification_key }; + + // Spot check some values in the recursive VK to ensure it was constructed correctly + EXPECT_EQ(verifier.key->circuit_size, verification_key->circuit_size); + EXPECT_EQ(verifier.key->log_circuit_size, verification_key->log_circuit_size); + EXPECT_EQ(verifier.key->num_public_inputs, verification_key->num_public_inputs); + EXPECT_EQ(verifier.key->q_m.get_value(), verification_key->q_m); + EXPECT_EQ(verifier.key->q_r.get_value(), verification_key->q_r); + EXPECT_EQ(verifier.key->sigma_1.get_value(), verification_key->sigma_1); + EXPECT_EQ(verifier.key->id_3.get_value(), verification_key->id_3); + EXPECT_EQ(verifier.key->lagrange_ecc_op.get_value(), verification_key->lagrange_ecc_op); + } + + /** + * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on + it + * + */ + static void test_recursive_verification() + { + // Create an arbitrary inner circuit + auto inner_circuit = create_inner_circuit(); + + // Generate a proof over the inner circuit + InnerComposer inner_composer; + auto instance = inner_composer.create_prover_instance(inner_circuit); + auto verification_key = std::make_shared(instance->proving_key); + auto inner_prover = inner_composer.create_prover(instance); + auto inner_proof = inner_prover.construct_proof(); + + // Create a recursive verification circuit for the proof of the inner circuit + OuterBuilder outer_circuit; + RecursiveVerifier verifier{ &outer_circuit, verification_key }; + auto pairing_points = verifier.verify_proof(inner_proof); + info("Recursive Verifier Goblin: num gates = ", outer_circuit.num_gates); + + // Check for a failure flag in the recursive verifier circuit + EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err(); + + // Check 1: Perform native verification then perform the pairing on the outputs of the recursive + // verifier and check that the result agrees. + auto native_verifier = inner_composer.create_verifier(verification_key); + auto native_result = native_verifier.verify_proof(inner_proof); + auto recursive_result = native_verifier.pcs_verification_key->pairing_check(pairing_points[0].get_value(), + pairing_points[1].get_value()); + EXPECT_EQ(recursive_result, native_result); + + // Check 2: Ensure that the underlying native and recursive verification algorithms agree by ensuring + // the manifests produced by each agree. + auto recursive_manifest = verifier.transcript->get_manifest(); + auto native_manifest = native_verifier.transcript->get_manifest(); + for (size_t i = 0; i < recursive_manifest.size(); ++i) { + EXPECT_EQ(recursive_manifest[i], native_manifest[i]); + } + + // Check 3: Construct and verify a proof of the recursive verifier circuit + { + auto composer = get_outer_composer(); + auto instance = composer.create_prover_instance(outer_circuit); + auto prover = composer.create_prover(instance); + auto verifier_instance = composer.create_verifier_instance(instance); + auto verifier = composer.create_verifier(verifier_instance->verification_key); + auto proof = prover.construct_proof(); + bool verified = verifier.verify_proof(proof); + + ASSERT(verified); + } + } + + /** + * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure + * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would + be + * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is + * wrong. This is difficult now but should be straightforward if the proof is a struct. + */ + static void test_recursive_verification_fails() + { + // Create an arbitrary inner circuit + auto inner_circuit = create_inner_circuit(); + + // Generate a proof over the inner circuit + InnerComposer inner_composer; + auto instance = inner_composer.create_prover_instance(inner_circuit); + auto inner_prover = inner_composer.create_prover(instance); + auto inner_proof = inner_prover.construct_proof(); + + // Arbitrarily tamper with the proof to be verified + inner_prover.transcript->deserialize_full_transcript(); + inner_prover.transcript->sorted_accum_comm = InnerCommitment::one() * InnerFF::random_element(); + inner_prover.transcript->serialize_full_transcript(); + inner_proof = inner_prover.export_proof(); + + // Generate the corresponding inner verification key + auto inner_verification_key = std::make_shared(instance->proving_key); + + // Create a recursive verification circuit for the proof of the inner circuit + OuterBuilder outer_circuit; + RecursiveVerifier verifier{ &outer_circuit, inner_verification_key }; + verifier.verify_proof(inner_proof); + + // We expect the circuit check to fail due to the bad proof + EXPECT_FALSE(outer_circuit.check_circuit()); + } +}; + +// Run the recursive verifier tests with conventional Ultra builder and Goblin builder +using BuilderTypes = testing::Types; + +TYPED_TEST_SUITE(GoblinRecursiveVerifierTest, BuilderTypes); + +HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, InnerCircuit) +{ + TestFixture::test_inner_circuit(); +} + +HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, RecursiveVerificationKey) +{ + TestFixture::test_recursive_verification_key_creation(); +} + +HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerification) +{ + TestFixture::test_recursive_verification(); +}; + +HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, SingleRecursiveVerificationFailure) +{ + TestFixture::test_recursive_verification_fails(); +}; + +} // namespace bb::stdlib::recursion::honk \ No newline at end of file From aa355877780839b5ca5a3a17eda2bf1230d72eb7 Mon Sep 17 00:00:00 2001 From: maramihali Date: Mon, 4 Mar 2024 11:35:05 +0000 Subject: [PATCH 3/4] final cleanups --- barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp | 2 -- .../stdlib/recursion/honk/verifier/goblin_verifier.test.cpp | 1 - .../src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index edf398f6174..a17021b803c 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -115,7 +115,6 @@ void ClientIVC::precompute_folding_verification_keys() kernel_circuit, { function_fold_proof, vks.func_vk }, {}, initial_verifier_acc); auto kernel_fold_proof = accumulate(kernel_circuit); vks.first_kernel_vk = std::make_shared(prover_instance->proving_key); - ; // Create another mock function circuit to run the full kernel function_circuit = ClientCircuit{ goblin.op_queue }; @@ -129,7 +128,6 @@ void ClientIVC::precompute_folding_verification_keys() kernel_fold_proof = accumulate(kernel_circuit); vks.kernel_vk = std::make_shared(prover_instance->proving_key); - ; // Clean the ivc state goblin.op_queue = std::make_shared(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp index 78573d4442e..33800779a6b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp @@ -149,7 +149,6 @@ template class GoblinRecursiveVerifierTest : public testi // Compute native verification key InnerComposer inner_composer; auto instance = inner_composer.create_prover_instance(inner_circuit); - // auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK auto verification_key = std::make_shared(instance->proving_key); // Instantiate the recursive verifier using the native verification key RecursiveVerifier verifier{ &outer_circuit, verification_key }; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp index 17d7a1037aa..7ac3a91b378 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp @@ -25,7 +25,6 @@ class GoblinUltraHonkComposerTests : public ::testing::Test { using CommitmentKey = bb::CommitmentKey; using MergeProver = MergeProver_; using MergeVerifier = MergeVerifier_; - using VerificationKey = GoblinUltraFlavor::VerificationKey; /** * @brief Generate a simple test circuit with some ECC op gates and conventional arithmetic gates @@ -65,7 +64,7 @@ class GoblinUltraHonkComposerTests : public ::testing::Test { { auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); - auto verification_key = std::make_shared(instance->proving_key); + auto verification_key = std::make_shared(instance->proving_key); auto verifier = composer.create_verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); From 23152c6ec93f125d84cafb3361149f6a47d05ab7 Mon Sep 17 00:00:00 2001 From: maramihali Date: Mon, 4 Mar 2024 13:05:43 +0000 Subject: [PATCH 4/4] resolve review comments --- .../stdlib/recursion/honk/verifier/goblin_verifier.test.cpp | 4 ++-- .../stdlib/recursion/honk/verifier/merge_verifier.test.cpp | 1 + .../stdlib/recursion/honk/verifier/verifier.test.cpp | 6 ++---- .../src/barretenberg/sumcheck/instance/prover_instance.hpp | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp index 33800779a6b..e4b227e57b8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp @@ -211,6 +211,7 @@ template class GoblinRecursiveVerifierTest : public testi auto composer = get_outer_composer(); auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); + TODO: // github.com/AztecProtocol/barretenberg/issues/892 auto verifier_instance = composer.create_verifier_instance(instance); auto verifier = composer.create_verifier(verifier_instance->verification_key); auto proof = prover.construct_proof(); @@ -222,8 +223,7 @@ template class GoblinRecursiveVerifierTest : public testi /** * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure - * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would - be + * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would be * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is * wrong. This is difficult now but should be straightforward if the proof is a struct. */ diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp index 69105a3fc8e..ca58db33acc 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp @@ -83,6 +83,7 @@ class RecursiveMergeVerifierTest : public testing::Test { GoblinUltraComposer composer; auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); + // TODO: github.com/AztecProtocol/barretenberg/issues/892 auto verifier_instance = composer.create_verifier_instance(instance); auto verifier = composer.create_verifier(verifier_instance->verification_key); auto proof = prover.construct_proof(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp index 6d4f4914005..fd1eddeebe1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp @@ -147,8 +147,7 @@ template class RecursiveVerifierTest : public testing::Te } /** - * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on - it + * @brief Construct a recursive verification circuit for the proof of an inner circuit then call check_circuit on it * */ static void test_recursive_verification() @@ -206,8 +205,7 @@ template class RecursiveVerifierTest : public testing::Te /** * @brief Construct a verifier circuit for a proof whose data has been tampered with. Expect failure - * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would - be + * TODO(bberg #656): For now we get a "bad" proof by arbitrarily tampering with bits in a valid proof. It would be * much nicer to explicitly change meaningful components, e.g. such that one of the multilinear evaluations is * wrong. This is difficult now but should be straightforward if the proof is a struct. */ diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 255f14f74e6..c11f3ebb74a 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -36,7 +36,6 @@ template class ProverInstance_ { // currently commitment_key needs to be here, and not accessed through the proving key, since sometimes the proving // key is null during protogalaxy proving (TODO(https://github.com/AztecProtocol/barretenberg/issues/881)?) std::shared_ptr commitment_key; - std::shared_ptr verification_key; ProverPolynomials prover_polynomials; WitnessCommitments witness_commitments;