From e9c2cc9c82ef177ab223fc2f120eec1cd7ad1544 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 12 Jan 2024 20:30:59 +0000 Subject: [PATCH 1/7] Xray script restricted to build desired target --- barretenberg/cpp/scripts/collect_profile_information.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/scripts/collect_profile_information.sh b/barretenberg/cpp/scripts/collect_profile_information.sh index ebc0249392e..1323e157b02 100755 --- a/barretenberg/cpp/scripts/collect_profile_information.sh +++ b/barretenberg/cpp/scripts/collect_profile_information.sh @@ -15,7 +15,7 @@ cd $(dirname $0)/.. # Configure and build with xray preset. cmake --preset $PRESET -cmake --build --preset $PRESET +cmake --build --preset $PRESET --target $EXECUTABLE cd build-$PRESET From 0d19aaa76e5e287e2574c7eb85aaab2b441889c8 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 12 Jan 2024 20:51:29 +0000 Subject: [PATCH 2/7] Remove vk computation from xray --- .../protogalaxy_bench/protogalaxy.bench.cpp | 2 +- .../ultra_bench/benchmark_utilities.hpp | 3 ++- .../cpp/src/barretenberg/goblin/goblin.hpp | 4 +-- .../protogalaxy/decider_prover.cpp | 6 ----- .../protogalaxy/protogalaxy_prover.cpp | 27 ------------------- .../protogalaxy/protogalaxy_prover.hpp | 1 - .../honk/verifier/goblin_verifier.test.cpp | 8 +++--- .../honk/verifier/merge_verifier.test.cpp | 2 +- .../recursion/honk/verifier/verifier.test.cpp | 8 +++--- .../sumcheck/instance/prover_instance.hpp | 2 -- .../ultra_honk/databus_composer.test.cpp | 2 +- .../ultra_honk/goblin_ultra_composer.test.cpp | 2 +- .../goblin_ultra_transcript.test.cpp | 6 ++--- .../ultra_honk/protogalaxy.test.cpp | 20 +++++++------- .../ultra_honk/relation_correctness.test.cpp | 4 +-- .../barretenberg/ultra_honk/sumcheck.test.cpp | 2 +- .../ultra_honk/ultra_composer.cpp | 26 +++++++++--------- .../ultra_honk/ultra_composer.hpp | 21 ++++++++------- .../ultra_honk/ultra_composer.test.cpp | 6 ++--- .../ultra_honk/ultra_transcript.test.cpp | 6 ++--- 20 files changed, 62 insertions(+), 96 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp index 4153499e672..edfeb2f0d1a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp @@ -24,7 +24,7 @@ void fold_one(State& state) noexcept const auto construct_instance = [&]() { Builder builder; bench_utils::generate_basic_arithmetic_circuit(builder, log2_num_gates); - return composer.create_instance(builder); + return composer.create_prover_instance(builder); }; std::shared_ptr instance_1 = construct_instance(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp index 0ef9fabfa0a..a8c4b86a405 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp @@ -174,7 +174,8 @@ inline proof_system::honk::UltraProver get_prover( { proof_system::honk::UltraComposer::CircuitBuilder builder; test_circuit_function(builder, num_iterations); - std::shared_ptr instance = composer.create_instance(builder); + std::shared_ptr instance = + composer.create_prover_instance(builder); return composer.create_prover(instance); } diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 164b29e0600..a2a289a8db3 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -104,7 +104,7 @@ class Goblin { // Construct a Honk proof for the main circuit GoblinUltraComposer composer; - auto instance = composer.create_instance(circuit_builder); + auto instance = composer.create_prover_instance(circuit_builder); auto prover = composer.create_prover(instance); auto ultra_proof = prover.construct_proof(); @@ -174,7 +174,7 @@ class Goblin { // Construct a Honk proof for the main circuit GoblinUltraComposer composer; - auto instance = composer.create_instance(circuit_builder); + auto instance = composer.create_prover_instance(circuit_builder); auto prover = composer.create_prover(instance); auto ultra_proof = prover.construct_proof(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp index eea53966aa6..c0d4d201fb7 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp @@ -57,12 +57,6 @@ template void DeciderProver_::execute_preamble_roun for (size_t idx = 0; idx < witness_labels.size(); idx++) { transcript->send_to_verifier(witness_labels[idx], comm_view[idx]); } - - auto vk_view = accumulator->verification_key->get_all(); - auto vk_labels = accumulator->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < vk_labels.size(); idx++) { - transcript->send_to_verifier(vk_labels[idx], vk_view[idx]); - } } /** diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index e735ff8cab9..772375bc392 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -59,11 +59,6 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) { instance->alphas[idx] = transcript->get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); } - auto vk_view = instance->verification_key->get_all(); - auto labels = instance->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < labels.size(); idx++) { - transcript->send_to_verifier(domain_separator + "_" + labels[idx], vk_view[idx]); - } } template @@ -103,12 +98,6 @@ void ProtoGalaxyProver_::send_accumulator(std::shared_ptrsend_to_verifier(domain_separator + "_" + witness_labels[idx], comm_view[idx]); } - - auto vk_view = instance->verification_key->get_all(); - auto vk_labels = instance->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < vk_labels.size(); idx++) { - transcript->send_to_verifier(domain_separator + "_" + vk_labels[idx], vk_view[idx]); - } } template void ProtoGalaxyProver_::prepare_for_folding() @@ -250,22 +239,6 @@ std::shared_ptr ProtoGalaxyProver_relation_parameters = folded_relation_parameters; - // Fold the verification key and send it to the verifier as this is part of ϕ as well - auto acc_vk = std::make_shared(instances[0]->prover_polynomials.get_polynomial_size(), - instances[0]->public_inputs.size()); - auto labels = next_accumulator->commitment_labels.get_precomputed(); - size_t vk_idx = 0; - for (auto& vk : acc_vk->get_all()) { - size_t inst = 0; - vk = Commitment::infinity(); - for (auto& instance : instances) { - vk = vk + (instance->verification_key->get_all()[vk_idx]) * lagranges[inst]; - inst++; - } - transcript->send_to_verifier("next_" + labels[vk_idx], vk); - vk_idx++; - } - next_accumulator->verification_key = acc_vk; return next_accumulator; } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index f9eed3b6bb2..7328b89ef7f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -25,7 +25,6 @@ template class ProtoGalaxyProver_ { using Relations = typename Flavor::Relations; using RelationSeparator = typename Flavor::RelationSeparator; using CombinedRelationSeparator = typename ProverInstances::RelationSeparator; - using VerificationKey = typename Flavor::VerificationKey; using CommitmentKey = typename Flavor::CommitmentKey; using WitnessCommitments = typename Flavor::WitnessCommitments; using Commitment = typename Flavor::Commitment; 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 5263c6b90c0..f085b67900d 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 @@ -151,7 +151,7 @@ template class GoblinRecursiveVerifierTest : public testi // Compute native verification key InnerComposer inner_composer; - auto instance = inner_composer.create_instance(inner_circuit); + auto instance = inner_composer.create_prover_instance(inner_circuit); auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK // Instantiate the recursive verifier using the native verification key @@ -179,7 +179,7 @@ template class GoblinRecursiveVerifierTest : public testi // Generate a proof over the inner circuit InnerComposer inner_composer; - auto instance = inner_composer.create_instance(inner_circuit); + auto instance = inner_composer.create_prover_instance(inner_circuit); auto inner_prover = inner_composer.create_prover(instance); auto inner_proof = inner_prover.construct_proof(); @@ -211,7 +211,7 @@ template class GoblinRecursiveVerifierTest : public testi // Check 3: Construct and verify a proof of the recursive verifier circuit { auto composer = get_outer_composer(); - auto instance = composer.create_instance(outer_circuit); + auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); auto verifier = composer.create_verifier(instance); auto proof = prover.construct_proof(); @@ -234,7 +234,7 @@ template class GoblinRecursiveVerifierTest : public testi // Generate a proof over the inner circuit InnerComposer inner_composer; - auto instance = inner_composer.create_instance(inner_circuit); + auto instance = inner_composer.create_prover_instance(inner_circuit); auto inner_prover = inner_composer.create_prover(instance); auto inner_proof = inner_prover.construct_proof(); 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 765759e1722..91b23694896 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 @@ -81,7 +81,7 @@ class RecursiveMergeVerifierTest : public testing::Test { // Check 3: Construct and verify a (goblin) ultra honk proof of the Merge recursive verifier circuit { GoblinUltraComposer composer; - auto instance = composer.create_instance(outer_circuit); + auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); auto verifier = composer.create_verifier(instance); 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 49b8882d759..6eb02d092ed 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 @@ -134,7 +134,7 @@ template class RecursiveVerifierTest : public testing::Te // Compute native verification key InnerComposer inner_composer; - auto instance = inner_composer.create_instance(inner_circuit); + auto instance = inner_composer.create_prover_instance(inner_circuit); auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK // Instantiate the recursive verifier using the native verification key @@ -162,7 +162,7 @@ template class RecursiveVerifierTest : public testing::Te // Generate a proof over the inner circuit InnerComposer inner_composer; - auto instance = inner_composer.create_instance(inner_circuit); + auto instance = inner_composer.create_prover_instance(inner_circuit); auto inner_prover = inner_composer.create_prover(instance); auto inner_proof = inner_prover.construct_proof(); @@ -194,7 +194,7 @@ template class RecursiveVerifierTest : public testing::Te // Check 3: Construct and verify a proof of the recursive verifier circuit { auto composer = get_outer_composer(); - auto instance = composer.create_instance(outer_circuit); + auto instance = composer.create_prover_instance(outer_circuit); auto prover = composer.create_prover(instance); auto verifier = composer.create_verifier(instance); auto proof = prover.construct_proof(); @@ -218,7 +218,7 @@ template class RecursiveVerifierTest : public testing::Te // Generate a proof over the inner circuit InnerComposer inner_composer; - auto instance = inner_composer.create_instance(inner_circuit); + auto instance = inner_composer.create_prover_instance(inner_circuit); auto inner_prover = inner_composer.create_prover(instance); auto inner_proof = inner_prover.construct_proof(); diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 8c5e91b2e23..703daa74419 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -19,7 +19,6 @@ namespace proof_system::honk { template class ProverInstance_ { using Circuit = typename Flavor::CircuitBuilder; using ProvingKey = typename Flavor::ProvingKey; - using VerificationKey = typename Flavor::VerificationKey; using CommitmentKey = typename Flavor::CommitmentKey; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; @@ -30,7 +29,6 @@ template class ProverInstance_ { public: std::shared_ptr proving_key; - std::shared_ptr verification_key; ProverPolynomials prover_polynomials; WitnessCommitments witness_commitments; 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 e9adb253f0c..f47d96a98bb 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,7 @@ TEST_F(DataBusComposerTests, CallDataRead) auto composer = GoblinUltraComposer(); // Construct and verify Honk proof - auto instance = composer.create_instance(builder); + 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); 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 52bc8aa9a03..bcf0ae1706d 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 @@ -61,7 +61,7 @@ class GoblinUltraHonkComposerTests : public ::testing::Test { */ bool construct_and_verify_honk_proof(auto& composer, auto& builder) { - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto verifier = composer.create_verifier(instance); auto proof = prover.construct_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 5f7cc775fbf..03b3270d028 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 @@ -145,7 +145,7 @@ TEST_F(GoblinUltraTranscriptTests, ProverManifestConsistency) // Automatically generate a transcript manifest by constructing a proof auto composer = GoblinUltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); @@ -172,7 +172,7 @@ TEST_F(GoblinUltraTranscriptTests, VerifierManifestConsistency) // Automatically generate a transcript manifest in the prover by constructing a proof auto composer = GoblinUltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); @@ -223,7 +223,7 @@ TEST_F(GoblinUltraTranscriptTests, StructureTest) // Automatically generate a transcript manifest by constructing a proof auto composer = GoblinUltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); auto verifier = composer.create_verifier(instance); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp index f2f14ab43b4..02c79d209af 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp @@ -105,7 +105,7 @@ TEST_F(ProtoGalaxyTests, FullHonkEvaluationsValidCircuit) builder.create_add_gate({ a_idx, b_idx, c_idx, 1, 1, -1, 0 }); auto composer = UltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); instance->initialize_prover_polynomials(); auto eta = FF::random_element(); @@ -266,12 +266,12 @@ TEST_F(ProtoGalaxyTests, FullProtogalaxyTest) auto builder_1 = typename Flavor::CircuitBuilder(); builder_1.add_public_variable(FF(1)); - auto instance_1 = composer.create_instance(builder_1); + auto instance_1 = composer.create_prover_instance(builder_1); auto builder_2 = typename Flavor::CircuitBuilder(); builder_2.add_public_variable(FF(1)); - auto instance_2 = composer.create_instance(builder_2); + auto instance_2 = composer.create_prover_instance(builder_2); auto instances = std::vector>{ instance_1, instance_2 }; auto first_accumulator = fold_and_verify(instances, composer, true); @@ -279,7 +279,7 @@ TEST_F(ProtoGalaxyTests, FullProtogalaxyTest) auto builder_3 = typename Flavor::CircuitBuilder(); builder_3.add_public_variable(FF(1)); - auto instance_3 = composer.create_instance(builder_3); + auto instance_3 = composer.create_prover_instance(builder_3); instances = std::vector>{ first_accumulator, instance_3 }; auto second_accumulator = fold_and_verify(instances, composer, true); @@ -295,12 +295,12 @@ TEST_F(ProtoGalaxyTests, TamperedCommitment) auto builder_1 = typename Flavor::CircuitBuilder(); builder_1.add_public_variable(FF(1)); - auto instance_1 = composer.create_instance(builder_1); + auto instance_1 = composer.create_prover_instance(builder_1); auto builder_2 = typename Flavor::CircuitBuilder(); builder_2.add_public_variable(FF(1)); - auto instance_2 = composer.create_instance(builder_2); + auto instance_2 = composer.create_prover_instance(builder_2); auto instances = std::vector>{ instance_1, instance_2 }; auto first_accumulator = fold_and_verify(instances, composer, true); @@ -308,7 +308,7 @@ TEST_F(ProtoGalaxyTests, TamperedCommitment) auto builder_3 = typename Flavor::CircuitBuilder(); builder_3.add_public_variable(FF(1)); - auto instance_3 = composer.create_instance(builder_3); + auto instance_3 = composer.create_prover_instance(builder_3); // tampering with the commitment should cause the decider to fail first_accumulator->witness_commitments.w_l = Projective(Affine::random_element()); @@ -326,12 +326,12 @@ TEST_F(ProtoGalaxyTests, TamperedAccumulatorPolynomial) auto builder_1 = typename Flavor::CircuitBuilder(); builder_1.add_public_variable(FF(1)); - auto instance_1 = composer.create_instance(builder_1); + auto instance_1 = composer.create_prover_instance(builder_1); auto builder_2 = typename Flavor::CircuitBuilder(); builder_2.add_public_variable(FF(1)); - auto instance_2 = composer.create_instance(builder_2); + auto instance_2 = composer.create_prover_instance(builder_2); auto instances = std::vector>{ instance_1, instance_2 }; auto first_accumulator = fold_and_verify(instances, composer, true); @@ -339,7 +339,7 @@ TEST_F(ProtoGalaxyTests, TamperedAccumulatorPolynomial) auto builder_3 = typename Flavor::CircuitBuilder(); builder_3.add_public_variable(FF(1)); - auto instance_3 = composer.create_instance(builder_3); + auto instance_3 = composer.create_prover_instance(builder_3); // tampering with accumulator's polynomial should cause both folding and deciding to fail instances = std::vector>{ first_accumulator, instance_3 }; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp index 5cc43dad5fc..e7be78858f1 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -269,7 +269,7 @@ TEST_F(RelationCorrectnessTests, UltraRelationCorrectness) // Create a prover (it will compute proving key and witness) auto composer = UltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto proving_key = instance->proving_key; auto circuit_size = proving_key->circuit_size; @@ -322,7 +322,7 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) // Create a prover (it will compute proving key and witness) auto composer = GoblinUltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto proving_key = instance->proving_key; auto circuit_size = proving_key->circuit_size; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp index 09815ab23c8..cda43b0a9ff 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp @@ -150,7 +150,7 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) // Create a prover (it will compute proving key and witness) auto composer = UltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); // Generate eta, beta and gamma FF eta = FF::random_element(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp index 359c58b7949..c3b5e92b92d 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp @@ -12,13 +12,14 @@ namespace proof_system::honk { * @return Pointer to the resulting verification key of the Instance. * */ template -void UltraComposer_::compute_verification_key(const std::shared_ptr>& instance) +void UltraComposer_::compute_verification_key(std::shared_ptr>& prover_instance, + std::shared_ptr>& verifier_instance) { - if (instance->verification_key) { + if (verifier_instance->verification_key) { return; } - auto& proving_key = instance->proving_key; + auto& proving_key = prover_instance->proving_key; auto verification_key = std::make_shared(proving_key->circuit_size, proving_key->num_public_inputs); @@ -61,23 +62,22 @@ void UltraComposer_::compute_verification_key(const std::shared_ptrq_poseidon2_internal = commitment_key->commit(proving_key->q_poseidon2_internal); } - instance->verification_key = std::move(verification_key); + verifier_instance->verification_key = std::move(verification_key); } template -std::shared_ptr> UltraComposer_::create_instance(CircuitBuilder& circuit) +std::shared_ptr> UltraComposer_::create_prover_instance(CircuitBuilder& circuit) { circuit.add_gates_to_ensure_all_polys_are_non_zero(); circuit.finalize_circuit(); - auto instance = std::make_shared(circuit); + auto instance = std::make_shared(circuit); commitment_key = compute_commitment_key(instance->proving_key->circuit_size); - compute_verification_key(instance); return instance; } template -UltraProver_ UltraComposer_::create_prover(const std::shared_ptr& instance, +UltraProver_ UltraComposer_::create_prover(const std::shared_ptr& instance, const std::shared_ptr& transcript) { UltraProver_ output_state(instance, commitment_key, transcript); @@ -86,7 +86,7 @@ UltraProver_ UltraComposer_::create_prover(const std::shared_ptr } template -UltraVerifier_ UltraComposer_::create_verifier(const std::shared_ptr& instance, +UltraVerifier_ UltraComposer_::create_verifier(const std::shared_ptr& instance, const std::shared_ptr& transcript) { auto& verification_key = instance->verification_key; @@ -98,7 +98,7 @@ UltraVerifier_ UltraComposer_::create_verifier(const std::shared } template -DeciderProver_ UltraComposer_::create_decider_prover(const std::shared_ptr& accumulator, +DeciderProver_ UltraComposer_::create_decider_prover(const std::shared_ptr& accumulator, const std::shared_ptr& transcript) { commitment_key = compute_commitment_key(accumulator->instance_size); @@ -109,7 +109,7 @@ DeciderProver_ UltraComposer_::create_decider_prover(const std:: template DeciderProver_ UltraComposer_::create_decider_prover( - const std::shared_ptr& accumulator, + const std::shared_ptr& accumulator, const std::shared_ptr& commitment_key, const std::shared_ptr& transcript) { @@ -119,8 +119,8 @@ DeciderProver_ UltraComposer_::create_decider_prover( } template -DeciderVerifier_ UltraComposer_::create_decider_verifier(const std::shared_ptr& accumulator, - const std::shared_ptr& transcript) +DeciderVerifier_ UltraComposer_::create_decider_verifier( + const std::shared_ptr& accumulator, const std::shared_ptr& transcript) { auto& verification_key = accumulator->verification_key; DeciderVerifier_ output_state(transcript, verification_key); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp index 460e301afea..c132490005d 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp @@ -22,7 +22,7 @@ template class UltraComposer_ { using CommitmentKey = typename Flavor::CommitmentKey; using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; using ProverInstance = ProverInstance_; - using Instance = ProverInstance; + using VerifierInstance = VerifierInstance_; using FF = typename Flavor::FF; using Transcript = typename Flavor::Transcript; using CRSFactory = srs::factories::CrsFactory; @@ -59,25 +59,25 @@ template class UltraComposer_ { return commitment_key; }; - std::shared_ptr create_instance(CircuitBuilder& circuit); + std::shared_ptr create_prover_instance(CircuitBuilder& circuit); - UltraProver_ create_prover(const std::shared_ptr&, + UltraProver_ create_prover(const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); UltraVerifier_ create_verifier( - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); DeciderProver_ create_decider_prover( - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); DeciderProver_ create_decider_prover( - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); DeciderVerifier_ create_decider_verifier( - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); UltraVerifier_ create_verifier(CircuitBuilder& circuit); @@ -110,8 +110,9 @@ template class UltraComposer_ { */ MergeVerifier_ create_merge_verifier() { return MergeVerifier_(); } - ProtoGalaxyProver_ create_folding_prover(const std::vector>& instances, - const std::shared_ptr& commitment_key) + ProtoGalaxyProver_ create_folding_prover( + const std::vector>& instances, + const std::shared_ptr& commitment_key) { ProtoGalaxyProver_ output_state(instances, commitment_key); @@ -131,7 +132,7 @@ template class UltraComposer_ { * * @param inst */ - void compute_verification_key(const std::shared_ptr&); + void compute_verification_key(std::shared_ptr&, std::shared_ptr&); }; // TODO(#532): this pattern is weird; is this not instantiating the templates? 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 0f1e0e274a8..4b665fa40b2 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -35,7 +35,7 @@ std::vector add_variables(auto& circuit_builder, std::vectorproving_key; @@ -203,7 +203,7 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) } } auto composer = UltraComposer(); - auto instance = composer.create_instance(circuit_builder); + auto instance = composer.create_prover_instance(circuit_builder); auto prover = composer.create_prover(instance); auto verifier = composer.create_verifier(instance); auto proof = prover.construct_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 6e8b19a0891..61e5c19e31c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -130,7 +130,7 @@ TEST_F(UltraTranscriptTests, ProverManifestConsistency) // Automatically generate a transcript manifest by constructing a proof auto composer = UltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); @@ -157,7 +157,7 @@ TEST_F(UltraTranscriptTests, VerifierManifestConsistency) // Automatically generate a transcript manifest in the prover by constructing a proof auto composer = UltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); @@ -208,7 +208,7 @@ TEST_F(UltraTranscriptTests, StructureTest) // Automatically generate a transcript manifest by constructing a proof auto composer = UltraComposer(); - auto instance = composer.create_instance(builder); + auto instance = composer.create_prover_instance(builder); auto prover = composer.create_prover(instance); auto proof = prover.construct_proof(); auto verifier = composer.create_verifier(instance); From df7d6afc009f6e514eaa0441e0b3878bca368049 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 12 Jan 2024 21:07:52 +0000 Subject: [PATCH 3/7] Adjust benchmark ranges --- .../benchmark/protogalaxy_bench/protogalaxy.bench.cpp | 2 +- .../src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp index edfeb2f0d1a..e763b823aff 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp @@ -37,5 +37,5 @@ void fold_one(State& state) noexcept } } -BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); +BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(15, 20)->Unit(kMillisecond); } // namespace proof_system::honk \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp index 610f968157f..8b6e2e97177 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp @@ -44,5 +44,5 @@ BENCHMARK_CAPTURE(construct_proof_ultrahonk, BENCHMARK(construct_proof_ultrahonk_power_of_2) // 2**15 gates to 2**20 gates - ->DenseRange(15, 20) + ->DenseRange(14, 20) ->Unit(kMillisecond); \ No newline at end of file From 8da0cd918bd90d5ee8e912373bc29752d1218819 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 17 Jan 2024 22:53:19 +0000 Subject: [PATCH 4/7] Use vk or verifier instance --- .../cpp/src/barretenberg/goblin/goblin.hpp | 11 ++++- .../honk/verifier/goblin_verifier.test.cpp | 25 ++++++----- .../recursion/honk/verifier/verifier.test.cpp | 23 ++++++----- .../sumcheck/instance/verifier_instance.hpp | 13 ++++++ .../ultra_honk/protogalaxy.test.cpp | 30 +++++++------- .../ultra_honk/ultra_composer.cpp | 41 +++++++++++++++---- .../ultra_honk/ultra_composer.hpp | 13 +++++- 7 files changed, 107 insertions(+), 49 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 6a558f3fe78..dd0dc1110f8 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -26,6 +26,7 @@ class Goblin { * @brief Output of goblin::accumulate; an Ultra proof and the corresponding verification key * */ + // WORKTODO: this is being repurposed in the mock kernel circuit as KernelInput struct AccumulationOutput { HonkProof proof; std::shared_ptr verification_key; @@ -116,7 +117,10 @@ class Goblin { merge_proof_exists = true; } - return { ultra_proof, instance->verification_key }; + // WORKTODO: proper handling + auto verifier_instance = composer.create_verifier_instance(instance); + + return { ultra_proof, verifier_instance->verification_key }; }; void prove_eccvm() @@ -188,7 +192,10 @@ class Goblin { // merge_proof_exists = true; // } - accumulator = { ultra_proof, instance->verification_key }; + // WORKTODO: proper handling + auto verifier_instance = composer.create_verifier_instance(instance); + + accumulator = { ultra_proof, verifier_instance->verification_key }; return accumulator; }; 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 3d59f99ff7c..eb83a7f9c92 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 @@ -155,17 +155,18 @@ template class GoblinRecursiveVerifierTest : public testi auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK // Instantiate the recursive verifier using the native verification key - RecursiveVerifier verifier{ &outer_circuit, instance->verification_key }; + auto verification_key = inner_composer.compute_verification_key(instance); + 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, instance->verification_key->circuit_size); - EXPECT_EQ(verifier.key->log_circuit_size, instance->verification_key->log_circuit_size); - EXPECT_EQ(verifier.key->num_public_inputs, instance->verification_key->num_public_inputs); - EXPECT_EQ(verifier.key->q_m.get_value(), instance->verification_key->q_m); - EXPECT_EQ(verifier.key->q_r.get_value(), instance->verification_key->q_r); - EXPECT_EQ(verifier.key->sigma_1.get_value(), instance->verification_key->sigma_1); - EXPECT_EQ(verifier.key->id_3.get_value(), instance->verification_key->id_3); - EXPECT_EQ(verifier.key->lagrange_ecc_op.get_value(), instance->verification_key->lagrange_ecc_op); + 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); } /** @@ -184,8 +185,9 @@ template class GoblinRecursiveVerifierTest : public testi auto inner_proof = inner_prover.construct_proof(); // Create a recursive verification circuit for the proof of the inner circuit + auto verification_key = inner_composer.compute_verification_key(instance); 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 Goblin: num gates = ", outer_circuit.num_gates); @@ -245,8 +247,9 @@ template class GoblinRecursiveVerifierTest : public testi inner_proof = inner_prover.export_proof(); // Create a recursive verification circuit for the proof of the inner circuit + auto verification_key = inner_composer.compute_verification_key(instance); 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/stdlib/recursion/honk/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp index b9f3cbcecc5..52de8e22d3b 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 @@ -138,16 +138,17 @@ template class RecursiveVerifierTest : public testing::Te auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK // Instantiate the recursive verifier using the native verification key - RecursiveVerifier verifier{ &outer_circuit, instance->verification_key }; + auto verification_key = inner_composer.compute_verification_key(instance); + 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, instance->verification_key->circuit_size); - EXPECT_EQ(verifier.key->log_circuit_size, instance->verification_key->log_circuit_size); - EXPECT_EQ(verifier.key->num_public_inputs, instance->verification_key->num_public_inputs); - EXPECT_EQ(verifier.key->q_m.get_value(), instance->verification_key->q_m); - EXPECT_EQ(verifier.key->q_r.get_value(), instance->verification_key->q_r); - EXPECT_EQ(verifier.key->sigma_1.get_value(), instance->verification_key->sigma_1); - EXPECT_EQ(verifier.key->id_3.get_value(), instance->verification_key->id_3); + 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); } /** @@ -167,8 +168,9 @@ template class RecursiveVerifierTest : public testing::Te auto inner_proof = inner_prover.construct_proof(); // Create a recursive verification circuit for the proof of the inner circuit + auto verification_key = inner_composer.compute_verification_key(instance); 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); @@ -229,8 +231,9 @@ template class RecursiveVerifierTest : public testing::Te inner_proof = inner_prover.export_proof(); // Create a recursive verification circuit for the proof of the inner circuit + auto verification_key = inner_composer.compute_verification_key(instance); 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/verifier_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp index 23faaf87875..76358f5d89f 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp @@ -1,6 +1,7 @@ #pragma once #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/sumcheck/instance/prover_instance.hpp" namespace proof_system::honk { template class VerifierInstance_ { @@ -21,11 +22,23 @@ template class VerifierInstance_ { RelationSeparator alphas; bool is_accumulator = false; + // WORKTODO: why a vector? // The folding parameters (\vec{β}, e) which are set for accumulators (i.e. relaxed instances). std::vector gate_challenges; FF target_sum; WitnessCommitments witness_commitments; CommitmentLabels commitment_labels; + + // WORKTODO: what should be set here? + VerifierInstance_() = default; + + VerifierInstance_(const std::shared_ptr>& prover_instance) + : public_inputs(std::move(prover_instance->public_inputs)) + , pub_inputs_offset(prover_instance->pub_inputs_offset) + , public_input_size(prover_instance->public_inputs.size()) + , instance_size(prover_instance->instance_size) + , log_instance_size(prover_instance->log_instance_size) + {} }; } // namespace proof_system::honk \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp index a52da13a4d0..3cbd8fc2d90 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp @@ -7,9 +7,9 @@ using namespace proof_system::honk; using Flavor = flavor::Ultra; using VerificationKey = Flavor::VerificationKey; -using Instance = ProverInstance_; -using Instances = ProverInstances_; -using ProtoGalaxyProver = ProtoGalaxyProver_; +using ProverInstance = ProverInstance_; +using ProverInstances = ProverInstances_; +using ProtoGalaxyProver = ProtoGalaxyProver_; using FF = Flavor::FF; using Affine = Flavor::Commitment; using Projective = Flavor::GroupElement; @@ -47,9 +47,9 @@ ProverPolynomials construct_ultra_full_polynomials(auto& input_polynomials) return full_polynomials; } -std::shared_ptr fold_and_verify(const std::vector>& instances, - UltraComposer& composer, - bool expected_result) +std::shared_ptr fold_and_verify(const std::vector>& instances, + UltraComposer& composer, + bool expected_result) { auto folding_prover = composer.create_folding_prover(instances, composer.commitment_key); auto folding_verifier = composer.create_folding_verifier(); @@ -61,7 +61,7 @@ std::shared_ptr fold_and_verify(const std::vector& accumulator, bool expected_result) +void check_accumulator_target_sum_manual(std::shared_ptr& accumulator, bool expected_result) { auto instance_size = accumulator->instance_size; auto expected_honk_evals = ProtoGalaxyProver::compute_full_honk_evaluations( @@ -78,7 +78,7 @@ void check_accumulator_target_sum_manual(std::shared_ptr& accumulator, EXPECT_EQ(accumulator->target_sum == expected_target_sum, expected_result); } -void decide_and_verify(std::shared_ptr& accumulator, UltraComposer& composer, bool expected_result) +void decide_and_verify(std::shared_ptr& accumulator, UltraComposer& composer, bool expected_result) { auto decider_prover = composer.create_decider_prover(accumulator, composer.commitment_key); auto decider_verifier = composer.create_decider_verifier(accumulator); @@ -172,7 +172,7 @@ TEST_F(ProtoGalaxyTests, PerturbatorPolynomial) target_sum += full_honk_evals[i] * pow_beta[i]; } - auto accumulator = std::make_shared(); + auto accumulator = std::make_shared(); accumulator->prover_polynomials = std::move(full_polynomials); accumulator->gate_challenges = betas; accumulator->target_sum = target_sum; @@ -272,7 +272,7 @@ TEST_F(ProtoGalaxyTests, FullProtogalaxyTest) auto instance_2 = composer.create_prover_instance(builder_2); - auto instances = std::vector>{ instance_1, instance_2 }; + auto instances = std::vector>{ instance_1, instance_2 }; auto first_accumulator = fold_and_verify(instances, composer, true); check_accumulator_target_sum_manual(first_accumulator, true); @@ -280,7 +280,7 @@ TEST_F(ProtoGalaxyTests, FullProtogalaxyTest) builder_3.add_public_variable(FF(1)); auto instance_3 = composer.create_prover_instance(builder_3); - instances = std::vector>{ first_accumulator, instance_3 }; + instances = std::vector>{ first_accumulator, instance_3 }; auto second_accumulator = fold_and_verify(instances, composer, true); check_accumulator_target_sum_manual(second_accumulator, true); @@ -301,7 +301,7 @@ TEST_F(ProtoGalaxyTests, TamperedCommitment) auto instance_2 = composer.create_prover_instance(builder_2); - auto instances = std::vector>{ instance_1, instance_2 }; + auto instances = std::vector>{ instance_1, instance_2 }; auto first_accumulator = fold_and_verify(instances, composer, true); check_accumulator_target_sum_manual(first_accumulator, true); @@ -311,7 +311,7 @@ TEST_F(ProtoGalaxyTests, TamperedCommitment) // tampering with the commitment should cause the decider to fail first_accumulator->witness_commitments.w_l = Projective(Affine::random_element()); - instances = std::vector>{ first_accumulator, instance_3 }; + instances = std::vector>{ first_accumulator, instance_3 }; auto second_accumulator = fold_and_verify(instances, composer, true); @@ -332,7 +332,7 @@ TEST_F(ProtoGalaxyTests, TamperedAccumulatorPolynomial) auto instance_2 = composer.create_prover_instance(builder_2); - auto instances = std::vector>{ instance_1, instance_2 }; + auto instances = std::vector>{ instance_1, instance_2 }; auto first_accumulator = fold_and_verify(instances, composer, true); check_accumulator_target_sum_manual(first_accumulator, true); @@ -341,7 +341,7 @@ TEST_F(ProtoGalaxyTests, TamperedAccumulatorPolynomial) auto instance_3 = composer.create_prover_instance(builder_3); // tampering with accumulator's polynomial should cause both folding and deciding to fail - instances = std::vector>{ first_accumulator, instance_3 }; + instances = std::vector>{ first_accumulator, instance_3 }; first_accumulator->prover_polynomials.w_l[1] = FF::random_element(); auto second_accumulator = fold_and_verify(instances, composer, false); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp index c3b5e92b92d..2eaa2902d10 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp @@ -12,12 +12,9 @@ namespace proof_system::honk { * @return Pointer to the resulting verification key of the Instance. * */ template -void UltraComposer_::compute_verification_key(std::shared_ptr>& prover_instance, - std::shared_ptr>& verifier_instance) +std::shared_ptr UltraComposer_::compute_verification_key( + std::shared_ptr>& prover_instance) { - if (verifier_instance->verification_key) { - return; - } auto& proving_key = prover_instance->proving_key; @@ -62,7 +59,7 @@ void UltraComposer_::compute_verification_key(std::shared_ptrq_poseidon2_internal = commitment_key->commit(proving_key->q_poseidon2_internal); } - verifier_instance->verification_key = std::move(verification_key); + return verification_key; } template @@ -76,6 +73,16 @@ std::shared_ptr> UltraComposer_::create_prover_i return instance; } +template +std::shared_ptr> UltraComposer_::create_verifier_instance( + std::shared_ptr>& prover_instance) +{ + auto verifier_instance = std::make_shared(prover_instance); + verifier_instance->verification_key = compute_verification_key(prover_instance); + + return verifier_instance; +} + template UltraProver_ UltraComposer_::create_prover(const std::shared_ptr& instance, const std::shared_ptr& transcript) @@ -86,10 +93,10 @@ UltraProver_ UltraComposer_::create_prover(const std::shared_ptr } template -UltraVerifier_ UltraComposer_::create_verifier(const std::shared_ptr& instance, - const std::shared_ptr& transcript) +UltraVerifier_ UltraComposer_::create_verifier( + const std::shared_ptr& verifier_instance, const std::shared_ptr& transcript) { - auto& verification_key = instance->verification_key; + auto& verification_key = verifier_instance->verification_key; UltraVerifier_ output_state(transcript, verification_key); auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); output_state.pcs_verification_key = std::move(pcs_verification_key); @@ -97,6 +104,14 @@ UltraVerifier_ UltraComposer_::create_verifier(const std::shared return output_state; } +template +UltraVerifier_ UltraComposer_::create_verifier(std::shared_ptr& prover_instance, + const std::shared_ptr& transcript) +{ + std::shared_ptr> verifier_instance = create_verifier_instance(prover_instance); + return create_verifier(verifier_instance, transcript); +} + template DeciderProver_ UltraComposer_::create_decider_prover(const std::shared_ptr& accumulator, const std::shared_ptr& transcript) @@ -130,6 +145,14 @@ DeciderVerifier_ UltraComposer_::create_decider_verifier( return output_state; } +template +DeciderVerifier_ UltraComposer_::create_decider_verifier(std::shared_ptr& accumulator, + const std::shared_ptr& transcript) +{ + std::shared_ptr> verifier_instance = create_verifier_instance(accumulator); + return create_decider_verifier(verifier_instance, transcript); +} + template class UltraComposer_; template class UltraComposer_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp index dfe6fd4b680..a36b913e2c5 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp @@ -60,10 +60,15 @@ template class UltraComposer_ { }; std::shared_ptr create_prover_instance(CircuitBuilder& circuit); + std::shared_ptr create_verifier_instance(std::shared_ptr& prover_instance); UltraProver_ create_prover(const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); + UltraVerifier_ create_verifier( + std::shared_ptr&, + const std::shared_ptr& transcript = std::make_shared()); + UltraVerifier_ create_verifier( const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); @@ -71,15 +76,19 @@ template class UltraComposer_ { DeciderProver_ create_decider_prover( const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); + DeciderProver_ create_decider_prover( const std::shared_ptr&, const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); + DeciderVerifier_ create_decider_verifier( + std::shared_ptr&, + const std::shared_ptr& transcript = std::make_shared()); + 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); @@ -132,7 +141,7 @@ template class UltraComposer_ { * * @param inst */ - void compute_verification_key(std::shared_ptr&, std::shared_ptr&); + std::shared_ptr compute_verification_key(std::shared_ptr&); }; // TODO(#532): this pattern is weird; is this not instantiating the templates? From b02cc861f62f092e57f319dfdac6de04a8e9b030 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 18 Jan 2024 17:00:55 +0000 Subject: [PATCH 5/7] Fix SRS size bug --- barretenberg/cpp/src/barretenberg/goblin/goblin.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index dd0dc1110f8..261d3044168 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -105,8 +105,11 @@ class Goblin { // Construct a Honk proof for the main circuit GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(circuit_builder); - auto prover = composer.create_prover(instance); + auto prover_instance = composer.create_prover_instance(circuit_builder); + // TODO(https://github.com/AztecProtocol/barretenberg/issues/831): SRS is too small if the verifier instance is + // created after merge proving. + auto verifier_instance = composer.create_verifier_instance(prover_instance); + auto prover = composer.create_prover(prover_instance); auto ultra_proof = prover.construct_proof(); // Construct and store the merge proof to be recursively verified on the next call to accumulate @@ -117,9 +120,6 @@ class Goblin { merge_proof_exists = true; } - // WORKTODO: proper handling - auto verifier_instance = composer.create_verifier_instance(instance); - return { ultra_proof, verifier_instance->verification_key }; }; From 900d8aee469a423099c3be732c760fe858b4ba0d Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 18 Jan 2024 17:12:26 +0000 Subject: [PATCH 6/7] Fix databus test. --- .../src/barretenberg/sumcheck/instance/verifier_instance.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp index 76358f5d89f..16508778183 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp @@ -34,7 +34,7 @@ template class VerifierInstance_ { VerifierInstance_() = default; VerifierInstance_(const std::shared_ptr>& prover_instance) - : public_inputs(std::move(prover_instance->public_inputs)) + : public_inputs(prover_instance->public_inputs) , pub_inputs_offset(prover_instance->pub_inputs_offset) , public_input_size(prover_instance->public_inputs.size()) , instance_size(prover_instance->instance_size) From d35df102a6458675ed1eb38b537de6e9d06f5cfe Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 18 Jan 2024 21:46:02 +0000 Subject: [PATCH 7/7] Toward removing vk up to decider verifier. --- .../protogalaxy/decider_verifier.cpp | 7 --- .../protogalaxy/protogalaxy_prover.cpp | 5 +- .../protogalaxy/protogalaxy_prover.hpp | 1 + .../protogalaxy/protogalaxy_verifier.cpp | 47 ++++++++----------- .../ultra_honk/protogalaxy.test.cpp | 4 +- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp index dd7c313322a..4dff4f33ca5 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp @@ -74,13 +74,6 @@ template bool DeciderVerifier_::verify_proof(const plo comm_view[idx] = transcript->template receive_from_prover(witness_labels[idx]); } - inst->verification_key = std::make_shared(inst->instance_size, inst->public_input_size); - auto vk_view = inst->verification_key->get_all(); - auto vk_labels = inst->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < vk_labels.size(); idx++) { - vk_view[idx] = transcript->template receive_from_prover(vk_labels[idx]); - } - VerifierCommitments commitments{ inst->verification_key, inst->witness_commitments }; auto sumcheck = SumcheckVerifier(inst->log_instance_size, transcript, inst->target_sum); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 772375bc392..ad1b82bbcec 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -126,7 +126,7 @@ template void ProtoGalaxyProver_::prepa idx++; for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { - auto instance = *it; + auto instance = *it; // WORKTODO: possible unnecessary copy here? auto domain_separator = std::to_string(idx); finalise_and_send_instance(instance, domain_separator); } @@ -148,6 +148,9 @@ std::shared_ptr ProtoGalaxyProver_ lagranges{ FF(1) - challenge, challenge }; auto next_accumulator = std::make_shared(); + next_accumulator->proving_key = std::make_shared(); + next_accumulator->proving_key->circuit_size = instances[0]->proving_key->circuit_size; + next_accumulator->proving_key->num_public_inputs = instances[0]->proving_key->num_public_inputs; next_accumulator->is_accumulator = true; next_accumulator->instance_size = instances[0]->instance_size; next_accumulator->log_instance_size = instances[0]->log_instance_size; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index adf030c57bd..79af9ee5625 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -21,6 +21,7 @@ template class ProtoGalaxyProver_ { using Instance = typename ProverInstances::Instance; using Utils = bb::RelationUtils; using RowEvaluations = typename Flavor::AllValues; + using ProvingKey = typename Flavor::ProvingKey; using ProverPolynomials = typename Flavor::ProverPolynomials; using Relations = typename Flavor::Relations; using RelationSeparator = typename Flavor::RelationSeparator; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index 871d4ad23b8..f743fca758e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -44,13 +44,6 @@ void ProtoGalaxyVerifier_::receive_accumulator(const std::sha comm_view[idx] = transcript->template receive_from_prover(domain_separator + "_" + witness_labels[idx]); } - - inst->verification_key = std::make_shared(inst->instance_size, inst->public_input_size); - auto vk_view = inst->verification_key->get_all(); - auto vk_labels = inst->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < vk_labels.size(); idx++) { - vk_view[idx] = transcript->template receive_from_prover(domain_separator + "_" + vk_labels[idx]); - } } template @@ -98,12 +91,12 @@ void ProtoGalaxyVerifier_::receive_and_finalise_instance(cons inst->alphas[idx] = transcript->get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); } - inst->verification_key = std::make_shared(inst->instance_size, inst->public_input_size); - auto vk_view = inst->verification_key->get_all(); - auto vk_labels = labels.get_precomputed(); - for (size_t idx = 0; idx < vk_labels.size(); idx++) { - vk_view[idx] = transcript->template receive_from_prover(domain_separator + "_" + vk_labels[idx]); - } + // inst->verification_key = std::make_shared(inst->instance_size, inst->public_input_size); + // auto vk_view = inst->verification_key->get_all(); + // auto vk_labels = labels.get_precomputed(); + // for (size_t idx = 0; idx < vk_labels.size(); idx++) { + // vk_view[idx] = transcript->template receive_from_prover(domain_separator + "_" + vk_labels[idx]); + // } } // TODO(https://github.com/AztecProtocol/barretenberg/issues/795): The rounds prior to actual verifying are common @@ -255,20 +248,20 @@ bool ProtoGalaxyVerifier_::verify_folding_proof(std::vectortemplate receive_from_prover("next_lookup_grand_product_delta"); verified = verified & (next_lookup_grand_product_delta == expected_parameters.lookup_grand_product_delta); - auto acc_vk = std::make_shared(instances[0]->instance_size, instances[0]->public_input_size); - auto vk_labels = commitment_labels.get_precomputed(); - size_t vk_idx = 0; - for (auto& expected_vk : acc_vk->get_all()) { - size_t inst = 0; - expected_vk = Commitment::infinity(); - for (auto& instance : instances) { - expected_vk = expected_vk + instance->verification_key->get_all()[vk_idx] * lagranges[inst]; - inst++; - } - auto vk = transcript->template receive_from_prover("next_" + vk_labels[vk_idx]); - verified = verified & (vk == expected_vk); - vk_idx++; - } + // auto acc_vk = std::make_shared(instances[0]->instance_size, instances[0]->public_input_size); + // auto vk_labels = commitment_labels.get_precomputed(); + // size_t vk_idx = 0; + // for (auto& expected_vk : acc_vk->get_all()) { + // size_t inst = 0; + // expected_vk = Commitment::infinity(); + // for (auto& instance : instances) { + // expected_vk = expected_vk + instance->verification_key->get_all()[vk_idx] * lagranges[inst]; + // inst++; + // } + // auto vk = transcript->template receive_from_prover("next_" + vk_labels[vk_idx]); + // verified = verified & (vk == expected_vk); + // vk_idx++; + // } return verified; } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp index 3cbd8fc2d90..aa13a53cb12 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp @@ -81,7 +81,8 @@ void check_accumulator_target_sum_manual(std::shared_ptr& accumu void decide_and_verify(std::shared_ptr& accumulator, UltraComposer& composer, bool expected_result) { auto decider_prover = composer.create_decider_prover(accumulator, composer.commitment_key); - auto decider_verifier = composer.create_decider_verifier(accumulator); + auto decider_verifier = + composer.create_decider_verifier(accumulator); // LEFT OFF HERE: need to pass accumulated vk here. auto decision = decider_prover.construct_proof(); auto verified = decider_verifier.verify_proof(decision); EXPECT_EQ(verified, expected_result); @@ -280,6 +281,7 @@ TEST_F(ProtoGalaxyTests, FullProtogalaxyTest) builder_3.add_public_variable(FF(1)); auto instance_3 = composer.create_prover_instance(builder_3); + // WORKTODO: ensure independence of instance order. I get different failures for different orders now instances = std::vector>{ first_accumulator, instance_3 }; auto second_accumulator = fold_and_verify(instances, composer, true); check_accumulator_target_sum_manual(second_accumulator, true);