From 67a1e2efaf869b3b7c601500399901b79cd4a9bd Mon Sep 17 00:00:00 2001 From: maramihali Date: Mon, 12 Jun 2023 21:33:29 +0200 Subject: [PATCH] refactor(honk): template honk composers by flavor (https://github.com/AztecProtocol/barretenberg/pull/488) --------- Co-authored-by: maramihali Co-authored-by: codygunton Co-authored-by: Mara Mihali --- .../benchmark/honk_bench/honk.bench.cpp | 5 +- .../benchmark/honk_bench/ultra_honk.bench.cpp | 5 +- .../dsl/acir_format/acir_format.cpp | 1 + .../dsl/acir_format/acir_format.hpp | 1 + .../dsl/acir_format/acir_format.test.cpp | 1 + .../scalar_multiplication.cpp | 8 + .../scalar_multiplication.hpp | 9 + .../standard_honk_composer_helper.cpp | 38 +- .../standard_honk_composer_helper.hpp | 43 +- .../ultra_honk_composer_helper.cpp | 23 +- .../ultra_honk_composer_helper.hpp | 41 +- .../honk/composer/standard_honk_composer.hpp | 43 +- .../composer/standard_honk_composer.test.cpp | 14 + .../honk/composer/ultra_honk_composer.hpp | 50 ++- .../composer/ultra_honk_composer.test.cpp | 32 +- .../honk/flavor/standard_grumpkin.hpp | 296 +++++++++++++ .../src/barretenberg/honk/flavor/ultra.hpp | 8 +- .../honk/flavor/ultra_grumpkin.hpp | 395 ++++++++++++++++++ .../barretenberg/honk/proof_system/prover.cpp | 2 +- .../barretenberg/honk/proof_system/prover.hpp | 4 +- .../honk/proof_system/prover_library.cpp | 26 ++ .../honk/proof_system/ultra_prover.cpp | 1 + .../honk/proof_system/ultra_prover.hpp | 3 +- .../honk/proof_system/ultra_verifier.cpp | 1 + .../honk/proof_system/ultra_verifier.hpp | 3 +- .../honk/proof_system/verifier.cpp | 2 +- .../honk/proof_system/verifier.hpp | 2 + .../honk/sumcheck/sumcheck.test.cpp | 4 +- .../honk/transcript/transcript.test.cpp | 56 +-- .../proof_system/flavor/flavor.hpp | 13 +- .../stdlib/encryption/aes128/aes128.hpp | 3 +- .../stdlib/encryption/aes128/aes128.test.cpp | 2 +- .../stdlib/encryption/ecdsa/ecdsa.hpp | 1 - .../stdlib/encryption/ecdsa/ecdsa_impl.hpp | 2 + .../stdlib/hash/blake2s/blake2s.hpp | 6 +- .../stdlib/hash/blake3s/blake3s.hpp | 6 +- .../stdlib/hash/blake3s/blake3s.test.cpp | 1 + .../stdlib/hash/sha256/sha256.hpp | 10 +- .../stdlib/hash/sha256/sha256.test.cpp | 4 +- .../stdlib/hash/sha256/sha256_plookup.hpp | 5 +- .../primitives/bigfield/bigfield.test.cpp | 5 +- .../stdlib/primitives/biggroup/biggroup.hpp | 2 - .../primitives/biggroup/biggroup.test.cpp | 3 +- .../stdlib/primitives/bit_array/bit_array.hpp | 1 - .../primitives/bit_array/bit_array.test.cpp | 2 +- .../stdlib/primitives/bool/bool.cpp | 1 - .../stdlib/primitives/bool/bool.test.cpp | 3 +- .../stdlib/primitives/composers/composers.hpp | 7 + .../primitives/composers/composers_fwd.hpp | 20 +- .../stdlib/primitives/field/array.test.cpp | 5 +- .../stdlib/primitives/field/field.hpp | 2 - .../stdlib/primitives/field/field.test.cpp | 5 +- .../stdlib/primitives/logic/logic.cpp | 1 - .../stdlib/primitives/logic/logic.test.cpp | 1 + .../primitives/memory/dynamic_array.hpp | 2 +- .../primitives/memory/dynamic_array.test.cpp | 1 + .../packed_byte_array/packed_byte_array.hpp | 1 - .../packed_byte_array.test.cpp | 5 +- .../stdlib/primitives/plookup/plookup.hpp | 2 +- .../primitives/plookup/plookup.test.cpp | 1 + .../stdlib/primitives/safe_uint/safe_uint.hpp | 2 +- .../stdlib/primitives/uint/logic.cpp | 1 - .../stdlib/primitives/uint/uint.hpp | 6 - 63 files changed, 1024 insertions(+), 225 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp create mode 100644 barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp index 64229d59e67..3df61bba907 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp @@ -1,10 +1,9 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/proof_system/prover.hpp" -#include "barretenberg/honk/proof_system/verifier.hpp" #include #include -#include "barretenberg/honk/composer/standard_honk_composer.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" using namespace benchmark; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp index f794bc603dc..8a6f7933e42 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp @@ -1,10 +1,9 @@ #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/proof_system/ultra_prover.hpp" -#include "barretenberg/honk/proof_system/ultra_verifier.hpp" #include #include -#include "barretenberg/honk/composer/ultra_honk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp" #include "barretenberg/stdlib/hash/keccak/keccak.hpp" #include "barretenberg/stdlib/primitives/curves/secp256k1.hpp" diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index 9a7ca427671..41374f841e1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -1,5 +1,6 @@ #include "acir_format.hpp" #include "barretenberg/common/log.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" namespace acir_format { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 6e6857d83ad..40bbe871e3a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -13,6 +13,7 @@ #include "pedersen.hpp" #include "hash_to_field.hpp" #include "barretenberg/dsl/types.hpp" +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" namespace acir_format { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 545cab88b5f..43954df2cd9 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -5,6 +5,7 @@ #include "barretenberg/common/streams.hpp" #include "barretenberg/serialize/test_helper.hpp" #include "ecdsa_secp256k1.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" TEST(acir_format, test_a_single_constraint_no_pub_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp index d6fae4d5490..e84ff078e8c 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp @@ -957,6 +957,10 @@ typename Curve::Element pippenger_without_endomorphism_basis_points(typename Cur // Explicit instantiation // BN254 +template void generate_pippenger_point_table(curve::BN254::AffineElement* points, + curve::BN254::AffineElement* table, + size_t num_points); + template uint32_t construct_addition_chains(affine_product_runtime_state& state, bool empty_bucket_counts = true); @@ -1004,6 +1008,10 @@ template curve::BN254::Element pippenger_without_endomorphism_basis_points& state); // Grumpkin +template void generate_pippenger_point_table(curve::Grumpkin::AffineElement* points, + curve::Grumpkin::AffineElement* table, + size_t num_points); + template uint32_t construct_addition_chains(affine_product_runtime_state& state, bool empty_bucket_counts = true); diff --git a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp index f31dbd23b60..121edb3905e 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp @@ -173,6 +173,11 @@ typename Curve::Element pippenger_without_endomorphism_basis_points(typename Cur // Explicit instantiation // BN254 + +extern template void generate_pippenger_point_table(curve::BN254::AffineElement* points, + curve::BN254::AffineElement* table, + size_t num_points); + extern template uint32_t construct_addition_chains(affine_product_runtime_state& state, bool empty_bucket_counts = true); @@ -221,6 +226,10 @@ extern template curve::BN254::Element pippenger_without_endomorphism_basis_point // Grumpkin +extern template void generate_pippenger_point_table(curve::Grumpkin::AffineElement* points, + curve::Grumpkin::AffineElement* table, + size_t num_points); + extern template uint32_t construct_addition_chains( affine_product_runtime_state& state, bool empty_bucket_counts = true); diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.cpp index d22eb300206..ee99db17a03 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.cpp @@ -23,7 +23,8 @@ namespace proof_system::honk { * @param num_reserved_gates The number of reserved gates. * @return Pointer to the initialized proving key updated with selector polynomials. * */ -std::shared_ptr StandardHonkComposerHelper::compute_proving_key_base( +template +std::shared_ptr StandardHonkComposerHelper_::compute_proving_key_base( const CircuitConstructor& constructor, const size_t minimum_circuit_size, const size_t num_randomized_gates) { // Initialize proving_key @@ -45,8 +46,9 @@ std::shared_ptr StandardHonkComposerHelp * * @tparam Program settings needed to establish if w_4 is being used. * */ -void StandardHonkComposerHelper::compute_witness(const CircuitConstructor& circuit_constructor, - const size_t minimum_circuit_size) +template +void StandardHonkComposerHelper_::compute_witness(const CircuitConstructor& circuit_constructor, + const size_t minimum_circuit_size) { if (computed_witness) { return; @@ -67,14 +69,16 @@ void StandardHonkComposerHelper::compute_witness(const CircuitConstructor& circu * * @return Proving key with saved computed polynomials. * */ -std::shared_ptr StandardHonkComposerHelper::compute_proving_key( + +template +std::shared_ptr StandardHonkComposerHelper_::compute_proving_key( const CircuitConstructor& circuit_constructor) { if (proving_key) { return proving_key; } // Compute q_l, q_r, q_o, etc polynomials - StandardHonkComposerHelper::compute_proving_key_base( + StandardHonkComposerHelper_::compute_proving_key_base( circuit_constructor, /*minimum_circuit_size=*/0, NUM_RESERVED_GATES); // Compute sigma polynomials (we should update that late) @@ -91,14 +95,15 @@ std::shared_ptr StandardHonkComposerHelp * * @return Pointer to created circuit verification key. * */ -std::shared_ptr StandardHonkComposerHelper::compute_verification_key( +template +std::shared_ptr StandardHonkComposerHelper_::compute_verification_key( const CircuitConstructor& circuit_constructor) { if (verification_key) { return verification_key; } - verification_key = std::make_shared( + verification_key = std::make_shared( proving_key->circuit_size, proving_key->num_public_inputs, proving_key->composer_type); // Compute and store commitments to all precomputed polynomials @@ -121,28 +126,35 @@ std::shared_ptr StandardHonkCompose return verification_key; } -StandardVerifier StandardHonkComposerHelper::create_verifier(const CircuitConstructor& circuit_constructor) +template +StandardVerifier_ StandardHonkComposerHelper_::create_verifier( + const CircuitConstructor& circuit_constructor) { compute_verification_key(circuit_constructor); - StandardVerifier output_state(verification_key); + StandardVerifier_ output_state(verification_key); auto pcs_verification_key = - std::make_unique(verification_key->circuit_size, crs_factory_); + std::make_unique(verification_key->circuit_size, crs_factory_); output_state.pcs_verification_key = std::move(pcs_verification_key); return output_state; } -StandardProver StandardHonkComposerHelper::create_prover(const CircuitConstructor& circuit_constructor) +template +StandardProver_ StandardHonkComposerHelper_::create_prover( + const CircuitConstructor& circuit_constructor) { compute_proving_key(circuit_constructor); compute_witness(circuit_constructor); compute_commitment_key(proving_key->circuit_size, crs_factory_); - StandardProver output_state(proving_key, commitment_key); + StandardProver_ output_state(proving_key, commitment_key); return output_state; } -} // namespace proof_system::honk +template class StandardHonkComposerHelper_; +template class StandardHonkComposerHelper_; + +} // namespace proof_system::honk \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp index a1542e53b7b..bf5b0953228 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp @@ -10,16 +10,16 @@ #include "barretenberg/proof_system/composer/permutation_helper.hpp" #include "barretenberg/honk/flavor/standard.hpp" +#include "barretenberg/honk/flavor/standard_grumpkin.hpp" namespace proof_system::honk { -class StandardHonkComposerHelper { +template class StandardHonkComposerHelper_ { public: - using Flavor = flavor::Standard; - using PCSParams = Flavor::PCSParams; - using CircuitConstructor = Flavor::CircuitConstructor; - using ProvingKey = Flavor::ProvingKey; - using VerificationKey = Flavor::VerificationKey; - using PCSCommitmentKey = PCSParams::CommitmentKey; + using PCSParams = typename Flavor::PCSParams; + using CircuitConstructor = typename Flavor::CircuitConstructor; + using ProvingKey = typename Flavor::ProvingKey; + using VerificationKey = typename Flavor::VerificationKey; + using PCSCommitmentKey = typename PCSParams::CommitmentKey; static constexpr size_t NUM_RESERVED_GATES = 2; // equal to the number of multilinear evaluations leaked static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; @@ -34,33 +34,33 @@ class StandardHonkComposerHelper { bool computed_witness = false; // TODO(Luke): use make_shared - StandardHonkComposerHelper() - : StandardHonkComposerHelper( + StandardHonkComposerHelper_() + : StandardHonkComposerHelper_( std::shared_ptr(new srs::factories::FileCrsFactory("../srs_db/ignition"))) {} - StandardHonkComposerHelper(std::shared_ptr crs_factory) + StandardHonkComposerHelper_(std::shared_ptr crs_factory) : crs_factory_(std::move(crs_factory)) {} - StandardHonkComposerHelper(std::unique_ptr&& crs_factory) + StandardHonkComposerHelper_(std::unique_ptr&& crs_factory) : crs_factory_(std::move(crs_factory)) {} - StandardHonkComposerHelper(std::shared_ptr p_key, std::shared_ptr v_key) + StandardHonkComposerHelper_(std::shared_ptr p_key, std::shared_ptr v_key) : proving_key(std::move(p_key)) , verification_key(std::move(v_key)) {} - StandardHonkComposerHelper(StandardHonkComposerHelper&& other) noexcept = default; - StandardHonkComposerHelper(const StandardHonkComposerHelper& other) = delete; - StandardHonkComposerHelper& operator=(StandardHonkComposerHelper&& other) noexcept = default; - StandardHonkComposerHelper& operator=(const StandardHonkComposerHelper& other) = delete; - ~StandardHonkComposerHelper() = default; + StandardHonkComposerHelper_(StandardHonkComposerHelper_&& other) noexcept = default; + StandardHonkComposerHelper_(const StandardHonkComposerHelper_& other) = delete; + StandardHonkComposerHelper_& operator=(StandardHonkComposerHelper_&& other) noexcept = default; + StandardHonkComposerHelper_& operator=(const StandardHonkComposerHelper_& other) = delete; + ~StandardHonkComposerHelper_() = default; std::shared_ptr compute_proving_key(const CircuitConstructor& circuit_constructor); std::shared_ptr compute_verification_key(const CircuitConstructor& circuit_constructor); - StandardVerifier create_verifier(const CircuitConstructor& circuit_constructor); + StandardVerifier_ create_verifier(const CircuitConstructor& circuit_constructor); - StandardProver create_prover(const CircuitConstructor& circuit_constructor); + StandardProver_ create_prover(const CircuitConstructor& circuit_constructor); // TODO(#216)(Adrian): Seems error prone to provide the number of randomized gates std::shared_ptr compute_proving_key_base(const CircuitConstructor& circuit_constructor, @@ -71,8 +71,11 @@ class StandardHonkComposerHelper { void compute_commitment_key(size_t circuit_size, std::shared_ptr crs_factory) { - commitment_key = std::make_shared(circuit_size, crs_factory_); + commitment_key = std::make_shared(circuit_size, crs_factory_); }; }; +extern template class StandardHonkComposerHelper_; +extern template class StandardHonkComposerHelper_; +using StandardHonkComposerHelper = StandardHonkComposerHelper_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp index 3516adb6e87..aed2c22d58c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp @@ -10,7 +10,8 @@ namespace proof_system::honk { * @brief Compute witness polynomials * */ -void UltraHonkComposerHelper::compute_witness(CircuitConstructor& circuit_constructor) +template +void UltraHonkComposerHelper_::compute_witness(CircuitConstructor& circuit_constructor) { if (computed_witness) { return; @@ -155,7 +156,8 @@ void UltraHonkComposerHelper::compute_witness(CircuitConstructor& circuit_constr computed_witness = true; } -UltraProver UltraHonkComposerHelper::create_prover(CircuitConstructor& circuit_constructor) +template +UltraProver_ UltraHonkComposerHelper_::create_prover(CircuitConstructor& circuit_constructor) { finalize_circuit(circuit_constructor); @@ -164,7 +166,7 @@ UltraProver UltraHonkComposerHelper::create_prover(CircuitConstructor& circuit_c compute_commitment_key(proving_key->circuit_size, crs_factory_); - UltraProver output_state(proving_key, commitment_key); + UltraProver_ output_state(proving_key, commitment_key); return output_state; } @@ -175,11 +177,12 @@ UltraProver UltraHonkComposerHelper::create_prover(CircuitConstructor& circuit_c * * @return The verifier. * */ -UltraVerifier UltraHonkComposerHelper::create_verifier(const CircuitConstructor& circuit_constructor) +template +UltraVerifier_ UltraHonkComposerHelper_::create_verifier(const CircuitConstructor& circuit_constructor) { auto verification_key = compute_verification_key(circuit_constructor); - UltraVerifier output_state(verification_key); + UltraVerifier_ output_state(verification_key); auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); @@ -188,7 +191,8 @@ UltraVerifier UltraHonkComposerHelper::create_verifier(const CircuitConstructor& return output_state; } -std::shared_ptr UltraHonkComposerHelper::compute_proving_key( +template +std::shared_ptr UltraHonkComposerHelper_::compute_proving_key( const CircuitConstructor& circuit_constructor) { if (proving_key) { @@ -310,7 +314,8 @@ std::shared_ptr UltraHonkComposerHe * * @return Pointer to created circuit verification key. * */ -std::shared_ptr UltraHonkComposerHelper::compute_verification_key( +template +std::shared_ptr UltraHonkComposerHelper_::compute_verification_key( const CircuitConstructor& circuit_constructor) { if (verification_key) { @@ -321,7 +326,7 @@ std::shared_ptr UltraHonkComposerHelpe compute_proving_key(circuit_constructor); } - verification_key = std::make_shared( + verification_key = std::make_shared( proving_key->circuit_size, proving_key->num_public_inputs, proving_key->composer_type); // Compute and store commitments to all precomputed polynomials @@ -360,5 +365,7 @@ std::shared_ptr UltraHonkComposerHelpe return verification_key; } +template class UltraHonkComposerHelper_; +template class UltraHonkComposerHelper_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp index 2596b0a336f..a07e9c16846 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp @@ -13,16 +13,15 @@ #include namespace proof_system::honk { -class UltraHonkComposerHelper { +template class UltraHonkComposerHelper_ { public: - using Flavor = flavor::Ultra; - using CircuitConstructor = Flavor::CircuitConstructor; - using ProvingKey = Flavor::ProvingKey; - using VerificationKey = Flavor::VerificationKey; - using PCSParams = Flavor::PCSParams; - using PCS = Flavor::PCS; - using PCSCommitmentKey = PCSParams::CommitmentKey; - using PCSVerificationKey = PCSParams::VerificationKey; + using CircuitConstructor = typename Flavor::CircuitConstructor; + using ProvingKey = typename Flavor::ProvingKey; + using VerificationKey = typename Flavor::VerificationKey; + using PCSParams = typename Flavor::PCSParams; + using PCS = typename Flavor::PCS; + using PCSCommitmentKey = typename PCSParams::CommitmentKey; + using PCSVerificationKey = typename PCSParams::VerificationKey; static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of multilinear evaluations leaked static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; @@ -45,20 +44,20 @@ class UltraHonkComposerHelper { // vanishing_polynomial cannot be trivially fetched here, I am directly setting this to 4 - 1 = 3. static constexpr size_t s_randomness = 3; - explicit UltraHonkComposerHelper(std::shared_ptr crs_factory) + explicit UltraHonkComposerHelper_(std::shared_ptr crs_factory) : crs_factory_(std::move(crs_factory)) {} - UltraHonkComposerHelper(std::shared_ptr p_key, std::shared_ptr v_key) + UltraHonkComposerHelper_(std::shared_ptr p_key, std::shared_ptr v_key) : proving_key(std::move(p_key)) , verification_key(std::move(v_key)) {} - UltraHonkComposerHelper(UltraHonkComposerHelper&& other) noexcept = default; - UltraHonkComposerHelper(UltraHonkComposerHelper const& other) noexcept = default; - UltraHonkComposerHelper& operator=(UltraHonkComposerHelper&& other) noexcept = default; - UltraHonkComposerHelper& operator=(UltraHonkComposerHelper const& other) noexcept = default; - ~UltraHonkComposerHelper() = default; + UltraHonkComposerHelper_(UltraHonkComposerHelper_&& other) noexcept = default; + UltraHonkComposerHelper_(UltraHonkComposerHelper_ const& other) noexcept = default; + UltraHonkComposerHelper_& operator=(UltraHonkComposerHelper_&& other) noexcept = default; + UltraHonkComposerHelper_& operator=(UltraHonkComposerHelper_ const& other) noexcept = default; + ~UltraHonkComposerHelper_() = default; void finalize_circuit(CircuitConstructor& circuit_constructor) { circuit_constructor.finalize_circuit(); }; @@ -67,15 +66,17 @@ class UltraHonkComposerHelper { void compute_witness(CircuitConstructor& circuit_constructor); - UltraProver create_prover(CircuitConstructor& circuit_constructor); - UltraVerifier create_verifier(const CircuitConstructor& circuit_constructor); + UltraProver_ create_prover(CircuitConstructor& circuit_constructor); + UltraVerifier_ create_verifier(const CircuitConstructor& circuit_constructor); void add_table_column_selector_poly_to_proving_key(polynomial& small, const std::string& tag); void compute_commitment_key(size_t circuit_size, std::shared_ptr crs_factory) { - commitment_key = std::make_shared(circuit_size, crs_factory_); + commitment_key = std::make_shared(circuit_size, crs_factory_); }; }; - +extern template class UltraHonkComposerHelper_; +extern template class UltraHonkComposerHelper_; +using UltraHonkComposerHelper = UltraHonkComposerHelper_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp index 33366039b5c..ff9467cf249 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp @@ -13,13 +13,12 @@ namespace proof_system::honk { * @details However, it has a lot of its logic separated into subclasses and simply proxies the calls. * */ -class StandardHonkComposer { +template class StandardHonkComposer_ { public: // TODO(#426): This doesn't belong here static constexpr merkle::HashType merkle_hash_type = merkle::HashType::LOOKUP_PEDERSEN; static constexpr pedersen::CommitmentType commitment_type = pedersen::CommitmentType::FIXED_BASE_PEDERSEN; - using Flavor = flavor::Standard; using CircuitConstructor = StandardCircuitConstructor; using ProvingKey = typename Flavor::ProvingKey; using VerificationKey = typename Flavor::VerificationKey; @@ -32,7 +31,7 @@ class StandardHonkComposer { // 1) Proving and verification keys // 2) CRS // 3) Converting variables to witness vectors/polynomials - StandardHonkComposerHelper composer_helper; + StandardHonkComposerHelper_ composer_helper; // Leaving it in for now just in case bool contains_recursive_proof = false; @@ -40,24 +39,24 @@ class StandardHonkComposer { /**Standard methods*/ - StandardHonkComposer(const size_t size_hint = 0) + StandardHonkComposer_(const size_t size_hint = 0) : circuit_constructor(size_hint) , num_gates(circuit_constructor.num_gates) , variables(circuit_constructor.variables){}; - StandardHonkComposer(std::string const& crs_path, const size_t size_hint = 0) - : StandardHonkComposer(barretenberg::srs::get_crs_factory(), size_hint){}; + StandardHonkComposer_(std::string const& crs_path, const size_t size_hint = 0) + : StandardHonkComposer_(barretenberg::srs::get_crs_factory(), size_hint){}; - StandardHonkComposer(std::shared_ptr const& crs_factory, - const size_t size_hint = 0) + StandardHonkComposer_(std::shared_ptr const& crs_factory, + const size_t size_hint = 0) : circuit_constructor(size_hint) , composer_helper(crs_factory) , num_gates(circuit_constructor.num_gates) , variables(circuit_constructor.variables) {} - StandardHonkComposer(std::unique_ptr&& crs_factory, - const size_t size_hint = 0) + StandardHonkComposer_(std::unique_ptr&& crs_factory, + const size_t size_hint = 0) : circuit_constructor(size_hint) , composer_helper(std::move(crs_factory)) , num_gates(circuit_constructor.num_gates) @@ -65,22 +64,22 @@ class StandardHonkComposer { {} - StandardHonkComposer(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0) + StandardHonkComposer_(std::shared_ptr const& p_key, + std::shared_ptr const& v_key, + size_t size_hint = 0) : circuit_constructor(size_hint) , composer_helper(p_key, v_key) , num_gates(circuit_constructor.num_gates) , variables(circuit_constructor.variables) {} - StandardHonkComposer(const StandardHonkComposer& other) = delete; - StandardHonkComposer(StandardHonkComposer&& other) = default; - StandardHonkComposer& operator=(const StandardHonkComposer& other) = delete; + StandardHonkComposer_(const StandardHonkComposer_& other) = delete; + StandardHonkComposer_(StandardHonkComposer_&& other) = default; + StandardHonkComposer_& operator=(const StandardHonkComposer_& other) = delete; // TODO(#230)(Cody): This constructor started to be implicitly deleted when I added `n` and `variables` members. // This is a temporary measure until we can rewrite Plonk and all tests using circuit builder methods in place of - // composer methods, where appropriate. StandardHonkComposer& operator=(StandardHonkComposer&& other) = default; - ~StandardHonkComposer() = default; + // composer methods, where appropriate. StandardHonkComposer_& operator=(StandardHonkComposer_&& other) = default; + ~StandardHonkComposer_() = default; size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } @@ -183,8 +182,8 @@ class StandardHonkComposer { void compute_witness() { composer_helper.compute_witness(circuit_constructor); }; - StandardVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); } - StandardProver create_prover() { return composer_helper.create_prover(circuit_constructor); }; + StandardVerifier_ create_verifier() { return composer_helper.create_verifier(circuit_constructor); } + StandardProver_ create_prover() { return composer_helper.create_prover(circuit_constructor); }; size_t& num_gates; std::vector& variables; @@ -192,4 +191,8 @@ class StandardHonkComposer { const std::string& err() const { return circuit_constructor.err(); }; void failure(std::string msg) { circuit_constructor.failure(msg); } }; +template class StandardHonkComposer_; +template class StandardHonkComposer_; +using StandardHonkComposer = StandardHonkComposer_; +using StandardGrumpkinHonkComposer = StandardHonkComposer_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp index d2476915148..913c4197e5e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp @@ -195,6 +195,7 @@ TEST_F(StandardHonkComposerTests, LagrangeCorrectness) */ TEST_F(StandardHonkComposerTests, AssertEquals) { + /** * @brief A function that creates a simple circuit with repeated gates, leading to large permutation cycles * @@ -289,6 +290,7 @@ TEST_F(StandardHonkComposerTests, AssertEquals) TEST_F(StandardHonkComposerTests, VerificationKeyCreation) { + // Create a composer and a dummy circuit with a few gates StandardHonkComposer composer = StandardHonkComposer(); fr a = fr::one(); @@ -390,4 +392,16 @@ TEST_F(StandardHonkComposerTests, SumcheckEvaluations) run_test(/*expected_result=*/true); run_test(/*expected_result=*/false); } +TEST(StandardGrumpkinHonkComposer, BaseCase) +{ + auto composer = StandardGrumpkinHonkComposer(); + fr a = 1; + composer.circuit_constructor.add_variable(a); + + auto prover = composer.create_prover(); + plonk::proof proof = prover.construct_proof(); + auto verifier = composer.create_verifier(); + bool verified = verifier.verify_proof(proof); + ASSERT_TRUE(verified); +} } // namespace test_standard_honk_composer diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp index 23ba1b043f2..e70e37f63d4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp @@ -7,7 +7,7 @@ #include "barretenberg/honk/flavor/ultra.hpp" namespace proof_system::honk { -class UltraHonkComposer { +template class UltraHonkComposer_ { public: // An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system @@ -16,20 +16,18 @@ class UltraHonkComposer { // 1) Proving and verification keys // 2) CRS // 3) Converting variables to witness vectors/polynomials - using Flavor = honk::flavor::Ultra; using CircuitConstructor = UltraCircuitConstructor; using ProvingKey = typename Flavor::ProvingKey; using VerificationKey = typename Flavor::VerificationKey; + // TODO(#426): This don't belong here static constexpr ComposerType type = ComposerType::PLOOKUP; static_assert(type == CircuitConstructor::type); static constexpr merkle::HashType merkle_hash_type = CircuitConstructor::merkle_hash_type; static constexpr pedersen::CommitmentType commitment_type = CircuitConstructor::commitment_type; static constexpr size_t DEFAULT_PLOOKUP_RANGE_BITNUM = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM; - UltraHonkComposerHelper composer_helper; - - // References to circuit_constructor's members for convenience + UltraHonkComposerHelper_ composer_helper; size_t& num_gates; std::vector& variables; // While we always have it set to zero, feels wrong to have a potentially broken dependency @@ -37,16 +35,16 @@ class UltraHonkComposer { bool& contains_recursive_proof; std::vector& recursive_proof_public_input_indices; - UltraHonkComposer() - : UltraHonkComposer(barretenberg::srs::get_crs_factory(), 0){}; + UltraHonkComposer_() + : UltraHonkComposer_(barretenberg::srs::get_crs_factory(), 0){}; - UltraHonkComposer(std::string const& crs_path, const size_t size_hint) - : UltraHonkComposer(std::unique_ptr( - new barretenberg::srs::factories::FileCrsFactory(crs_path)), - size_hint){}; + UltraHonkComposer_(std::string const& crs_path, const size_t size_hint) + : UltraHonkComposer_(std::unique_ptr( + new barretenberg::srs::factories::FileCrsFactory(crs_path)), + size_hint){}; - UltraHonkComposer(std::shared_ptr const& crs_factory, - const size_t size_hint) + UltraHonkComposer_(std::shared_ptr const& crs_factory, + const size_t size_hint) : circuit_constructor(size_hint) , composer_helper(crs_factory) , num_gates(circuit_constructor.num_gates) @@ -59,17 +57,12 @@ class UltraHonkComposer { add_gates_to_ensure_all_polys_are_non_zero(); }; - UltraHonkComposer(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0); - UltraHonkComposer(UltraHonkComposer&& other) = default; - UltraHonkComposer& operator=(UltraHonkComposer&& other) - { - circuit_constructor = std::move(other.circuit_constructor); - composer_helper = std::move(other.composer_helper); - return *this; - }; - ~UltraHonkComposer() = default; + UltraHonkComposer_(std::shared_ptr const& p_key, + std::shared_ptr const& v_key, + size_t size_hint = 0); + UltraHonkComposer_(UltraHonkComposer_&& other) = default; + UltraHonkComposer_& operator=(UltraHonkComposer_&& other) = delete; + ~UltraHonkComposer_() = default; size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } uint32_t get_zero_idx() { return circuit_constructor.zero_idx; } @@ -87,8 +80,8 @@ class UltraHonkComposer { void finalize_circuit() { circuit_constructor.finalize_circuit(); }; - UltraProver create_prover() { return composer_helper.create_prover(circuit_constructor); }; - UltraVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); }; + UltraProver_ create_prover() { return composer_helper.create_prover(circuit_constructor); }; + UltraVerifier_ create_verifier() { return composer_helper.create_verifier(circuit_constructor); }; void add_gates_to_ensure_all_polys_are_non_zero() { @@ -300,4 +293,9 @@ class UltraHonkComposer { const std::string& err() const { return circuit_constructor.err(); }; void failure(std::string msg) { circuit_constructor.failure(msg); } }; +template class UltraHonkComposer_; +template class UltraHonkComposer_; +using UltraHonkComposer = UltraHonkComposer_; +using UltraGrumpkinHonkComposer = UltraHonkComposer_; + } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp index 19a1e71bc54..f76025bee55 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp @@ -113,9 +113,9 @@ TEST_F(UltraHonkComposerTests, XorConstraint) const auto lookup_accumulators = plookup::get_lookup_accumulators( plookup::MultiTableId::UINT32_XOR, left_witness_value, right_witness_value, true); auto xor_result = lookup_accumulators[plookup::ColumnIdx::C3] - [0]; // The zeroth index in the 3rd column is the fully accumulated xor result - EXPECT_EQ(xor_result, xor_result_expected); + [0]; // The zeroth index in the 3rd column is the fully accumulated xor + EXPECT_EQ(xor_result, xor_result_expected); composer.create_gates_from_plookup_accumulators( plookup::MultiTableId::UINT32_XOR, lookup_accumulators, left_witness_index, right_witness_index); @@ -560,7 +560,6 @@ TEST_F(UltraHonkComposerTests, range_constraint) TEST_F(UltraHonkComposerTests, range_with_gates) { - auto composer = UltraHonkComposer(); auto idx = add_variables(composer, { 1, 2, 3, 4, 5, 6, 7, 8 }); for (size_t i = 0; i < idx.size(); i++) { @@ -805,6 +804,33 @@ TEST_F(UltraHonkComposerTests, ram) prove_and_verify(composer, /*expected_result=*/true); } +TEST(UltraGrumpkinHonkComposer, XorConstraint) +{ + auto composer = UltraGrumpkinHonkComposer(); + + uint32_t left_value = engine.get_random_uint32(); + uint32_t right_value = engine.get_random_uint32(); + + fr left_witness_value = fr{ left_value, 0, 0, 0 }.to_montgomery_form(); + fr right_witness_value = fr{ right_value, 0, 0, 0 }.to_montgomery_form(); + + uint32_t left_witness_index = composer.add_variable(left_witness_value); + uint32_t right_witness_index = composer.add_variable(right_witness_value); + + uint32_t xor_result_expected = left_value ^ right_value; + + const auto lookup_accumulators = plookup::get_lookup_accumulators( + plookup::MultiTableId::UINT32_XOR, left_witness_value, right_witness_value, true); + auto xor_result = lookup_accumulators[plookup::ColumnIdx::C3] + [0]; // The zeroth index in the 3rd column is the fully accumulated xor + + EXPECT_EQ(xor_result, xor_result_expected); + composer.create_gates_from_plookup_accumulators( + plookup::MultiTableId::UINT32_XOR, lookup_accumulators, left_witness_index, right_witness_index); + + prove_and_verify(composer, /*expected_result=*/true); +} + // TODO(#378)(luke): this is a recent update from Zac and fails; do we need a corresponding bug fix in ultra circuit // c_Fonstructor? TEST(UltraHonkComposerTests, range_checks_on_duplicates) // { diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp new file mode 100644 index 00000000000..331fecaa9ad --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp @@ -0,0 +1,296 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" +#include "barretenberg/honk/pcs/ipa/ipa.hpp" +#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/ecc/curves/bn254/g1.hpp" +#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" +#include "barretenberg/polynomials/evaluation_domain.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" +#include "barretenberg/proof_system/flavor/flavor.hpp" + +namespace proof_system::honk::flavor { +class StandardGrumpkin { + // TODO(Mara): At the moment this class is a duplicate of the Standard flavor with a different PCS for testing + // purposes. This will be changed to Grumpkin once generating Honk proofs over Grumpkin has been enabled. + public: + using CircuitConstructor = StandardCircuitConstructor; + using FF = barretenberg::fr; + using Polynomial = barretenberg::Polynomial; + using PolynomialHandle = std::span; + using G1 = barretenberg::g1; + using GroupElement = G1::element; + using Commitment = G1::affine_element; + using CommitmentHandle = G1::affine_element; + using PCSParams = pcs::ipa::Params; + using PCS = pcs::ipa::IPA; + static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; + // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often + // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS` + static constexpr size_t NUM_ALL_ENTITIES = 18; + // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying + // assignment of witnesses. We again choose a neutral name. + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 13; + // The total number of witness entities not including shifts. + static constexpr size_t NUM_WITNESS_ENTITIES = 4; + + // define the tuple of Relations that comprise the Sumcheck relation + using Relations = std::tuple, sumcheck::PermutationRelation>; + + static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t NUM_RELATIONS = std::tuple_size::value; + + // Instantiate the BarycentricData needed to extend each Relation Univariate + static_assert(instantiate_barycentric_utils()); + + // define the containers for storing the contributions from each relation in Sumcheck + using RelationUnivariates = decltype(create_relation_univariates_container()); + using RelationValues = decltype(create_relation_values_container()); + + // define utilities to extend univarates from RELATION_LENGTH to MAX_RELATION_LENGTH for each Relation + // using BarycentricUtils = decltype(create_barycentric_utils()); + + private: + /** + * @brief A base class labelling precomputed entities and (ordered) subsets of interest. + * @details Used to build the proving key and verification key. + */ + template + class PrecomputedEntities : public PrecomputedEntities_ { + public: + DataType& q_m = std::get<0>(this->_data); + DataType& q_l = std::get<1>(this->_data); + DataType& q_r = std::get<2>(this->_data); + DataType& q_o = std::get<3>(this->_data); + DataType& q_c = std::get<4>(this->_data); + DataType& sigma_1 = std::get<5>(this->_data); + DataType& sigma_2 = std::get<6>(this->_data); + DataType& sigma_3 = std::get<7>(this->_data); + DataType& id_1 = std::get<8>(this->_data); + DataType& id_2 = std::get<9>(this->_data); + DataType& id_3 = std::get<10>(this->_data); + DataType& lagrange_first = std::get<11>(this->_data); + DataType& lagrange_last = std::get<12>(this->_data); // = LAGRANGE_N-1 whithout ZK, but can be less + + std::vector get_selectors() override { return { q_m, q_l, q_r, q_o, q_c }; }; + std::vector get_sigma_polynomials() override { return { sigma_1, sigma_2, sigma_3 }; }; + std::vector get_id_polynomials() override { return { id_1, id_2, id_3 }; }; + }; + + /** + * @brief Container for all witness polynomials used/constructed by the prover. + * @details Shifts are not included here since they do not occupy their own memory. + */ + template + class WitnessEntities : public WitnessEntities_ { + public: + DataType& w_l = std::get<0>(this->_data); + DataType& w_r = std::get<1>(this->_data); + DataType& w_o = std::get<2>(this->_data); + DataType& z_perm = std::get<3>(this->_data); + + std::vector get_wires() override { return { w_l, w_r, w_o }; }; + }; + + /** + * @brief A base class labelling all entities (for instance, all of the polynomials used by the prover during + * sumcheck) in this Honk variant along with particular subsets of interest + * @details Used to build containers for: the prover's polynomial during sumcheck; the sumcheck's folded + * polynomials; the univariates consturcted during during sumcheck; the evaluations produced by sumcheck. + * + * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be + * implemented as such, but we don't have this now. + */ + template + class AllEntities : public AllEntities_ { + public: + DataType& q_c = std::get<0>(this->_data); + DataType& q_l = std::get<1>(this->_data); + DataType& q_r = std::get<2>(this->_data); + DataType& q_o = std::get<3>(this->_data); + DataType& q_m = std::get<4>(this->_data); + DataType& sigma_1 = std::get<5>(this->_data); + DataType& sigma_2 = std::get<6>(this->_data); + DataType& sigma_3 = std::get<7>(this->_data); + DataType& id_1 = std::get<8>(this->_data); + DataType& id_2 = std::get<9>(this->_data); + DataType& id_3 = std::get<10>(this->_data); + DataType& lagrange_first = std::get<11>(this->_data); + DataType& lagrange_last = std::get<12>(this->_data); + DataType& w_l = std::get<13>(this->_data); + DataType& w_r = std::get<14>(this->_data); + DataType& w_o = std::get<15>(this->_data); + DataType& z_perm = std::get<16>(this->_data); + DataType& z_perm_shift = std::get<17>(this->_data); + + std::vector get_wires() override { return { w_l, w_r, w_o }; }; + + // Gemini-specific getters. + std::vector get_unshifted() override + { + return { q_c, q_l, q_r, q_o, q_m, sigma_1, sigma_2, sigma_3, id_1, id_2, id_3, lagrange_first, + lagrange_last, w_l, w_r, w_o, z_perm }; + }; + std::vector get_to_be_shifted() override { return { z_perm }; }; + std::vector get_shifted() override { return { z_perm_shift }; }; + + // TODO(Cody): It would be nice to define these constructors once in a base class template. + AllEntities() = default; + + AllEntities(const AllEntities& other) + : AllEntities_(other){}; + + AllEntities(AllEntities&& other) + : AllEntities_(other){}; + + AllEntities& operator=(const AllEntities& other) + { + if (this == &other) { + return *this; + } + AllEntities_::operator=(other); + return *this; + } + + AllEntities& operator=(AllEntities&& other) + { + AllEntities_::operator=(other); + return *this; + } + + ~AllEntities() = default; + }; + + public: + /** + * @brief The proving key is responsible for storing the polynomials used by the prover. + * @note TODO(Cody): Maybe multiple inheritance is the right thing here. In that case, nothing should eve inherit + * from ProvingKey. + */ + class ProvingKey : public ProvingKey_, + WitnessEntities> { + public: + // Expose constructors of the base class + using Base = ProvingKey_, + WitnessEntities>; + using Base::Base; + }; + + /** + * @brief The verification key is responsible for storing the the commitments to the precomputed (non-witness) + * polynomials used by the verifier. + * + * @note Note the discrepancy with what sort of data is stored here vs in the proving key. We may want to resolve + * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our + * circuits. + */ + using VerificationKey = VerificationKey_>; + + /** + * @brief A container for polynomials handles; only stores spans. + */ + using ProverPolynomials = AllEntities; + + /** + * @brief A container for storing the partially evaluated multivariates produced by sumcheck. + */ + class PartiallyEvaluatedMultivariates : public AllEntities { + + public: + PartiallyEvaluatedMultivariates() = default; + PartiallyEvaluatedMultivariates(const size_t circuit_size) + { + // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) + for (auto& poly : this->_data) { + poly = Polynomial(circuit_size / 2); + } + } + }; + + /** + * @brief A container for univariates produced during the hot loop in sumcheck. + * @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? + */ + template + using ExtendedEdges = + AllEntities, sumcheck::Univariate>; + + /** + * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the + * evaluations of polynomials committed in earlier rounds. + */ + class ClaimedEvaluations : public AllEntities { + public: + using Base = AllEntities; + using Base::Base; + ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + }; + + /** + * @brief A container for commitment labels. + * @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly needed. It + * has, however, been useful during debugging to have these labels available. + * + */ + class CommitmentLabels : public AllEntities { + public: + CommitmentLabels() + : AllEntities() + { + w_l = "W_1"; + w_r = "W_2"; + w_o = "W_3"; + z_perm = "Z_PERM"; + // The ones beginning with "__" are only used for debugging + z_perm_shift = "__Z_PERM_SHIFT"; + q_m = "__Q_M"; + q_l = "__Q_L"; + q_r = "__Q_R"; + q_o = "__Q_O"; + q_c = "__Q_C"; + sigma_1 = "__SIGMA_1"; + sigma_2 = "__SIGMA_2"; + sigma_3 = "__SIGMA_3"; + id_1 = "__ID_1"; + id_2 = "__ID_2"; + id_3 = "__ID_3"; + lagrange_first = "__LAGRANGE_FIRST"; + lagrange_last = "__LAGRANGE_LAST"; + }; + }; + + /** + * @brief A container for all commitments used by the verifier. + */ + class VerifierCommitments : public AllEntities { + public: + VerifierCommitments(std::shared_ptr verification_key) + { + // Initialize pre-computed commitments here, witness commitments during proof verification. + q_m = verification_key->q_m; + q_l = verification_key->q_l; + q_r = verification_key->q_r; + q_o = verification_key->q_o; + q_c = verification_key->q_c; + sigma_1 = verification_key->sigma_1; + sigma_2 = verification_key->sigma_2; + sigma_3 = verification_key->sigma_3; + id_1 = verification_key->id_1; + id_2 = verification_key->id_2; + id_3 = verification_key->id_3; + lagrange_first = verification_key->lagrange_first; + lagrange_last = verification_key->lagrange_last; + } + }; +}; +} // namespace proof_system::honk::flavor \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 80daafbd2ec..6005b809a27 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -7,7 +7,7 @@ #include #include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/pcs/ipa/ipa.hpp" +#include "barretenberg/honk/pcs/kzg/kzg.hpp" #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/transcript/transcript.hpp" @@ -38,9 +38,9 @@ class Ultra { using CommitmentHandle = G1::affine_element; // UltraHonk will be run with KZG by default but temporarily we set the commitment to IPA to // be able to do e2e tests with this pcs as well - // TODO: instantiate this with but IPA and KZG when the templating work is finished - using PCSParams = pcs::ipa::Params; - using PCS = pcs::ipa::IPA; + // TODO: instantiate this with both IPA and KZG when the templating work is finished + using PCSParams = pcs::kzg::Params; + using PCS = pcs::kzg::KZG; static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp new file mode 100644 index 00000000000..eb263996274 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -0,0 +1,395 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" +#include "barretenberg/honk/pcs/ipa/ipa.hpp" +#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/ecc/curves/bn254/g1.hpp" +#include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" +#include "barretenberg/polynomials/evaluation_domain.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" +#include "barretenberg/proof_system/flavor/flavor.hpp" +#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" + +namespace proof_system::honk::flavor { + +class UltraGrumpkin { + // TODO(Mara): At the moment this class is a duplicate of the Standard flavor with a different PCS for testing + // purposes. This will be changed to Grumpkin once generating Honk proofs over Grumpkin has been enabled. + public: + using CircuitConstructor = UltraCircuitConstructor; + using FF = barretenberg::fr; + using Polynomial = barretenberg::Polynomial; + using PolynomialHandle = std::span; + using G1 = barretenberg::g1; + using GroupElement = G1::element; + using Commitment = G1::affine_element; + using CommitmentHandle = G1::affine_element; + using PCSParams = pcs::ipa::Params; + using PCS = pcs::ipa::IPA; + + static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; + // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often + // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. + // Note: this number does not include the individual sorted list polynomials. + static constexpr size_t NUM_ALL_ENTITIES = 43; + // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying + // assignment of witnesses. We again choose a neutral name. + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25; + // The total number of witness entities not including shifts. + static constexpr size_t NUM_WITNESS_ENTITIES = 11; + + // define the tuple of Relations that comprise the Sumcheck relation + using Relations = std::tuple, + sumcheck::UltraPermutationRelation, + sumcheck::LookupRelation, + sumcheck::GenPermSortRelation, + sumcheck::EllipticRelation, + sumcheck::AuxiliaryRelation>; + + static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t NUM_RELATIONS = std::tuple_size::value; + + // Instantiate the BarycentricData needed to extend each Relation Univariate + static_assert(instantiate_barycentric_utils()); + + // define the container for storing the univariate contribution from each relation in Sumcheck + using RelationUnivariates = decltype(create_relation_univariates_container()); + using RelationValues = decltype(create_relation_values_container()); + + private: + template + /** + * @brief A base class labelling precomputed entities and (ordered) subsets of interest. + * @details Used to build the proving key and verification key. + */ + class PrecomputedEntities : public PrecomputedEntities_ { + public: + DataType& q_m = std::get<0>(this->_data); + DataType& q_c = std::get<1>(this->_data); + DataType& q_l = std::get<2>(this->_data); + DataType& q_r = std::get<3>(this->_data); + DataType& q_o = std::get<4>(this->_data); + DataType& q_4 = std::get<5>(this->_data); + DataType& q_arith = std::get<6>(this->_data); + DataType& q_sort = std::get<7>(this->_data); + DataType& q_elliptic = std::get<8>(this->_data); + DataType& q_aux = std::get<9>(this->_data); + DataType& q_lookup = std::get<10>(this->_data); + DataType& sigma_1 = std::get<11>(this->_data); + DataType& sigma_2 = std::get<12>(this->_data); + DataType& sigma_3 = std::get<13>(this->_data); + DataType& sigma_4 = std::get<14>(this->_data); + DataType& id_1 = std::get<15>(this->_data); + DataType& id_2 = std::get<16>(this->_data); + DataType& id_3 = std::get<17>(this->_data); + DataType& id_4 = std::get<18>(this->_data); + DataType& table_1 = std::get<19>(this->_data); + DataType& table_2 = std::get<20>(this->_data); + DataType& table_3 = std::get<21>(this->_data); + DataType& table_4 = std::get<22>(this->_data); + DataType& lagrange_first = std::get<23>(this->_data); + DataType& lagrange_last = std::get<24>(this->_data); + + std::vector get_selectors() override + { + return { q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_sort, q_elliptic, q_aux, q_lookup }; + }; + std::vector get_sigma_polynomials() override { return { sigma_1, sigma_2, sigma_3, sigma_4 }; }; + std::vector get_id_polynomials() override { return { id_1, id_2, id_3, id_4 }; }; + + std::vector get_table_polynomials() { return { table_1, table_2, table_3, table_4 }; }; + }; + + /** + * @brief Container for all witness polynomials used/constructed by the prover. + * @details Shifts are not included here since they do not occupy their own memory. + */ + template + class WitnessEntities : public WitnessEntities_ { + public: + DataType& w_l = std::get<0>(this->_data); + DataType& w_r = std::get<1>(this->_data); + DataType& w_o = std::get<2>(this->_data); + DataType& w_4 = std::get<3>(this->_data); + DataType& sorted_1 = std::get<4>(this->_data); + DataType& sorted_2 = std::get<5>(this->_data); + DataType& sorted_3 = std::get<6>(this->_data); + DataType& sorted_4 = std::get<7>(this->_data); + DataType& sorted_accum = std::get<8>(this->_data); + DataType& z_perm = std::get<9>(this->_data); + DataType& z_lookup = std::get<10>(this->_data); + + std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; + // The sorted concatenations of table and witness data needed for plookup. + std::vector get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; }; + }; + + /** + * @brief A base class labelling all entities (for instance, all of the polynomials used by the prover during + * sumcheck) in this Honk variant along with particular subsets of interest + * @details Used to build containers for: the prover's polynomial during sumcheck; the sumcheck's folded + * polynomials; the univariates consturcted during during sumcheck; the evaluations produced by sumcheck. + * + * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be + * implemented as such, but we have this now. + */ + template + class AllEntities : public AllEntities_ { + public: + DataType& q_c = std::get<0>(this->_data); + DataType& q_l = std::get<1>(this->_data); + DataType& q_r = std::get<2>(this->_data); + DataType& q_o = std::get<3>(this->_data); + DataType& q_4 = std::get<4>(this->_data); + DataType& q_m = std::get<5>(this->_data); + DataType& q_arith = std::get<6>(this->_data); + DataType& q_sort = std::get<7>(this->_data); + DataType& q_elliptic = std::get<8>(this->_data); + DataType& q_aux = std::get<9>(this->_data); + DataType& q_lookup = std::get<10>(this->_data); + DataType& sigma_1 = std::get<11>(this->_data); + DataType& sigma_2 = std::get<12>(this->_data); + DataType& sigma_3 = std::get<13>(this->_data); + DataType& sigma_4 = std::get<14>(this->_data); + DataType& id_1 = std::get<15>(this->_data); + DataType& id_2 = std::get<16>(this->_data); + DataType& id_3 = std::get<17>(this->_data); + DataType& id_4 = std::get<18>(this->_data); + DataType& table_1 = std::get<19>(this->_data); + DataType& table_2 = std::get<20>(this->_data); + DataType& table_3 = std::get<21>(this->_data); + DataType& table_4 = std::get<22>(this->_data); + DataType& lagrange_first = std::get<23>(this->_data); + DataType& lagrange_last = std::get<24>(this->_data); + DataType& w_l = std::get<25>(this->_data); + DataType& w_r = std::get<26>(this->_data); + DataType& w_o = std::get<27>(this->_data); + DataType& w_4 = std::get<28>(this->_data); + DataType& sorted_accum = std::get<29>(this->_data); + DataType& z_perm = std::get<30>(this->_data); + DataType& z_lookup = std::get<31>(this->_data); + DataType& table_1_shift = std::get<32>(this->_data); + DataType& table_2_shift = std::get<33>(this->_data); + DataType& table_3_shift = std::get<34>(this->_data); + DataType& table_4_shift = std::get<35>(this->_data); + DataType& w_l_shift = std::get<36>(this->_data); + DataType& w_r_shift = std::get<37>(this->_data); + DataType& w_o_shift = std::get<38>(this->_data); + DataType& w_4_shift = std::get<39>(this->_data); + DataType& sorted_accum_shift = std::get<40>(this->_data); + DataType& z_perm_shift = std::get<41>(this->_data); + DataType& z_lookup_shift = std::get<42>(this->_data); + + std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; + // Gemini-specific getters. + std::vector get_unshifted() override + { + return { q_c, q_l, q_r, q_o, q_4, q_m, q_arith, q_sort, + q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1, + id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first, + lagrange_last, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup + + }; + }; + std::vector get_to_be_shifted() override + { + return { table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; + }; + std::vector get_shifted() override + { + return { table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift, + w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift }; + }; + + AllEntities() = default; + + AllEntities(const AllEntities& other) + : AllEntities_(other){}; + + AllEntities(AllEntities&& other) + : AllEntities_(other){}; + + AllEntities& operator=(const AllEntities& other) + { + if (this == &other) { + return *this; + } + AllEntities_::operator=(other); + return *this; + } + + AllEntities& operator=(AllEntities&& other) + { + AllEntities_::operator=(other); + return *this; + } + + ~AllEntities() = default; + }; + + public: + /** + * @brief The proving key is responsible for storing the polynomials used by the prover. + * @note TODO(Cody): Maybe multiple inheritance is the right thing here. In that case, nothing should eve inherit + * from ProvingKey. + */ + class ProvingKey : public ProvingKey_, + WitnessEntities> { + public: + // Expose constructors on the base class + using Base = ProvingKey_, + WitnessEntities>; + using Base::Base; + + std::vector memory_read_records; + std::vector memory_write_records; + + // The plookup wires that store plookup read data. + std::array get_table_column_wires() { return { w_l, w_r, w_o }; }; + }; + + /** + * @brief The verification key is responsible for storing the the commitments to the precomputed (non-witnessk) + * polynomials used by the verifier. + * + * @note Note the discrepancy with what sort of data is stored here vs in the proving key. We may want to resolve + * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our + * circuits. + */ + using VerificationKey = VerificationKey_>; + + /** + * @brief A container for polynomials handles; only stores spans. + */ + using ProverPolynomials = AllEntities; + + /** + * @brief A container for storing the partially evaluated multivariates produced by sumcheck. + */ + class PartiallyEvaluatedMultivariates : public AllEntities { + + public: + PartiallyEvaluatedMultivariates() = default; + PartiallyEvaluatedMultivariates(const size_t circuit_size) + { + // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) + for (auto& poly : this->_data) { + poly = Polynomial(circuit_size / 2); + } + } + }; + + /** + * @brief A container for univariates produced during the hot loop in sumcheck. + * @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? + */ + template + using ExtendedEdges = + AllEntities, sumcheck::Univariate>; + + /** + * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the + * evaluations of polynomials committed in earlier rounds. + */ + class ClaimedEvaluations : public AllEntities { + public: + using Base = AllEntities; + using Base::Base; + ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + }; + + /** + * @brief A container for commitment labels. + * @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly needed. It + * has, however, been useful during debugging to have these labels available. + * + */ + class CommitmentLabels : public AllEntities { + public: + CommitmentLabels() + { + w_l = "W_L"; + w_r = "W_R"; + w_o = "W_O"; + w_4 = "W_4"; + z_perm = "Z_PERM"; + z_lookup = "Z_LOOKUP"; + sorted_accum = "SORTED_ACCUM"; + + // The ones beginning with "__" are only used for debugging + q_c = "__Q_C"; + q_l = "__Q_L"; + q_r = "__Q_R"; + q_o = "__Q_O"; + q_4 = "__Q_4"; + q_m = "__Q_M"; + q_arith = "__Q_ARITH"; + q_sort = "__Q_SORT"; + q_elliptic = "__Q_ELLIPTIC"; + q_aux = "__Q_AUX"; + q_lookup = "__Q_LOOKUP"; + sigma_1 = "__SIGMA_1"; + sigma_2 = "__SIGMA_2"; + sigma_3 = "__SIGMA_3"; + sigma_4 = "__SIGMA_4"; + id_1 = "__ID_1"; + id_2 = "__ID_2"; + id_3 = "__ID_3"; + id_4 = "__ID_4"; + table_1 = "__TABLE_1"; + table_2 = "__TABLE_2"; + table_3 = "__TABLE_3"; + table_4 = "__TABLE_4"; + lagrange_first = "__LAGRANGE_FIRST"; + lagrange_last = "__LAGRANGE_LAST"; + }; + }; + + class VerifierCommitments : public AllEntities { + public: + VerifierCommitments(std::shared_ptr verification_key, VerifierTranscript transcript) + { + static_cast(transcript); + q_m = verification_key->q_m; + q_l = verification_key->q_l; + q_r = verification_key->q_r; + q_o = verification_key->q_o; + q_4 = verification_key->q_4; + q_c = verification_key->q_c; + q_arith = verification_key->q_arith; + q_sort = verification_key->q_sort; + q_elliptic = verification_key->q_elliptic; + q_aux = verification_key->q_aux; + q_lookup = verification_key->q_lookup; + sigma_1 = verification_key->sigma_1; + sigma_2 = verification_key->sigma_2; + sigma_3 = verification_key->sigma_3; + sigma_4 = verification_key->sigma_4; + id_1 = verification_key->id_1; + id_2 = verification_key->id_2; + id_3 = verification_key->id_3; + id_4 = verification_key->id_4; + table_1 = verification_key->table_1; + table_2 = verification_key->table_2; + table_3 = verification_key->table_3; + table_4 = verification_key->table_4; + lagrange_first = verification_key->lagrange_first; + lagrange_last = verification_key->lagrange_last; + } + }; +}; + +} // namespace proof_system::honk::flavor diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp index ba1a7e20e53..9407fe95f6f 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp @@ -3,7 +3,6 @@ #include "barretenberg/honk/sumcheck/sumcheck.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/honk/utils/power_polynomial.hpp" -#include "barretenberg/honk/flavor/standard.hpp" namespace proof_system::honk { @@ -284,5 +283,6 @@ template plonk::proof& StandardProver_::construc } template class StandardProver_; +template class StandardProver_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp index 8cda5365528..cf024c4c5a1 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp @@ -9,13 +9,12 @@ #include "barretenberg/honk/proof_system/prover_library.hpp" #include "barretenberg/honk/proof_system/work_queue.hpp" #include "barretenberg/honk/flavor/standard.hpp" +#include "barretenberg/honk/flavor/standard_grumpkin.hpp" namespace proof_system::honk { // We won't compile this class with honk::flavor::Ultra, but we will like want to compile it (at least for testing) // with a flavor that uses the curve Grumpkin, or a flavor that does/does not have zk, etc. -template concept StandardFlavor = IsAnyOf; - template class StandardProver_ { using FF = typename Flavor::FF; @@ -85,6 +84,7 @@ template class StandardProver_ { }; extern template class StandardProver_; +extern template class StandardProver_; using StandardProver = StandardProver_; // using GrumpkinStandardProver = StandardProver_; // e.g. diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.cpp index 3a5cff0db33..81cfadf4a67 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.cpp @@ -1,6 +1,8 @@ #include "prover_library.hpp" #include "barretenberg/honk/flavor/standard.hpp" +#include "barretenberg/honk/flavor/standard_grumpkin.hpp" #include "barretenberg/honk/flavor/ultra.hpp" +#include "barretenberg/honk/flavor/ultra_grumpkin.hpp" #include #include @@ -397,6 +399,11 @@ void add_plookup_memory_records_to_wire_4(std::shared_ptr( std::shared_ptr&, honk::flavor::Standard::FF, honk::flavor::Standard::FF); +template honk::flavor::StandardGrumpkin::Polynomial compute_permutation_grand_product( + std::shared_ptr&, + honk::flavor::StandardGrumpkin::FF, + honk::flavor::StandardGrumpkin::FF); + template honk::flavor::Ultra::Polynomial compute_permutation_grand_product( std::shared_ptr&, honk::flavor::Ultra::FF, honk::flavor::Ultra::FF); @@ -412,4 +419,23 @@ template typename honk::flavor::Ultra::Polynomial compute_sorted_list_accumulato template void add_plookup_memory_records_to_wire_4( std::shared_ptr& key, typename honk::flavor::Ultra::FF eta); +template honk::flavor::UltraGrumpkin::Polynomial compute_permutation_grand_product( + std::shared_ptr&, + honk::flavor::UltraGrumpkin::FF, + honk::flavor::UltraGrumpkin::FF); + +template typename honk::flavor::UltraGrumpkin::Polynomial compute_lookup_grand_product( + std::shared_ptr& key, + typename honk::flavor::UltraGrumpkin::FF eta, + typename honk::flavor::UltraGrumpkin::FF beta, + typename honk::flavor::UltraGrumpkin::FF gamma); + +template typename honk::flavor::UltraGrumpkin::Polynomial compute_sorted_list_accumulator( + std::shared_ptr& key, + typename honk::flavor::UltraGrumpkin::FF eta); + +template void add_plookup_memory_records_to_wire_4( + std::shared_ptr& key, + typename honk::flavor::UltraGrumpkin::FF eta); + } // namespace proof_system::honk::prover_library diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp index 89423a3c781..ba61525755a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -338,5 +338,6 @@ template plonk::proof& UltraProver_::construct_proo } template class UltraProver_; +template class UltraProver_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp index 245d023dae9..070d5e3df1c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp @@ -5,6 +5,7 @@ #include "barretenberg/honk/pcs/shplonk/shplonk_single.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/honk/flavor/ultra.hpp" +#include "barretenberg/honk/flavor/ultra_grumpkin.hpp" #include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" @@ -12,7 +13,6 @@ namespace proof_system::honk { // We won't compile this class with honk::flavor::Standard, but we will like want to compile it (at least for testing) // with a flavor that uses the curve Grumpkin, or a flavor that does/does not have zk, etc. -template concept UltraFlavor = IsAnyOf; template class UltraProver_ { using FF = typename Flavor::FF; @@ -79,6 +79,7 @@ template class UltraProver_ { }; extern template class UltraProver_; +extern template class UltraProver_; using UltraProver = UltraProver_; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp index f2cc8f8efa4..4b70607dd36 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp @@ -158,5 +158,6 @@ template bool UltraVerifier_::verify_proof(const plonk } template class UltraVerifier_; +template class UltraVerifier_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp index a5456f5a0de..00a3736a99c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp @@ -1,6 +1,6 @@ #pragma once -// #include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/flavor/ultra.hpp" +#include "barretenberg/honk/flavor/ultra_grumpkin.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/honk/sumcheck/sumcheck.hpp" @@ -28,6 +28,7 @@ template class UltraVerifier_ { }; extern template class UltraVerifier_; +extern template class UltraVerifier_; using UltraVerifier = UltraVerifier_; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp index 4934d9ec136..a03b9060e9c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp @@ -1,7 +1,6 @@ #include "./verifier.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/utils/power_polynomial.hpp" using namespace barretenberg; @@ -168,5 +167,6 @@ template bool StandardVerifier_::verify_proof(const pl } template class StandardVerifier_; +template class StandardVerifier_; } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp index 7034adf3d62..bbf7228aa93 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp @@ -2,6 +2,7 @@ #include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/honk/sumcheck/sumcheck.hpp" +#include "barretenberg/honk/flavor/standard_grumpkin.hpp" namespace proof_system::honk { template class StandardVerifier_ { @@ -27,6 +28,7 @@ template class StandardVerifier_ { }; extern template class StandardVerifier_; +extern template class StandardVerifier_; using StandardVerifier = StandardVerifier_; diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp index fca6b7a4e27..e0718b33942 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp @@ -161,8 +161,8 @@ TEST_F(SumcheckTests, PolynomialNormalization) * sumcheck.multivariates.folded_polynoimals[i][0] is the evaluatioin of the i'th multivariate at the vector of challenges u_i. What does this mean? - Here we show that if the multivariate is F(X0, X1, X2) defined as above, then what we get is F(u0, u1, u2) and not, - say F(u2, u1, u0). This is in accordance with Adrian's thesis (cf page 9). + Here we show that if the multivariate is F(X0, X1, X2) defined as above, then what we get is F(u0, u1, u2) and + not, say F(u2, u1, u0). This is in accordance with Adrian's thesis (cf page 9). */ // Get the values of the Lagrange basis polys L_i defined diff --git a/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp index 8b3c36e76a4..1e0ae9f38ca 100644 --- a/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp @@ -5,6 +5,7 @@ #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/honk/flavor/standard.hpp" +#include "barretenberg/proof_system/flavor/flavor.hpp" #include #include #include @@ -12,15 +13,18 @@ using namespace proof_system::honk; -template class TranscriptTests : public testing::Test { +template class TranscriptTests : public testing::Test { public: + using FF = typename Flavor::FF; static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); } /** * @brief Construct a manifest for a standard Honk proof * - * @details This is where we define the "Manifest" for a Standard Honk proof. The tests in this suite are intented - * to warn the developer if the Prover/Verifier has deviated from this manifest, however, the Transcript class is + * @details This is where we define the "Manifest" for a Standard Honk proof. The tests in this suite are + intented + * to warn the developer if the Prover/Verifier has deviated from this manifest, however, the Transcript class + is * not otherwise contrained to follow the manifest. * * @return TranscriptManifest @@ -35,7 +39,7 @@ template class TranscriptTests : public testing::Test { size_t size_FF = sizeof(FF); size_t size_G = 2 * size_FF; size_t size_uni = max_relation_length * size_FF; - size_t size_evals = flavor::Standard::NUM_ALL_ENTITIES * size_FF; + size_t size_evals = (Flavor::NUM_ALL_ENTITIES)*size_FF; size_t round = 0; manifest_expected.add_entry(round, "circuit_size", 4); @@ -82,23 +86,24 @@ template class TranscriptTests : public testing::Test { round++; // TODO(Mara): Make testing more flavor agnostic so we can test this with all flavors - manifest_expected.add_entry(round, "KZG:W", size_G); + if constexpr (IsGrumpkinFlavor) { + manifest_expected.add_entry(round, "IPA:poly_degree", circuit_size); + manifest_expected.add_challenge(round, "IPA:generator_challenge"); + + for (size_t i = 0; i < log_n; i++) { + round++; + std::string idx = std::to_string(i); + manifest_expected.add_entry(round, "IPA:L_" + idx, size_G); + manifest_expected.add_entry(round, "IPA:R_" + idx, size_G); + std::string label = "IPA:round_challenge_" + idx; + manifest_expected.add_challenge(round, label); + } - // For IPA - // manifest_expected.add_entry(round, "IPA:poly_degree", circuit_size); - // manifest_expected.add_challenge(round, "IPA:generator_challenge"); - - // for (size_t i = 0; i < log_n; i++) { - // round++; - // std::string idx = std::to_string(i); - // manifest_expected.add_entry(round, "IPA:L_" + idx, size_G); - // manifest_expected.add_entry(round, "IPA:R_" + idx, size_G); - // std::string label = "IPA:round_challenge_" + idx; - // manifest_expected.add_challenge(round, label); - // } - - // round++; - // manifest_expected.add_entry(round, "IPA:a_0", size_FF); + round++; + manifest_expected.add_entry(round, "IPA:a_0", size_FF); + } else { + manifest_expected.add_entry(round, "KZG:W", size_G); + } manifest_expected.add_challenge(round); // no challenge @@ -106,8 +111,8 @@ template class TranscriptTests : public testing::Test { } }; -using FieldTypes = testing::Types; -TYPED_TEST_SUITE(TranscriptTests, FieldTypes); +using StandardFlavorTypes = testing::Types; +TYPED_TEST_SUITE(TranscriptTests, StandardFlavorTypes); /** * @brief Ensure consistency between the manifest hard coded in this testing suite and the one generated by the @@ -115,8 +120,9 @@ TYPED_TEST_SUITE(TranscriptTests, FieldTypes); */ TYPED_TEST(TranscriptTests, ProverManifestConsistency) { + using Flavor = TypeParam; // Construct a simple circuit of size n = 8 (i.e. the minimum circuit size) - auto composer = StandardHonkComposer(); + auto composer = StandardHonkComposer_(); fr a = 1; composer.circuit_constructor.add_variable(a); composer.circuit_constructor.add_public_variable(a); @@ -141,8 +147,9 @@ TYPED_TEST(TranscriptTests, ProverManifestConsistency) */ TYPED_TEST(TranscriptTests, VerifierManifestConsistency) { + using Flavor = TypeParam; // Construct a simple circuit of size n = 8 (i.e. the minimum circuit size) - auto composer = StandardHonkComposer(); + auto composer = StandardHonkComposer_(); fr a = 1; composer.circuit_constructor.add_variable(a); composer.circuit_constructor.add_public_variable(a); @@ -274,6 +281,7 @@ TYPED_TEST(TranscriptTests, VerifierMistake) * construction and the one generated by the verifier over the course of proof verification. * */ +// TODO(Mara): This is not a typed test and we should have a construct_ultra_honk_manifest as well. TYPED_TEST(TranscriptTests, UltraVerifierManifestConsistency) { // Construct a simple circuit of size n = 8 (i.e. the minimum circuit size) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index c786f2abae4..d0b5d022d8c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -291,7 +291,9 @@ static constexpr auto create_barycentric_utils() // Forward declare honk flavors namespace proof_system::honk::flavor { class Standard; +class StandardGrumpkin; class Ultra; +class UltraGrumpkin; } // namespace proof_system::honk::flavor // Forward declare plonk flavors @@ -316,7 +318,14 @@ concept IsAnyOf = (std::same_as || ...); template concept IsPlonkFlavor = IsAnyOf; -template -concept IsHonkFlavor = IsAnyOf; +template +concept IsHonkFlavor = IsAnyOf; + +template concept IsGrumpkinFlavor = IsAnyOf; + +template concept StandardFlavor = IsAnyOf; + +template concept UltraFlavor = IsAnyOf; + // clang-format on } // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp index 64b80d6071b..6ea96484aaa 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp @@ -3,8 +3,7 @@ #include #include -#include "../../primitives/composers/composers_fwd.hpp" - +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/witness/witness.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp index 53f47c79a33..6563fd8a9c3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp @@ -1,5 +1,5 @@ #include "aes128.hpp" - +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/crypto/aes128/aes128.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp index 20d1c32aba3..0208b75595c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp @@ -4,7 +4,6 @@ #include "../../primitives/byte_array/byte_array.hpp" #include "../../primitives/uint/uint.hpp" #include "../../primitives/composers/composers_fwd.hpp" - namespace proof_system::plonk { namespace stdlib { namespace ecdsa { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp index a28b7817a3d..097eab81a36 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp @@ -2,6 +2,8 @@ #include "../../hash/sha256/sha256.hpp" #include "../../primitives/bit_array/bit_array.hpp" +#include "../../primitives/composers/composers.hpp" + namespace proof_system::plonk { namespace stdlib { namespace ecdsa { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp index 4ab080c5429..f056a21c834 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp @@ -1,10 +1,6 @@ #pragma once #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" - -namespace proof_system::plonk { -class TurboPlonkComposer; -class UltraPlonkComposer; -} // namespace proof_system::plonk +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp index 96920f127cc..d5bd02f5d2e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp @@ -1,10 +1,6 @@ #pragma once #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" - -namespace proof_system::plonk { -class TurboPlonkComposer; -class UltraPlonkComposer; -} // namespace proof_system::plonk +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp index 70d6c6941ee..6e951187c73 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp @@ -3,6 +3,7 @@ #include "barretenberg/crypto/blake3s/blake3s.hpp" #include "barretenberg/common/streams.hpp" #include +#include "barretenberg/stdlib/primitives/composers/composers.hpp" using namespace barretenberg; using namespace proof_system::plonk; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp index 10670df7d98..e123dc723a6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp @@ -3,15 +3,9 @@ #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" - +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" #include "sha256_plookup.hpp" - -namespace proof_system::plonk { -class UltraPlonkComposer; -class StandardPlonkComposer; -class TurboPlonkComposer; -class UltraHonkComposer; -} // namespace proof_system::plonk +// namespace proof_system::plonk namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp index 6296aff8210..9fb1261eb99 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp @@ -1,9 +1,7 @@ #include "sha256.hpp" #include "barretenberg/common/test.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" #include "barretenberg/numeric/random/engine.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp index 06472cdcb37..447ca209a4d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp @@ -4,14 +4,11 @@ #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/numeric/bitop/sparse_form.hpp" +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" -namespace proof_system::plonk { -class UltraPlonkComposer; -} // namespace proof_system::plonk - namespace proof_system::plonk { namespace stdlib { namespace sha256_plookup { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp index 58e5b5b4b87..567edcd7a5f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp @@ -9,10 +9,7 @@ #include "../byte_array/byte_array.hpp" #include "../field/field.hpp" #include "./bigfield.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/honk/composer/ultra_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" - +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/plonk/proof_system/verifier/verifier.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp index 7e42b5c4bbe..c44f550ab78 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp @@ -12,8 +12,6 @@ #include "barretenberg/ecc/curves/secp256r1/secp256r1.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "../composers/composers_fwd.hpp" - namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp index 037f8e1f8ad..9176076a56f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -5,8 +5,7 @@ #include "../biggroup/biggroup.hpp" #include "../bool/bool.hpp" #include "../field/field.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/honk/composer/ultra_honk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/primitives/curves/secp256r1.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp index 2183dceebbb..a3e6846b9b2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp @@ -1,7 +1,6 @@ #pragma once #include "../composers/composers_fwd.hpp" #include "../uint/uint.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" #include namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp index c015391199d..29ca9133d2a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp @@ -1,7 +1,7 @@ #include "bit_array.hpp" #include #include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp index 6d3e1e8d1a2..30e83c42a7b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp @@ -1,6 +1,5 @@ #include "bool.hpp" #include "../composers/composers.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" using namespace barretenberg; using namespace proof_system; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp index 814a8f83ea9..37cde2d4652 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp @@ -1,7 +1,6 @@ #include "bool.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" #include -#include "barretenberg/honk/composer/standard_honk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.cpp" #define STDLIB_TYPE_ALIASES \ diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp index 7cecc12a4a0..6ab1223240b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp @@ -1,3 +1,10 @@ +/** + * @brief Contains all the headers required to adequately compile the types defined in composers_fwd.hpp and instantiate + * templates. + * + * @details This should be the ONLY file related to composer/circuit construct included in source files not part of the + * proof systems. + */ #pragma once #include "barretenberg/plonk/composer/standard_plonk_composer.hpp" #include "barretenberg/honk/composer/standard_honk_composer.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp index 75b9a7e2e24..3d5570a276e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp @@ -1,3 +1,11 @@ +/** + * @brief Defines particular composer and circuit constructor types expected to be used for proof or circuit +construction (outside the proof_system and honk folder) and contains macros for explicit instantiation. + * + * @details This file is designed to be included in header files to instruct the compiler that these classes exist and + * their instantiation will eventually take place. Given it has no dependencies, it causes no additional compilation or + * propagation. This should be the ONLY file related to these types included in files out side the proof system. + */ #pragma once namespace proof_system::plonk { @@ -5,13 +13,19 @@ class StandardPlonkComposer; class TurboPlonkComposer; class UltraPlonkComposer; -class StandardPlonkComposer; } // namespace proof_system::plonk namespace proof_system::honk { -class StandardHonkComposer; -class UltraHonkComposer; +namespace flavor { +class Standard; +class Ultra; +} // namespace flavor +template class StandardHonkComposer_; +using StandardHonkComposer = StandardHonkComposer_; +template class UltraHonkComposer_; +using UltraHonkComposer = UltraHonkComposer_; } // namespace proof_system::honk + namespace proof_system { class StandardCircuitConstructor; class TurboCircuitConstructor; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp index 518fcbcb474..2543e5d16c9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp @@ -3,10 +3,7 @@ #include "array.hpp" #include #include -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/numeric/random/engine.hpp" namespace test_stdlib_array { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp index d1e89ca7ed0..2e78f7856f6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp @@ -2,8 +2,6 @@ #include #include "../composers/composers_fwd.hpp" #include "../witness/witness.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" #include "barretenberg/common/assert.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp index 83347eab598..2bbe6bb7ff4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp @@ -4,12 +4,9 @@ #include "barretenberg/plonk/proof_system/constants.hpp" #include #include -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/common/streams.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" using namespace proof_system; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp index b8bb2e7a936..d8a3e0ca903 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp @@ -1,5 +1,4 @@ #include "logic.hpp" - #include "../composers/composers.hpp" #include "../plookup/plookup.hpp" #include "barretenberg/common/assert.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp index 5f78ddcaab9..d29b29b9459 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp @@ -2,6 +2,7 @@ #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/proof_system/types/composer_type.hpp" #include "logic.hpp" +#include "../composers/composers.hpp" #include #include "barretenberg/numeric/random/engine.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp index 0f274fe4d77..b3435522bf0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp @@ -1,6 +1,6 @@ #pragma once #include "ram_table.hpp" - +#include "../composers/composers_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp index 6f2488a3ad1..44beaa9b719 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp @@ -5,6 +5,7 @@ #include "barretenberg/numeric/random/engine.hpp" #include "../bool/bool.hpp" +#include "../composers/composers.hpp" namespace test_stdlib_dynamic_array { using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp index 3147bedc652..a8e452f02b8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp @@ -3,7 +3,6 @@ #include "../field/field.hpp" #include "../bool/bool.hpp" #include "../byte_array/byte_array.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp index f6ba2999fb3..5c16d0b59d1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp @@ -3,10 +3,7 @@ #include "packed_byte_array.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp index 0857224ef39..778f76b7ac1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp @@ -2,7 +2,7 @@ #include #include #include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" #include "barretenberg/proof_system/plookup_tables/types.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp index ffad6bd0676..f564c80b7a4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp @@ -8,6 +8,7 @@ #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/curves/secp256k1.hpp" +#include "barretenberg/stdlib/primitives/composers/composers.hpp" namespace test_stdlib_plookups { using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp index 4148565d4d8..213eee5c963 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp @@ -1,11 +1,11 @@ #pragma once #include #include "../composers/composers_fwd.hpp" +#include "../composers/composers.hpp" #include "../witness/witness.hpp" #include "../bool/bool.hpp" #include "barretenberg/common/assert.hpp" #include "../field/field.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" // The purpose of this class is to enable positive integer operations without a risk of overflow. // Despite the name, it is *not* a "safe" version of the uint class - as operations are positive integer diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp index 779b30a23bf..39662dd8c53 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp @@ -1,5 +1,4 @@ #include "../composers/composers.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp index 7ba8328f8e4..7658a010dfa 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp @@ -7,12 +7,6 @@ #include "./plookup/uint.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/honk/composer/ultra_honk_composer.hpp" - namespace proof_system::plonk { namespace stdlib {