diff --git a/barretenberg/cpp/pil/fib/fibonacci.pil b/barretenberg/cpp/pil/fib/fibonacci.pil deleted file mode 100644 index 993a675e7d2..00000000000 --- a/barretenberg/cpp/pil/fib/fibonacci.pil +++ /dev/null @@ -1,18 +0,0 @@ -constant %N = 16; - -// This uses the alternative nomenclature as well. - -namespace Fibonacci(%N); - col fixed LAST(i) { match i { - %N - 1 => 1, - _ => 0, - } }; - col fixed FIRST(i) { match i { - 0 => 1, - _ => 0, - } }; - col witness x, y; - - (1-FIRST) * (1-LAST) * (x' - y) = 0; - (1-FIRST) * (1-LAST) * (y' - (x + y)) = 0; - diff --git a/barretenberg/cpp/pil/fib/fibonacci_opt.pil b/barretenberg/cpp/pil/fib/fibonacci_opt.pil deleted file mode 100644 index 2c36cd15327..00000000000 --- a/barretenberg/cpp/pil/fib/fibonacci_opt.pil +++ /dev/null @@ -1,8 +0,0 @@ -constant %N = 16; -namespace Fibonacci(16); - col fixed LAST(i) { match i { (%N - 1) => 1, _ => 0, } }; - col fixed FIRST(i) { match i { 0 => 1, _ => 0, } }; - col witness x; - col witness y; - (((1 - Fibonacci.FIRST) * (1 - Fibonacci.LAST)) * (Fibonacci.x' - Fibonacci.y)) = 0; - (((1 - Fibonacci.FIRST) * (1 - Fibonacci.LAST)) * (Fibonacci.y' - (Fibonacci.x + Fibonacci.y))) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp deleted file mode 100644 index 9572fedd3ff..00000000000 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp +++ /dev/null @@ -1,296 +0,0 @@ - - -#pragma once -#include "../relation_definitions_fwd.hpp" -#include "barretenberg/commitment_schemes/kzg/kzg.hpp" -#include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" - -#include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/flavor/flavor_macros.hpp" -#include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/relations/generated/Fib.hpp" -#include "barretenberg/transcript/transcript.hpp" - -namespace proof_system::honk { -namespace flavor { - -class FibFlavor { - public: - using Curve = curve::BN254; - using G1 = Curve::Group; - using PCS = pcs::kzg::KZG; - - using FF = G1::subgroup_field; - using Polynomial = barretenberg::Polynomial; - using PolynomialHandle = std::span; - using GroupElement = G1::element; - using Commitment = G1::affine_element; - using CommitmentHandle = G1::affine_element; - using CommitmentKey = pcs::CommitmentKey; - using VerifierCommitmentKey = pcs::VerifierCommitmentKey; - - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 2; - static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; - // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for - // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 6; - - using Relations = std::tuple>; - - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); - - // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` - // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation - // length = 3 - static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; - static constexpr size_t NUM_RELATIONS = std::tuple_size::value; - - template - using ProtogalaxyTupleOfTuplesOfUnivariates = - decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); - using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); - - static constexpr bool has_zero_row = true; - - private: - template class PrecomputedEntities : public PrecomputedEntitiesBase { - public: - using DataType = DataType_; - DEFINE_FLAVOR_MEMBERS(DataType, Fibonacci_LAST, Fibonacci_FIRST) - - RefVector get_selectors() - { - return { - Fibonacci_LAST, - Fibonacci_FIRST, - }; - }; - - RefVector get_sigma_polynomials() { return {}; }; - RefVector get_id_polynomials() { return {}; }; - RefVector get_table_polynomials() { return {}; }; - }; - - template class WitnessEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, Fibonacci_x, Fibonacci_y) - - RefVector get_wires() - { - return { - Fibonacci_x, - Fibonacci_y, - - }; - }; - - RefVector get_sorted_polynomials() { return {}; }; - }; - - template class AllEntities { - public: - DEFINE_FLAVOR_MEMBERS( - DataType, Fibonacci_LAST, Fibonacci_FIRST, Fibonacci_x, Fibonacci_y, Fibonacci_x_shift, Fibonacci_y_shift) - - RefVector get_wires() - { - return { - Fibonacci_LAST, Fibonacci_FIRST, Fibonacci_x, Fibonacci_y, Fibonacci_x_shift, Fibonacci_y_shift, - - }; - }; - - RefVector get_unshifted() - { - return { - Fibonacci_LAST, - Fibonacci_FIRST, - Fibonacci_x, - Fibonacci_y, - - }; - }; - - RefVector get_to_be_shifted() - { - return { - Fibonacci_x, - Fibonacci_y, - - }; - }; - - RefVector get_shifted() - { - return { - Fibonacci_x_shift, - Fibonacci_y_shift, - - }; - }; - }; - - public: - class ProvingKey : public ProvingKey_, WitnessEntities> { - public: - // Expose constructors on the base class - using Base = ProvingKey_, WitnessEntities>; - using Base::Base; - - // The plookup wires that store plookup read data. - std::array get_table_column_wires() { return {}; }; - }; - - using VerificationKey = VerificationKey_>; - - using ProverPolynomials = AllEntities; - - using FoldedPolynomials = AllEntities>; - - class AllValues : public AllEntities { - public: - using Base = AllEntities; - using Base::Base; - }; - - class AllPolynomials : public AllEntities { - public: - [[nodiscard]] size_t get_polynomial_size() const { return this->Fibonacci_LAST.size(); } - [[nodiscard]] AllValues get_row(const size_t row_idx) const - { - AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) { - result_field = polynomial[row_idx]; - } - return result; - } - }; - - using RowPolynomials = AllEntities; - - 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 : get_all()) { - poly = Polynomial(circuit_size / 2); - } - } - }; - - /** - * @brief A container for univariates used during Protogalaxy folding and sumcheck. - * @details During folding and sumcheck, the prover evaluates the relations on these univariates. - */ - template using ProverUnivariates = AllEntities>; - - /** - * @brief A container for univariates produced during the hot loop in sumcheck. - */ - using ExtendedEdges = ProverUnivariates; - - class CommitmentLabels : public AllEntities { - private: - using Base = AllEntities; - - public: - CommitmentLabels() - : AllEntities() - { - Base::Fibonacci_LAST = "Fibonacci_LAST"; - Base::Fibonacci_FIRST = "Fibonacci_FIRST"; - Base::Fibonacci_x = "Fibonacci_x"; - Base::Fibonacci_y = "Fibonacci_y"; - }; - }; - - class VerifierCommitments : public AllEntities { - private: - using Base = AllEntities; - - public: - VerifierCommitments(const std::shared_ptr& verification_key) - { - Fibonacci_LAST = verification_key->Fibonacci_LAST; - Fibonacci_FIRST = verification_key->Fibonacci_FIRST; - } - }; - - class Transcript : public BaseTranscript { - public: - uint32_t circuit_size; - - Commitment Fibonacci_x; - Commitment Fibonacci_y; - - std::vector> sumcheck_univariates; - std::array sumcheck_evaluations; - std::vector zm_cq_comms; - Commitment zm_cq_comm; - Commitment zm_pi_comm; - - Transcript() = default; - - Transcript(const std::vector& proof) - : BaseTranscript(proof) - {} - - void deserialize_full_transcript() - { - size_t num_bytes_read = 0; - circuit_size = deserialize_from_buffer(proof_data, num_bytes_read); - size_t log_n = numeric::get_msb(circuit_size); - - Fibonacci_x = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - Fibonacci_y = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - - for (size_t i = 0; i < log_n; ++i) { - sumcheck_univariates.emplace_back( - deserialize_from_buffer>( - BaseTranscript::proof_data, num_bytes_read)); - } - sumcheck_evaluations = - deserialize_from_buffer>(BaseTranscript::proof_data, num_bytes_read); - for (size_t i = 0; i < log_n; ++i) { - zm_cq_comms.push_back(deserialize_from_buffer(proof_data, num_bytes_read)); - } - zm_cq_comm = deserialize_from_buffer(proof_data, num_bytes_read); - zm_pi_comm = deserialize_from_buffer(proof_data, num_bytes_read); - } - - void serialize_full_transcript() - { - size_t old_proof_length = proof_data.size(); - BaseTranscript::proof_data.clear(); - size_t log_n = numeric::get_msb(circuit_size); - - serialize_to_buffer(circuit_size, BaseTranscript::proof_data); - - serialize_to_buffer(Fibonacci_x, BaseTranscript::proof_data); - serialize_to_buffer(Fibonacci_y, BaseTranscript::proof_data); - - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(sumcheck_univariates[i], BaseTranscript::proof_data); - } - serialize_to_buffer(sumcheck_evaluations, BaseTranscript::proof_data); - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(zm_cq_comms[i], proof_data); - } - serialize_to_buffer(zm_cq_comm, proof_data); - serialize_to_buffer(zm_pi_comm, proof_data); - - // sanity check to make sure we generate the same length of proof as before. - ASSERT(proof_data.size() == old_proof_length); - } - }; -}; - -} // namespace flavor -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp deleted file mode 100644 index a233692ebf7..00000000000 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp +++ /dev/null @@ -1,99 +0,0 @@ - - -// AUTOGENERATED FILE -#pragma once - -#include "barretenberg/common/throw_or_abort.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" - -#include "barretenberg/flavor/generated/Fib_flavor.hpp" -#include "barretenberg/relations/generated/Fib.hpp" - -using namespace barretenberg; - -namespace proof_system { - -class FibCircuitBuilder { - public: - using Flavor = proof_system::honk::flavor::FibFlavor; - using FF = Flavor::FF; - using Row = Fib_vm::Row; - - // TODO: template - using Polynomial = Flavor::Polynomial; - using AllPolynomials = Flavor::AllPolynomials; - - static constexpr size_t num_fixed_columns = 6; - static constexpr size_t num_polys = 4; - std::vector rows; - - void set_trace(std::vector&& trace) { rows = std::move(trace); } - - AllPolynomials compute_polynomials() - { - const auto num_rows = get_circuit_subgroup_size(); - AllPolynomials polys; - - // Allocate mem for each column - for (auto& poly : polys.get_all()) { - poly = Polynomial(num_rows); - } - - for (size_t i = 0; i < rows.size(); i++) { - polys.Fibonacci_LAST[i] = rows[i].Fibonacci_LAST; - polys.Fibonacci_FIRST[i] = rows[i].Fibonacci_FIRST; - polys.Fibonacci_x[i] = rows[i].Fibonacci_x; - polys.Fibonacci_y[i] = rows[i].Fibonacci_y; - } - - polys.Fibonacci_x_shift = Polynomial(polys.Fibonacci_x.shifted()); - polys.Fibonacci_y_shift = Polynomial(polys.Fibonacci_y.shifted()); - - return polys; - } - - [[maybe_unused]] bool check_circuit() - { - auto polys = compute_polynomials(); - const size_t num_rows = polys.get_polynomial_size(); - - const auto evaluate_relation = [&](const std::string& relation_name) { - typename Relation::SumcheckArrayOfValuesOverSubrelations result; - for (auto& r : result) { - r = 0; - } - constexpr size_t NUM_SUBRELATIONS = result.size(); - - for (size_t i = 0; i < num_rows; ++i) { - Relation::accumulate(result, polys.get_row(i), {}, 1); - - bool x = true; - for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { - if (result[j] != 0) { - throw_or_abort( - format("Relation ", relation_name, ", subrelation index ", j, " failed at row ", i)); - x = false; - } - } - if (!x) { - return false; - } - } - return true; - }; - - return evaluate_relation.template operator()>("Fib"); - } - - [[nodiscard]] size_t get_num_gates() const { return rows.size(); } - - [[nodiscard]] size_t get_circuit_subgroup_size() const - { - const size_t num_rows = get_num_gates(); - const auto num_rows_log2 = static_cast(numeric::get_msb64(num_rows)); - size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); - return num_rows_pow2; - } -}; -} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_trace.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_trace.cpp deleted file mode 100644 index d2d86ba4993..00000000000 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_trace.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/proof_system/arithmetization/arithmetization.hpp" -#include -#include -#include -#include -#include -#include - -#include "./Fib_trace.hpp" - -#include "barretenberg/relations/generated/Fib.hpp" - -using namespace barretenberg; - -namespace proof_system { - -using Row = Fib_vm::Row; - -std::vector FibTraceBuilder::build_trace() -{ - { - std::vector trace; - // Build up the rows - size_t n = 16; - // Build the is_last column - - // Add first row that makes the shifted cols 0 - Row first_row = Row{ .Fibonacci_FIRST = 1 }; - trace.push_back(first_row); - - // The actual first row - Row row = { - .Fibonacci_x = 0, - .Fibonacci_y = 1, - }; - trace.push_back(row); - - for (size_t i = 2; i < n; i++) { - Row prev_row = trace[i - 1]; - - FF x = prev_row.Fibonacci_y; - FF y = prev_row.Fibonacci_x + prev_row.Fibonacci_y; - Row row = { - .Fibonacci_x = x, - .Fibonacci_y = y, - }; - trace.push_back(row); - } - // Build the isLast row - trace[n - 1].Fibonacci_LAST = 1; - - // Build the shifts - for (size_t i = 1; i < n; i++) { - Row& row = trace[i - 1]; - row.Fibonacci_x_shift = trace[(i) % trace.size()].Fibonacci_x; - row.Fibonacci_y_shift = trace[(i) % trace.size()].Fibonacci_y; - } - return trace; - } -} -} // namespace proof_system \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_trace.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_trace.hpp deleted file mode 100644 index 856400d82b4..00000000000 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_trace.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "barretenberg/common/throw_or_abort.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" - -#include "barretenberg/flavor/generated/Fib_flavor.hpp" -#include "barretenberg/relations/generated/Fib.hpp" - -using namespace barretenberg; - -namespace proof_system { - -class FibTraceBuilder { - public: - using Flavor = proof_system::honk::flavor::FibFlavor; - using FF = Flavor::FF; - using Row = Fib_vm::Row; - - static std::vector build_trace(); -}; -} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/Fib.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/Fib.hpp deleted file mode 100644 index 428c6a1208b..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/Fib.hpp +++ /dev/null @@ -1,64 +0,0 @@ - -#pragma once -#include "../relation_parameters.hpp" -#include "../relation_types.hpp" - -namespace proof_system::Fib_vm { - -template struct Row { - FF Fibonacci_LAST{}; - FF Fibonacci_FIRST{}; - FF Fibonacci_x{}; - FF Fibonacci_y{}; - FF Fibonacci_x_shift{}; - FF Fibonacci_y_shift{}; -}; - -#define DECLARE_VIEWS(index) \ - using View = typename std::tuple_element::type; \ - [[maybe_unused]] auto Fibonacci_LAST = View(new_term.Fibonacci_LAST); \ - [[maybe_unused]] auto Fibonacci_FIRST = View(new_term.Fibonacci_FIRST); \ - [[maybe_unused]] auto Fibonacci_x = View(new_term.Fibonacci_x); \ - [[maybe_unused]] auto Fibonacci_y = View(new_term.Fibonacci_y); \ - [[maybe_unused]] auto Fibonacci_x_shift = View(new_term.Fibonacci_x_shift); \ - [[maybe_unused]] auto Fibonacci_y_shift = View(new_term.Fibonacci_y_shift); - -template class FibImpl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 4, - 4, - }; - - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& new_term, - [[maybe_unused]] const RelationParameters&, - [[maybe_unused]] const FF& scaling_factor) - { - - // Contribution 0 - { - DECLARE_VIEWS(0); - - auto tmp = (((-Fibonacci_FIRST + FF(1)) * (-Fibonacci_LAST + FF(1))) * (Fibonacci_x_shift - Fibonacci_y)); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - // Contribution 1 - { - DECLARE_VIEWS(1); - - auto tmp = (((-Fibonacci_FIRST + FF(1)) * (-Fibonacci_LAST + FF(1))) * - (Fibonacci_y_shift - (Fibonacci_x + Fibonacci_y))); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - } -}; - -template using Fib = Relation>; - -} // namespace proof_system::Fib_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.cpp deleted file mode 100644 index 7a78c264e75..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.cpp +++ /dev/null @@ -1,85 +0,0 @@ - - -#include "./Fib_composer.hpp" -#include "barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp" -#include "barretenberg/proof_system/composer/composer_lib.hpp" -#include "barretenberg/proof_system/composer/permutation_lib.hpp" -#include "barretenberg/vm/generated/Fib_verifier.hpp" - -namespace proof_system::honk { - -using Flavor = honk::flavor::FibFlavor; -void FibComposer::compute_witness(CircuitConstructor& circuit) -{ - if (computed_witness) { - return; - } - - auto polynomials = circuit.compute_polynomials(); - - proving_key->Fibonacci_LAST = polynomials.Fibonacci_LAST; - proving_key->Fibonacci_FIRST = polynomials.Fibonacci_FIRST; - proving_key->Fibonacci_x = polynomials.Fibonacci_x; - proving_key->Fibonacci_y = polynomials.Fibonacci_y; - - computed_witness = true; -} - -FibProver FibComposer::create_prover(CircuitConstructor& circuit_constructor) -{ - compute_proving_key(circuit_constructor); - compute_witness(circuit_constructor); - compute_commitment_key(circuit_constructor.get_circuit_subgroup_size()); - - FibProver output_state(proving_key, commitment_key); - - return output_state; -} - -FibVerifier FibComposer::create_verifier(CircuitConstructor& circuit_constructor) -{ - auto verification_key = compute_verification_key(circuit_constructor); - - FibVerifier output_state(verification_key); - - auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); - - output_state.pcs_verification_key = std::move(pcs_verification_key); - - return output_state; -} - -std::shared_ptr FibComposer::compute_proving_key(CircuitConstructor& circuit_constructor) -{ - if (proving_key) { - return proving_key; - } - - // Initialize proving_key - { - const size_t subgroup_size = circuit_constructor.get_circuit_subgroup_size(); - proving_key = std::make_shared(subgroup_size, 0); - } - - proving_key->contains_recursive_proof = false; - - return proving_key; -} - -std::shared_ptr FibComposer::compute_verification_key(CircuitConstructor& circuit_constructor) -{ - if (verification_key) { - return verification_key; - } - - if (!proving_key) { - compute_proving_key(circuit_constructor); - } - - verification_key = - std::make_shared(proving_key->circuit_size, proving_key->num_public_inputs); - - return verification_key; -} - -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.hpp deleted file mode 100644 index 99c71c1913f..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.hpp +++ /dev/null @@ -1,69 +0,0 @@ - - -#pragma once - -#include "barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp" -#include "barretenberg/proof_system/composer/composer_lib.hpp" -#include "barretenberg/srs/global_crs.hpp" -#include "barretenberg/vm/generated/Fib_prover.hpp" -#include "barretenberg/vm/generated/Fib_verifier.hpp" - -namespace proof_system::honk { -class FibComposer { - public: - using Flavor = honk::flavor::FibFlavor; - using CircuitConstructor = FibCircuitBuilder; - using ProvingKey = Flavor::ProvingKey; - using VerificationKey = Flavor::VerificationKey; - using PCS = Flavor::PCS; - using CommitmentKey = Flavor::CommitmentKey; - using VerifierCommitmentKey = Flavor::VerifierCommitmentKey; - - // TODO: which of these will we really need - static constexpr std::string_view NAME_STRING = "Fib"; - static constexpr size_t NUM_RESERVED_GATES = 0; - static constexpr size_t NUM_WIRES = Flavor::NUM_WIRES; - - std::shared_ptr proving_key; - std::shared_ptr verification_key; - - // The crs_factory holds the path to the srs and exposes methods to extract the srs elements - std::shared_ptr> crs_factory_; - - // The commitment key is passed to the prover but also used herein to compute the verfication key commitments - std::shared_ptr commitment_key; - - std::vector recursive_proof_public_input_indices; - bool contains_recursive_proof = false; - bool computed_witness = false; - - FibComposer() { crs_factory_ = barretenberg::srs::get_crs_factory(); } - - FibComposer(std::shared_ptr p_key, std::shared_ptr v_key) - : proving_key(std::move(p_key)) - , verification_key(std::move(v_key)) - {} - - FibComposer(FibComposer&& other) noexcept = default; - FibComposer(FibComposer const& other) noexcept = default; - FibComposer& operator=(FibComposer&& other) noexcept = default; - FibComposer& operator=(FibComposer const& other) noexcept = default; - ~FibComposer() = default; - - std::shared_ptr compute_proving_key(CircuitConstructor& circuit_constructor); - std::shared_ptr compute_verification_key(CircuitConstructor& circuit_constructor); - - void compute_witness(CircuitConstructor& circuit_constructor); - - FibProver create_prover(CircuitConstructor& circuit_constructor); - FibVerifier create_verifier(CircuitConstructor& circuit_constructor); - - void add_table_column_selector_poly_to_proving_key(barretenberg::polynomial& small, const std::string& tag); - - void compute_commitment_key(size_t circuit_size) - { - commitment_key = std::make_shared(circuit_size, crs_factory_); - }; -}; - -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.test.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.test.cpp deleted file mode 100644 index 36650f8ce61..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_composer.test.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "barretenberg/vm/generated/Fib_composer.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/flavor/generated/Fib_flavor.hpp" -#include "barretenberg/proof_system/circuit_builder/generated/Fib_trace.hpp" -#include "barretenberg/proof_system/plookup_tables/types.hpp" -#include "barretenberg/sumcheck/sumcheck_round.hpp" -#include "barretenberg/vm/generated/Fib_prover.hpp" -#include "barretenberg/vm/generated/Fib_verifier.hpp" -#include -#include -#include -#include -#include - -using namespace proof_system::honk; - -namespace example_relation_honk_composer { - -class FibTests : public ::testing::Test { - protected: - // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. - void SetUp() override { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }; -}; - -namespace { -auto& engine = numeric::random::get_debug_engine(); -} - -TEST_F(FibTests, powdre2e) -{ - barretenberg::srs::init_crs_factory("../srs_db/ignition"); - - auto circuit_builder = proof_system::FibCircuitBuilder(); - - auto rows = proof_system::FibTraceBuilder::build_trace(); - circuit_builder.set_trace(std::move(rows)); - - auto composer = FibComposer(); - - bool circuit_gud = circuit_builder.check_circuit(); - ASSERT_TRUE(circuit_gud); - - auto prover = composer.create_prover(circuit_builder); - auto proof = prover.construct_proof(); - - auto verifier = composer.create_verifier(circuit_builder); - bool verified = verifier.verify_proof(proof); - ASSERT_TRUE(verified) << proof; -} - -} // namespace example_relation_honk_composer \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_prover.cpp deleted file mode 100644 index a5ade6bdf00..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_prover.cpp +++ /dev/null @@ -1,136 +0,0 @@ - - -#include "Fib_prover.hpp" -#include "barretenberg/commitment_schemes/claim.hpp" -#include "barretenberg/commitment_schemes/commitment_key.hpp" -#include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/honk/proof_system/permutation_library.hpp" -#include "barretenberg/honk/proof_system/power_polynomial.hpp" -#include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/proof_system/library/grand_product_library.hpp" -#include "barretenberg/relations/lookup_relation.hpp" -#include "barretenberg/relations/permutation_relation.hpp" -#include "barretenberg/sumcheck/sumcheck.hpp" - -namespace proof_system::honk { - -using Flavor = honk::flavor::FibFlavor; - -/** - * Create FibProver from proving key, witness and manifest. - * - * @param input_key Proving key. - * @param input_manifest Input manifest - * - * @tparam settings Settings class. - * */ -FibProver::FibProver(std::shared_ptr input_key, std::shared_ptr commitment_key) - : key(input_key) - , commitment_key(commitment_key) -{ - // TODO: take every polynomial and assign it to the key!! - - prover_polynomials.Fibonacci_LAST = key->Fibonacci_LAST; - prover_polynomials.Fibonacci_FIRST = key->Fibonacci_FIRST; - prover_polynomials.Fibonacci_x = key->Fibonacci_x; - prover_polynomials.Fibonacci_y = key->Fibonacci_y; - - prover_polynomials.Fibonacci_x = key->Fibonacci_x; - prover_polynomials.Fibonacci_x_shift = key->Fibonacci_x.shifted(); - - prover_polynomials.Fibonacci_y = key->Fibonacci_y; - prover_polynomials.Fibonacci_y_shift = key->Fibonacci_y.shifted(); - - // prover_polynomials.lookup_inverses = key->lookup_inverses; - // key->z_perm = Polynomial(key->circuit_size); - // prover_polynomials.z_perm = key->z_perm; -} - -/** - * @brief Add circuit size, public input size, and public inputs to transcript - * - */ -void FibProver::execute_preamble_round() -{ - const auto circuit_size = static_cast(key->circuit_size); - - transcript->send_to_verifier("circuit_size", circuit_size); -} - -/** - * @brief Compute commitments to the first three wires - * - */ -void FibProver::execute_wire_commitments_round() -{ - auto wire_polys = key->get_wires(); - auto labels = commitment_labels.get_wires(); - for (size_t idx = 0; idx < wire_polys.size(); ++idx) { - transcript->send_to_verifier(labels[idx], commitment_key->commit(wire_polys[idx])); - } -} - -/** - * @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated. - * - */ -void FibProver::execute_relation_check_rounds() -{ - using Sumcheck = sumcheck::SumcheckProver; - - auto sumcheck = Sumcheck(key->circuit_size, transcript); - auto alpha = transcript->get_challenge("alpha"); - - sumcheck_output = sumcheck.prove(prover_polynomials, relation_parameters, alpha); -} - -/** - * @brief Execute the ZeroMorph protocol to prove the multilinear evaluations produced by Sumcheck - * @details See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the unrolled protocol. - * - * */ -void FibProver::execute_zeromorph_rounds() -{ - ZeroMorph::prove(prover_polynomials.get_unshifted(), - prover_polynomials.get_to_be_shifted(), - sumcheck_output.claimed_evaluations.get_unshifted(), - sumcheck_output.claimed_evaluations.get_shifted(), - sumcheck_output.challenge, - commitment_key, - transcript); -} - -plonk::proof& FibProver::export_proof() -{ - proof.proof_data = transcript->proof_data; - return proof; -} - -plonk::proof& FibProver::construct_proof() -{ - // Add circuit size public input size and public inputs to transcript-> - execute_preamble_round(); - - // Compute wire commitments - execute_wire_commitments_round(); - - // TODO: not implemented for codegen just yet - // Compute sorted list accumulator and commitment - // execute_log_derivative_commitments_round(); - - // Fiat-Shamir: bbeta & gamma - // Compute grand product(s) and commitments. - // execute_grand_product_computation_round(); - - // Fiat-Shamir: alpha - // Run sumcheck subprotocol. - execute_relation_check_rounds(); - - // Fiat-Shamir: rho, y, x, z - // Execute Zeromorph multilinear PCS - execute_zeromorph_rounds(); - - return export_proof(); -} - -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_prover.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_prover.hpp deleted file mode 100644 index 7b9e3cc6862..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_prover.hpp +++ /dev/null @@ -1,62 +0,0 @@ - - -#pragma once -#include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" -#include "barretenberg/flavor/generated/Fib_flavor.hpp" -#include "barretenberg/plonk/proof_system/types/proof.hpp" -#include "barretenberg/relations/relation_parameters.hpp" -#include "barretenberg/sumcheck/sumcheck_output.hpp" -#include "barretenberg/transcript/transcript.hpp" - -namespace proof_system::honk { - -class FibProver { - - using Flavor = honk::flavor::FibFlavor; - using FF = Flavor::FF; - using PCS = Flavor::PCS; - using PCSCommitmentKey = Flavor::CommitmentKey; - using ProvingKey = Flavor::ProvingKey; - using Polynomial = Flavor::Polynomial; - using ProverPolynomials = Flavor::ProverPolynomials; - using CommitmentLabels = Flavor::CommitmentLabels; - using Curve = Flavor::Curve; - using Transcript = Flavor::Transcript; - - public: - explicit FibProver(std::shared_ptr input_key, std::shared_ptr commitment_key); - - void execute_preamble_round(); - void execute_wire_commitments_round(); - void execute_relation_check_rounds(); - void execute_zeromorph_rounds(); - - plonk::proof& export_proof(); - plonk::proof& construct_proof(); - - std::shared_ptr transcript = std::make_shared(); - - std::vector public_inputs; - - proof_system::RelationParameters relation_parameters; - - std::shared_ptr key; - - // Container for spans of all polynomials required by the prover (i.e. all multivariates evaluated by Sumcheck). - ProverPolynomials prover_polynomials; - - CommitmentLabels commitment_labels; - - Polynomial quotient_W; - - sumcheck::SumcheckOutput sumcheck_output; - - std::shared_ptr commitment_key; - - using ZeroMorph = pcs::zeromorph::ZeroMorphProver_; - - private: - plonk::proof proof; -}; - -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_verifier.cpp deleted file mode 100644 index a47e2c0fdf0..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_verifier.cpp +++ /dev/null @@ -1,89 +0,0 @@ - - -#include "./Fib_verifier.hpp" -#include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" -#include "barretenberg/honk/proof_system/power_polynomial.hpp" -#include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/transcript/transcript.hpp" - -using namespace barretenberg; -using namespace proof_system::honk::sumcheck; - -namespace proof_system::honk { -FibVerifier::FibVerifier(std::shared_ptr verifier_key) - : key(verifier_key) -{} - -FibVerifier::FibVerifier(FibVerifier&& other) noexcept - : key(std::move(other.key)) - , pcs_verification_key(std::move(other.pcs_verification_key)) -{} - -FibVerifier& FibVerifier::operator=(FibVerifier&& other) noexcept -{ - key = other.key; - pcs_verification_key = (std::move(other.pcs_verification_key)); - commitments.clear(); - return *this; -} - -/** - * @brief This function verifies an Fib Honk proof for given program settings. - * - */ -bool FibVerifier::verify_proof(const plonk::proof& proof) -{ - using Flavor = honk::flavor::FibFlavor; - using FF = Flavor::FF; - using Commitment = Flavor::Commitment; - // using Curve = Flavor::Curve; - // using ZeroMorph = pcs::zeromorph::ZeroMorphVerifier_; - using VerifierCommitments = Flavor::VerifierCommitments; - using CommitmentLabels = Flavor::CommitmentLabels; - using Transcript = Flavor::Transcript; - - RelationParameters relation_parameters; - - transcript = std::make_shared(proof.proof_data); - - VerifierCommitments commitments{ key }; - CommitmentLabels commitment_labels; - - const auto circuit_size = transcript->template receive_from_prover("circuit_size"); - - if (circuit_size != key->circuit_size) { - return false; - } - - // Get commitments to VM wires - commitments.Fibonacci_x = transcript->template receive_from_prover(commitment_labels.Fibonacci_x); - commitments.Fibonacci_y = transcript->template receive_from_prover(commitment_labels.Fibonacci_y); - - // Execute Sumcheck Verifier - auto sumcheck = SumcheckVerifier(circuit_size); - - auto alpha = transcript->get_challenge("alpha"); - auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] = - sumcheck.verify(relation_parameters, alpha, transcript); - - // If Sumcheck did not verify, return false - if (sumcheck_verified.has_value() && !sumcheck_verified.value()) { - return false; - } - - // Execute ZeroMorph rounds. See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the - // unrolled protocol. - // NOTE: temporarily disabled - facing integration issues - // auto pairing_points = ZeroMorph::verify(commitments.get_unshifted(), - // commitments.get_to_be_shifted(), - // claimed_evaluations.get_unshifted(), - // claimed_evaluations.get_shifted(), - // multivariate_challenge, - // transcript); - - // auto verified = pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); - // return sumcheck_verified.value() && verified; - return sumcheck_verified.value(); -} - -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_verifier.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/Fib_verifier.hpp deleted file mode 100644 index 303cb4fca70..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Fib_verifier.hpp +++ /dev/null @@ -1,33 +0,0 @@ - - -#pragma once -#include "barretenberg/flavor/generated/Fib_flavor.hpp" -#include "barretenberg/plonk/proof_system/types/proof.hpp" -#include "barretenberg/sumcheck/sumcheck.hpp" - -namespace proof_system::honk { -class FibVerifier { - using Flavor = honk::flavor::FibFlavor; - using FF = Flavor::FF; - using Commitment = Flavor::Commitment; - using VerificationKey = Flavor::VerificationKey; - using VerifierCommitmentKey = Flavor::VerifierCommitmentKey; - using Transcript = Flavor::Transcript; - - public: - explicit FibVerifier(std::shared_ptr verifier_key = nullptr); - FibVerifier(FibVerifier&& other) noexcept; - FibVerifier(const FibVerifier& other) = delete; - - FibVerifier& operator=(const FibVerifier& other) = delete; - FibVerifier& operator=(FibVerifier&& other) noexcept; - - bool verify_proof(const plonk::proof& proof); - - std::shared_ptr key; - std::map commitments; - std::shared_ptr pcs_verification_key; - std::shared_ptr transcript; -}; - -} // namespace proof_system::honk