From c018767ce6594b13c64b45c8711e422ce15fc5ee Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 2 Sep 2024 11:39:36 +0000 Subject: [PATCH] chore(avm): move proving key to avm files --- .../cpp/src/barretenberg/flavor/flavor.hpp | 46 ------------------- .../vm/avm/generated/composer.cpp | 2 - .../barretenberg/vm/avm/generated/flavor.cpp | 19 ++++++++ .../barretenberg/vm/avm/generated/flavor.hpp | 34 +++++++++++--- .../bb-pil-backend/templates/composer.cpp.hbs | 2 - .../bb-pil-backend/templates/flavor.cpp.hbs | 19 ++++++++ .../bb-pil-backend/templates/flavor.hpp.hbs | 35 +++++++++++--- 7 files changed, 94 insertions(+), 63 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 418e89d0de7..91a8ef652d4 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -141,52 +141,6 @@ template class ProvingKey_ { this->num_public_inputs = num_public_inputs; }; }; -template -class ProvingKeyAvm_ : public PrecomputedPolynomials, public WitnessPolynomials { - public: - using Polynomial = typename PrecomputedPolynomials::DataType; - using FF = typename Polynomial::FF; - - size_t circuit_size; - bool contains_recursive_proof; - AggregationObjectPubInputIndices recursive_proof_public_input_indices; - bb::EvaluationDomain evaluation_domain; - std::shared_ptr commitment_key; - - // Offset off the public inputs from the start of the execution trace - size_t pub_inputs_offset = 0; - - // The number of public inputs has to be the same for all instances because they are - // folded element by element. - std::vector public_inputs; - - std::vector get_labels() const - { - return concatenate(PrecomputedPolynomials::get_labels(), WitnessPolynomials::get_labels()); - } - // This order matters! must match get_unshifted in entity classes - auto get_all() { return concatenate(get_precomputed_polynomials(), get_witness_polynomials()); } - auto get_witness_polynomials() { return WitnessPolynomials::get_all(); } - auto get_precomputed_polynomials() { return PrecomputedPolynomials::get_all(); } - auto get_selectors() { return PrecomputedPolynomials::get_selectors(); } - ProvingKeyAvm_() = default; - ProvingKeyAvm_(const size_t circuit_size, const size_t num_public_inputs) - { - this->commitment_key = std::make_shared(circuit_size + 1); - this->evaluation_domain = bb::EvaluationDomain(circuit_size, circuit_size); - this->circuit_size = circuit_size; - this->log_circuit_size = numeric::get_msb(circuit_size); - this->num_public_inputs = num_public_inputs; - // Allocate memory for precomputed polynomials - for (auto& poly : PrecomputedPolynomials::get_all()) { - poly = Polynomial(circuit_size); - } - // Allocate memory for witness polynomials - for (auto& poly : WitnessPolynomials::get_all()) { - poly = Polynomial(circuit_size); - } - }; -}; /** * @brief Base verification key class. diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/composer.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/composer.cpp index baaebcea2f7..613a96aa9f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/composer.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/composer.cpp @@ -54,8 +54,6 @@ std::shared_ptr AvmComposer::compute_proving_key(CircuitCons proving_key = std::make_shared(subgroup_size, 0); } - proving_key->contains_recursive_proof = false; - return proving_key; } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index d6e3b0c7cab..fca4ae3c126 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -2264,4 +2264,23 @@ AvmFlavor::PartiallyEvaluatedMultivariates::PartiallyEvaluatedMultivariates(cons } } +AvmFlavor::ProvingKey::ProvingKey(const size_t circuit_size, const size_t num_public_inputs) + : circuit_size(circuit_size) + , evaluation_domain(bb::EvaluationDomain(circuit_size, circuit_size)) + , commitment_key(std::make_shared(circuit_size + 1)) +{ + // TODO: These come from PrecomputedEntitiesBase, ideal we'd just call that class's constructor. + this->log_circuit_size = numeric::get_msb(circuit_size); + this->num_public_inputs = num_public_inputs; + + // Allocate memory for precomputed polynomials + for (auto& poly : PrecomputedEntities::get_all()) { + poly = Polynomial(circuit_size); + } + // Allocate memory for witness polynomials + for (auto& poly : WitnessEntities::get_all()) { + poly = Polynomial(circuit_size); + } +}; + } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index 338a49da101..963e592b3df 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -282,13 +282,35 @@ class AvmFlavor { auto get_precomputed() { return PrecomputedEntities::get_all(); } }; - class ProvingKey - : public ProvingKeyAvm_, WitnessEntities, CommitmentKey> { + class ProvingKey : public PrecomputedEntities, public WitnessEntities { public: - // Expose constructors on the base class - using Base = ProvingKeyAvm_, WitnessEntities, CommitmentKey>; - using Base::Base; - auto get_to_be_shifted() { return AvmFlavor::get_to_be_shifted(*this); } + using FF = typename Polynomial::FF; + + ProvingKey() = default; + ProvingKey(const size_t circuit_size, const size_t num_public_inputs); + + size_t circuit_size; + bb::EvaluationDomain evaluation_domain; + std::shared_ptr commitment_key; + + // Offset off the public inputs from the start of the execution trace + size_t pub_inputs_offset = 0; + + // The number of public inputs has to be the same for all instances because they are + // folded element by element. + std::vector public_inputs; + + std::vector get_labels() const + { + return concatenate(PrecomputedEntities::get_labels(), + WitnessEntities::get_labels()); + } + auto get_witness_polynomials() { return WitnessEntities::get_all(); } + auto get_precomputed_polynomials() { return PrecomputedEntities::get_all(); } + auto get_selectors() { return PrecomputedEntities::get_all(); } + auto get_to_be_shifted() { return AvmFlavor::get_to_be_shifted(*this); } + // This order matters! must match get_unshifted in entity classes + auto get_all() { return concatenate(get_precomputed_polynomials(), get_witness_polynomials()); } }; class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { diff --git a/bb-pilcom/bb-pil-backend/templates/composer.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/composer.cpp.hbs index f4776a7121e..707d4a0bfd1 100644 --- a/bb-pilcom/bb-pil-backend/templates/composer.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/composer.cpp.hbs @@ -54,8 +54,6 @@ std::shared_ptr {{name}}Composer::compute_proving_key(Circui proving_key = std::make_shared(subgroup_size, 0); } - proving_key->contains_recursive_proof = false; - return proving_key; } diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.cpp.hbs index e577691c715..f4ca977fe54 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.cpp.hbs @@ -100,4 +100,23 @@ void {{name}}Flavor::Transcript::serialize_full_transcript() { } } +AvmFlavor::ProvingKey::ProvingKey(const size_t circuit_size, const size_t num_public_inputs) + : circuit_size(circuit_size) + , evaluation_domain(bb::EvaluationDomain(circuit_size, circuit_size)) + , commitment_key(std::make_shared(circuit_size + 1)) +{ + // TODO: These come from PrecomputedEntitiesBase, ideal we'd just call that class's constructor. + this->log_circuit_size = numeric::get_msb(circuit_size); + this->num_public_inputs = num_public_inputs; + + // Allocate memory for precomputed polynomials + for (auto& poly : PrecomputedEntities::get_all()) { + poly = Polynomial(circuit_size); + } + // Allocate memory for witness polynomials + for (auto& poly : WitnessEntities::get_all()) { + poly = Polynomial(circuit_size); + } +}; + } // namespace bb \ No newline at end of file diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs index 3313db0fedb..3aafbf028d5 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs @@ -162,14 +162,35 @@ class {{name}}Flavor { auto get_precomputed() { return PrecomputedEntities::get_all(); } }; - class ProvingKey : public ProvingKeyAvm_, WitnessEntities, CommitmentKey> { + class ProvingKey : public PrecomputedEntities, public WitnessEntities { public: - // Expose constructors on the base class - using Base = ProvingKeyAvm_, WitnessEntities, CommitmentKey>; - using Base::Base; - auto get_to_be_shifted() { - return {{name}}Flavor::get_to_be_shifted(*this); - } + using FF = typename Polynomial::FF; + + ProvingKey() = default; + ProvingKey(const size_t circuit_size, const size_t num_public_inputs); + + size_t circuit_size; + bb::EvaluationDomain evaluation_domain; + std::shared_ptr commitment_key; + + // Offset off the public inputs from the start of the execution trace + size_t pub_inputs_offset = 0; + + // The number of public inputs has to be the same for all instances because they are + // folded element by element. + std::vector public_inputs; + + std::vector get_labels() const + { + return concatenate(PrecomputedEntities::get_labels(), + WitnessEntities::get_labels()); + } + auto get_witness_polynomials() { return WitnessEntities::get_all(); } + auto get_precomputed_polynomials() { return PrecomputedEntities::get_all(); } + auto get_selectors() { return PrecomputedEntities::get_all(); } + auto get_to_be_shifted() { return AvmFlavor::get_to_be_shifted(*this); } + // This order matters! must match get_unshifted in entity classes + auto get_all() { return concatenate(get_precomputed_polynomials(), get_witness_polynomials()); } }; class VerificationKey : public VerificationKey_, VerifierCommitmentKey> {