diff --git a/barretenberg/cpp/scripts/bb-tests.sh b/barretenberg/cpp/scripts/bb-tests.sh index 0c0d27ed9227..f9dbe34fabcb 100755 --- a/barretenberg/cpp/scripts/bb-tests.sh +++ b/barretenberg/cpp/scripts/bb-tests.sh @@ -11,8 +11,18 @@ IMAGE_URI=$(calculate_image_uri $REPOSITORY) retry docker pull $IMAGE_URI TESTS=( - client_ivc_tests + flavor_tests + relations_tests + transcript_tests commitment_schemes_tests + sumcheck_tests + eccvm_tests + translator_vm_tests + protogalaxy_tests + ultra_honk_tests + goblin_tests + client_ivc_tests + dsl_tests crypto_aes128_tests crypto_blake2s_tests crypto_blake3s_tests @@ -22,23 +32,13 @@ TESTS=( crypto_poseidon2_tests crypto_schnorr_tests crypto_sha256_tests - dsl_tests ecc_tests - eccvm_tests - flavor_tests - goblin_tests join_split_example_proofs_inner_proof_data_tests join_split_example_proofs_notes_tests numeric_tests plonk_tests polynomials_tests - protogalaxy_tests - relations_tests srs_tests - sumcheck_tests - transcript_tests - translator_vm_tests - ultra_honk_tests vm_tests ) TESTS_STR="${TESTS[@]}" diff --git a/barretenberg/cpp/scripts/ultra_honk_tests.sh b/barretenberg/cpp/scripts/ultra_honk_tests.sh new file mode 100755 index 000000000000..654ba280c92b --- /dev/null +++ b/barretenberg/cpp/scripts/ultra_honk_tests.sh @@ -0,0 +1,22 @@ +set -eu + +# Move above script dir. +cd $(dirname $0)/.. + +cmake --preset clang16 +cmake --build --preset clang16 + +cd build/ + +./bin/flavor_tests +./bin/relations_tests +./bin/transcript_tests +./bin/commitment_schemes_tests +./bin/sumcheck_tests +./bin/eccvm_tests +./bin/translator_vm_tests +./bin/protogalaxy_tests +./bin/ultra_honk_tests +./bin/goblin_tests +./bin/client_ivc_tests +./bin/stdlib_recursion_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp index 4df728ba6b9f..e91b61bbad5d 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp @@ -11,20 +11,20 @@ namespace bb { +constexpr size_t COMMITMENT_TEST_NUM_POINTS = 4096; + template inline std::shared_ptr CreateCommitmentKey(); template <> inline std::shared_ptr> CreateCommitmentKey>() { srs::init_crs_factory("../srs_db/ignition"); - constexpr size_t n = 4096; - return std::make_shared>(n); + return std::make_shared>(COMMITMENT_TEST_NUM_POINTS); } // For IPA template <> inline std::shared_ptr> CreateCommitmentKey>() { srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); - constexpr size_t n = 4096; - return std::make_shared>(n); + return std::make_shared>(COMMITMENT_TEST_NUM_POINTS); } template inline std::shared_ptr CreateCommitmentKey() @@ -39,20 +39,16 @@ template <> inline std::shared_ptr> CreateVerifierCommitmentKey< VerifierCommitmentKey>() { - constexpr size_t n = 4096; - std::shared_ptr> crs_factory( - new bb::srs::factories::FileCrsFactory("../srs_db/ignition", 4096)); - return std::make_shared>(n, crs_factory); + return std::make_shared>(); } // For IPA template <> inline std::shared_ptr> CreateVerifierCommitmentKey< VerifierCommitmentKey>() { - constexpr size_t n = 4096; - std::shared_ptr> crs_factory( - new bb::srs::factories::FileCrsFactory("../srs_db/grumpkin", 4096)); - return std::make_shared>(n, crs_factory); + auto crs_factory = std::make_shared>("../srs_db/grumpkin", + COMMITMENT_TEST_NUM_POINTS); + return std::make_shared>(COMMITMENT_TEST_NUM_POINTS, crs_factory); } template inline std::shared_ptr CreateVerifierCommitmentKey() // requires std::default_initializable diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp index 569e72b14925..d84914980010 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp @@ -13,8 +13,7 @@ #include "barretenberg/numeric/bitop/pow.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" -#include "barretenberg/srs/factories/crs_factory.hpp" -#include "barretenberg/srs/factories/file_crs_factory.hpp" +#include "barretenberg/srs/global_crs.hpp" #include #include @@ -35,19 +34,13 @@ template <> class VerifierCommitmentKey { using Commitment = typename Curve::AffineElement; public: - VerifierCommitmentKey() = delete; + std::shared_ptr> srs; - /** - * @brief Construct a new Kate Verification Key object from existing SRS - * - * @param num_points - * @param srs verifier G2 point - */ - VerifierCommitmentKey( - [[maybe_unused]] size_t num_points, // TODO(https://github.com/AztecProtocol/barretenberg/issues/874) - std::shared_ptr> crs_factory) - : srs(crs_factory->get_verifier_crs()) - {} + VerifierCommitmentKey() + { + srs::init_crs_factory("../srs_db/ignition"); + srs = srs::get_crs_factory()->get_verifier_crs(); + }; /** * @brief verifies a pairing equation over 2 points using the verifier SRS @@ -65,8 +58,6 @@ template <> class VerifierCommitmentKey { return (result == Curve::TargetField::one()); } - - std::shared_ptr> srs; }; /** @@ -89,7 +80,7 @@ template <> class VerifierCommitmentKey { * @param num_points specifies the length of the SRS * @param path is the location to the SRS file */ - VerifierCommitmentKey(size_t num_points, std::shared_ptr> crs_factory) + VerifierCommitmentKey(size_t num_points, const std::shared_ptr>& crs_factory) : pippenger_runtime_state(num_points) , srs(crs_factory->get_verifier_crs(num_points)) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 2a8d455ecd4e..72f62b589fe1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -329,7 +329,7 @@ template class ECCVMBa * resolve that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for * portability of our circuits. */ - using VerificationKey = VerificationKey_>; + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; /** * @brief A container for polynomials produced after the first round of sumcheck. diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 7048f825fed3..00f890bc8753 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -73,6 +73,7 @@ #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/types/circuit_type.hpp" #include +#include #include #include @@ -142,8 +143,11 @@ class ProvingKey_ : public PrecomputedPolynomials, public WitnessPolynomials { * * @tparam PrecomputedEntities An instance of PrecomputedEntities_ with affine_element data type and handle type. */ -template class VerificationKey_ : public PrecomputedCommitments { +template +class VerificationKey_ : public PrecomputedCommitments { public: + std::shared_ptr pcs_verification_key; + VerificationKey_() = default; VerificationKey_(const size_t circuit_size, const size_t num_public_inputs) { @@ -151,11 +155,13 @@ template class VerificationKey_ : public Preco this->log_circuit_size = numeric::get_msb(circuit_size); this->num_public_inputs = num_public_inputs; }; + template VerificationKey_(const ProvingKeyPtr& proving_key) { this->circuit_size = proving_key->circuit_size; this->log_circuit_size = numeric::get_msb(this->circuit_size); this->num_public_inputs = proving_key->num_public_inputs; + this->pcs_verification_key = std::make_shared(); for (auto [polynomial, commitment] : zip_view(proving_key->get_precomputed_polynomials(), this->get_all())) { commitment = proving_key->commitment_key->commit(polynomial); diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp index efb23d6efc5e..9e32dca00fac 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp @@ -525,7 +525,7 @@ class AvmFlavor { RefArray get_table_column_wires() { return {}; }; }; - using VerificationKey = VerificationKey_>; + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; using FoldedPolynomials = AllEntities>; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp index ac7df4a07e2f..b776a68cd46e 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp @@ -212,7 +212,7 @@ class ToyFlavor { RefArray get_table_column_wires() { return {}; }; }; - using VerificationKey = VerificationKey_>; + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; using FoldedPolynomials = AllEntities>; diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index 5a1d9fb6d414..16ea236f8f64 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -934,7 +934,7 @@ class GoblinTranslatorFlavor { * resolve that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for * portability of our circuits. */ - using VerificationKey = VerificationKey_>; + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; /** * @brief A field element for each entity of the flavor. These entities represent the prover polynomials diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index e1fbb2e7b4de..3a68c154cb53 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -287,7 +287,7 @@ class GoblinUltraFlavor { * circuits. * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/876) */ - using VerificationKey = VerificationKey_>; + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; /** * @brief A container for storing the partially evaluated multivariates produced by sumcheck. diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp index 0444ebaf2f41..8e3a10f4f508 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp @@ -10,14 +10,6 @@ #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" -#include "barretenberg/srs/factories/crs_factory.hpp" -#include -#include -#include -#include -#include -#include - #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/recursion/honk/transcript/transcript.hpp" @@ -104,7 +96,8 @@ template class GoblinUltraRecursiveFlavor_ { * circuits. * This differs from GoblinUltra in how we construct the commitments. */ - class VerificationKey : public VerificationKey_> { + class VerificationKey + : public VerificationKey_, VerifierCommitmentKey> { public: VerificationKey(const size_t circuit_size, const size_t num_public_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp index 46fe5f4499f6..a2323eba35f4 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -290,7 +290,7 @@ class UltraFlavor { * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our * circuits. */ - using VerificationKey = VerificationKey_>; + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; /** * @brief A field element for each entity of the flavor. These entities represent the prover polynomials diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp index ffaa99c7a8c4..e7ab769eb6d6 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp @@ -269,7 +269,7 @@ template class UltraRecursiveFlavor_ { * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our * circuits. */ - class VerificationKey : public VerificationKey_> { + class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { public: VerificationKey(const size_t circuit_size, const size_t num_public_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp index c808e5e65423..3d0b2e4e8ed8 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp @@ -14,11 +14,10 @@ namespace bb { * */ template DeciderProver_::DeciderProver_(const std::shared_ptr& inst, - const std::shared_ptr& commitment_key, const std::shared_ptr& transcript) : accumulator(std::move(inst)) , transcript(transcript) - , commitment_key(commitment_key) + , commitment_key(inst->commitment_key) {} /** diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp index 562a1700ba2f..ef3cd372cee5 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp @@ -25,7 +25,6 @@ template class DeciderProver_ { public: explicit DeciderProver_(const std::shared_ptr&, - const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); BB_PROFILE void execute_relation_check_rounds(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp index e685f8930ecb..d140292bc4b3 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp @@ -10,11 +10,13 @@ template DeciderVerifier_::DeciderVerifier_(const std::shared_ptr& transcript, const std::shared_ptr& accumulator) : accumulator(accumulator) + , pcs_verification_key(accumulator->verification_key->pcs_verification_key) , transcript(transcript) {} + template DeciderVerifier_::DeciderVerifier_() - : pcs_verification_key(std::make_unique(0, bb::srs::get_bn254_crs_factory())) + : pcs_verification_key(std::make_unique()) , transcript(std::make_shared()) {} @@ -52,7 +54,7 @@ template bool DeciderVerifier_::verify_proof(const Hon multivariate_challenge, transcript); - auto verified = pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); + auto verified = accumulator->pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); return sumcheck_verified.value() && verified; } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 8d505a509592..e7fe59f6644e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -129,10 +129,12 @@ std::shared_ptr ProtoGalaxyProver_ lagranges{ FF(1) - challenge, challenge }; + // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern auto next_accumulator = std::make_shared(); next_accumulator->is_accumulator = true; next_accumulator->instance_size = instances[0]->instance_size; next_accumulator->log_instance_size = instances[0]->log_instance_size; + next_accumulator->commitment_key = instances[0]->commitment_key; // Compute the next target sum and send the next folding parameters to the verifier FF next_target_sum = diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 038c7a2e9dae..f1b41ae42b2d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -15,9 +15,9 @@ namespace bb { template struct ProtogalaxyProofConstructionState { using FF = typename ProverInstances_::FF; - using Instance = typename ProverInstances_::Instance; + using ProverInstance = typename ProverInstances_::Instance; - std::shared_ptr accumulator; + std::shared_ptr accumulator; Polynomial perturbator; std::vector deltas; Univariate combiner_quotient; 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 1a37b1fa092b..e37b54487cff 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 @@ -193,8 +193,8 @@ template class GoblinRecursiveVerifierTest : public testi // 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()); + auto recursive_result = native_verifier.key->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 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 cd603ed1c857..9b4ee8d37e12 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 @@ -49,7 +49,6 @@ class RecursiveMergeVerifierTest : public testing::Test { GoblinMockCircuits::construct_simple_initial_circuit(sample_circuit); // Generate a proof over the inner circuit - InnerComposer inner_composer; MergeProver merge_prover{ op_queue }; auto merge_proof = merge_prover.construct_proof(); @@ -65,7 +64,7 @@ class RecursiveMergeVerifierTest : public testing::Test { // verifier and check that the result agrees. MergeVerifier native_verifier; bool verified_native = native_verifier.verify_proof(merge_proof); - VerifierCommitmentKey pcs_verification_key(0, srs::get_bn254_crs_factory()); + VerifierCommitmentKey pcs_verification_key; auto verified_recursive = pcs_verification_key.pairing_check(pairing_points[0].get_value(), pairing_points[1].get_value()); EXPECT_EQ(verified_native, verified_recursive); 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 6e2f1f5f3ceb..55eb6116770b 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 @@ -278,7 +278,7 @@ template class ProtoGalaxyRecursiveTests : public tes // decider verifier and check that the result agrees. DeciderVerifier native_decider_verifier = composer.create_decider_verifier(verifier_accumulator); auto native_result = native_decider_verifier.verify_proof(decider_proof); - auto recursive_result = native_decider_verifier.pcs_verification_key->pairing_check( + auto recursive_result = native_decider_verifier.accumulator->pcs_verification_key->pairing_check( pairing_points[0].get_value(), pairing_points[1].get_value()); EXPECT_EQ(native_result, recursive_result); 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 384405d12722..3dda0156beee 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 @@ -177,8 +177,8 @@ template class RecursiveVerifierTest : public testing::Te // 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()); + auto recursive_result = native_verifier.key->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 diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp index e2c168406c31..dcfc88830983 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp @@ -4,9 +4,9 @@ namespace bb { -template struct ProverInstances_ { +template struct ProverInstances_ { public: - static_assert(NUM_ > 0, "Must have at least one prover instance"); + static_assert(NUM_ > 1, "Must have at least two prover instances"); using Flavor = Flavor_; using FF = typename Flavor::FF; static constexpr size_t NUM = NUM_; @@ -84,7 +84,8 @@ template struct ProverInstances_ { } }; -template struct VerifierInstances_ { +template struct VerifierInstances_ { + static_assert(NUM_ > 1, "Must have at least two prover instances"); using Flavor = Flavor_; using VerificationKey = typename Flavor::VerificationKey; using Instance = VerifierInstance_; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index a4196abfd956..6c83c5210d83 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -33,6 +33,9 @@ template class ProverInstance_ { public: std::shared_ptr proving_key; + // 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; @@ -90,6 +93,7 @@ template class ProverInstance_ { sorted_polynomials = construct_sorted_list_polynomials(circuit, dyadic_circuit_size); verification_key = std::make_shared(proving_key); + commitment_key = proving_key->commitment_key; } ProverInstance_() = default; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp index 0910ccb614dd..983dc37dd4e7 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/verifier_instance.hpp @@ -10,15 +10,19 @@ namespace bb { * * @details This is ϕ in the paper. */ -template class VerifierInstance_ { +template class VerifierInstance_ { public: using FF = typename Flavor::FF; using VerificationKey = typename Flavor::VerificationKey; + using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; using WitnessCommitments = typename Flavor::WitnessCommitments; using CommitmentLabels = typename Flavor::CommitmentLabels; using RelationSeparator = typename Flavor::RelationSeparator; std::shared_ptr verification_key; + // TODO(https://github.com/AztecProtocol/barretenberg/issues/881)?: Access throutgh vk by making sure vk is + // initialized in Protogalaxy? + std::shared_ptr pcs_verification_key; std::vector public_inputs; size_t pub_inputs_offset = 0; size_t public_input_size; @@ -34,9 +38,11 @@ template class VerifierInstance_ { WitnessCommitments witness_commitments; CommitmentLabels commitment_labels; - VerifierInstance_() = default; + VerifierInstance_() + : pcs_verification_key(std::make_shared()){}; VerifierInstance_(std::shared_ptr vk) : verification_key(std::move(vk)) + , pcs_verification_key(std::make_shared()) {} }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp index 24767656fd65..8178fe972cc5 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp @@ -223,7 +223,7 @@ GoblinTranslatorVerifier GoblinTranslatorComposer::create_verifier(const Circuit GoblinTranslatorVerifier output_state(verification_key); - auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); + auto pcs_verification_key = std::make_unique(); output_state.pcs_verification_key = std::move(pcs_verification_key); output_state.transcript = transcript; 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 8e8ed2876fb4..43ff53ffb0ca 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 @@ -136,8 +136,6 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsMergeOnly) generate_test_circuit(builder); - auto composer = GoblinUltraComposer(); - // Construct and verify Goblin ECC op queue Merge proof auto merge_verified = construct_and_verify_merge_proof(op_queue); EXPECT_TRUE(merge_verified); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/merge_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/merge_verifier.cpp index 16df9c30fab9..9ce6bada4820 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/merge_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/merge_verifier.cpp @@ -5,7 +5,7 @@ namespace bb { template MergeVerifier_::MergeVerifier_() : transcript(std::make_shared()) - , pcs_verification_key(std::make_unique(0, bb::srs::get_bn254_crs_factory())){}; + , pcs_verification_key(std::make_unique()){}; /** * @brief Verify proper construction of the aggregate Goblin ECC op queue polynomials T_i^(j), j = 1,2,3,4. diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp index e8da52f540b1..3cdeefdac7d4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp @@ -33,43 +33,21 @@ template UltraVerifier_ UltraComposer_::create_verifier(const std::shared_ptr& verification_key, const std::shared_ptr& transcript) { - 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); - - return output_state; + return UltraVerifier_(transcript, verification_key); } template DeciderProver_ UltraComposer_::create_decider_prover(const std::shared_ptr& accumulator, const std::shared_ptr& transcript) { - commitment_key = compute_commitment_key(accumulator->instance_size); - DeciderProver_ output_state(accumulator, commitment_key, transcript); - - return output_state; -} - -template -DeciderProver_ UltraComposer_::create_decider_prover( - const std::shared_ptr& accumulator, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript) -{ - DeciderProver_ output_state(accumulator, commitment_key, transcript); - - return output_state; + return DeciderProver_(accumulator, transcript); } template DeciderVerifier_ UltraComposer_::create_decider_verifier( const std::shared_ptr& accumulator, const std::shared_ptr& transcript) { - DeciderVerifier_ output_state(transcript, accumulator); - auto pcs_verification_key = std::make_unique(accumulator->instance_size, crs_factory_); - output_state.pcs_verification_key = std::move(pcs_verification_key); - - return output_state; + return DeciderVerifier_(transcript, accumulator); } template class UltraComposer_; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp index 0805d0e35f62..c87071ccb720 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp @@ -17,46 +17,13 @@ template class UltraComposer_ { using CircuitBuilder = typename Flavor::CircuitBuilder; using ProvingKey = typename Flavor::ProvingKey; using VerificationKey = typename Flavor::VerificationKey; - using PCS = typename Flavor::PCS; using CommitmentKey = typename Flavor::CommitmentKey; using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; using ProverInstance = ProverInstance_; using VerifierInstance = VerifierInstance_; - using FF = typename Flavor::FF; using Transcript = typename Flavor::Transcript; - using CRSFactory = srs::factories::CrsFactory; - - static constexpr size_t NUM_FOLDING = 2; - using ProverInstances = ProverInstances_; - using VerifierInstances = VerifierInstances_; - - // offset due to placing zero wires at the start of execution trace - static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0; - static constexpr std::string_view NAME_STRING = "UltraHonk"; - static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; - - // The crs_factory holds the path to the srs and exposes methods to extract the srs elements - std::shared_ptr crs_factory_; - // The commitment key is passed to the prover but also used herein to compute the verfication key commitments - std::shared_ptr commitment_key; - - UltraComposer_() { crs_factory_ = bb::srs::get_bn254_crs_factory(); } - - explicit UltraComposer_(std::shared_ptr crs_factory) - : crs_factory_(std::move(crs_factory)) - {} - - UltraComposer_(UltraComposer_&& other) noexcept = default; - UltraComposer_(UltraComposer_ const& other) noexcept = default; - UltraComposer_& operator=(UltraComposer_&& other) noexcept = default; - UltraComposer_& operator=(UltraComposer_ const& other) noexcept = default; - ~UltraComposer_() = default; - - std::shared_ptr compute_commitment_key(size_t circuit_size) - { - commitment_key = std::make_shared(circuit_size + 1); - return commitment_key; - }; + using ProverInstances = ProverInstances_; + using VerifierInstances = VerifierInstances_; std::shared_ptr create_prover_instance(CircuitBuilder&); @@ -77,10 +44,6 @@ 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( const std::shared_ptr&, 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 c8f0a1667ca2..1c4d29f30513 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -137,7 +137,7 @@ TEST_F(UltraHonkComposerTests, XorConstraint) circuit_builder.create_gates_from_plookup_accumulators( plookup::MultiTableId::UINT32_XOR, lookup_accumulators, left_witness_index, right_witness_index); - auto composer = UltraComposer(bb::srs::get_bn254_crs_factory()); + UltraComposer composer; prove_and_verify(circuit_builder, composer, /*expected_result=*/true); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp index e9e0a900f970..08ace233814e 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp @@ -20,20 +20,17 @@ UltraVerifier_::UltraVerifier_(const std::shared_ptr& transc template UltraVerifier_::UltraVerifier_(const std::shared_ptr& verifier_key) : key(verifier_key) - , pcs_verification_key(std::make_unique(0, bb::srs::get_bn254_crs_factory())) , transcript(std::make_shared()) {} template UltraVerifier_::UltraVerifier_(UltraVerifier_&& other) : key(std::move(other.key)) - , pcs_verification_key(std::move(other.pcs_verification_key)) {} template UltraVerifier_& UltraVerifier_::operator=(UltraVerifier_&& other) { key = other.key; - pcs_verification_key = (std::move(other.pcs_verification_key)); commitments.clear(); return *this; } @@ -155,7 +152,7 @@ template bool UltraVerifier_::verify_proof(const HonkP multivariate_challenge, transcript); - auto verified = pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); + auto verified = key->pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); return sumcheck_verified.value() && verified; } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.hpp index 9e6df95ebb85..d9f179718489 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.hpp @@ -28,7 +28,6 @@ template class UltraVerifier_ { std::shared_ptr key; std::map commitments; - std::shared_ptr pcs_verification_key; std::shared_ptr transcript; }; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp index e0d075cc5bf2..8ed61fbdd8f9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp @@ -42,7 +42,7 @@ AvmVerifier AvmComposer::create_verifier(CircuitConstructor& circuit_constructor AvmVerifier output_state(verification_key); - auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); + auto pcs_verification_key = std::make_unique(); output_state.pcs_verification_key = std::move(pcs_verification_key); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/toy_composer.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/toy_composer.cpp index 379a7949bf72..d74579371172 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/toy_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/toy_composer.cpp @@ -42,7 +42,7 @@ ToyVerifier ToyComposer::create_verifier(CircuitConstructor& circuit_constructor ToyVerifier output_state(verification_key); - auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); + auto pcs_verification_key = std::make_unique(); output_state.pcs_verification_key = std::move(pcs_verification_key);