From 16cd1eaaa763622556f2b4a81e72260293fa487a Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 9 Aug 2024 13:56:09 +0000 Subject: [PATCH 01/15] comments --- .../cpp/src/barretenberg/flavor/flavor.hpp | 30 +- .../barretenberg/polynomials/polynomial.hpp | 10 + .../shared_shifted_virtual_zeroes_array.hpp | 52 ++ .../polynomials/sparse_polynomial.cpp | 466 ++++++++++++++++++ .../polynomials/sparse_polynomial.hpp | 279 +++++++++++ .../polynomials/sparse_polynomial.test.cpp | 61 +++ .../stdlib_circuit_builders/ultra_flavor.hpp | 7 +- .../bb-pil-backend/templates/flavor.hpp.hbs | 12 +- 8 files changed, 894 insertions(+), 23 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp create mode 100644 barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp create mode 100644 barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp create mode 100644 barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index a0c9bb96ed7..92f00e143ca 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -414,29 +414,29 @@ concept IsPlonkFlavor = IsAnyOf concept IsUltraPlonkFlavor = IsAnyOf; -template +template concept IsUltraPlonkOrHonk = IsAnyOf; -template +template concept IsHonkFlavor = IsAnyOf; -template +template concept IsUltraFlavor = IsAnyOf; -template +template concept IsGoblinFlavor = IsAnyOf, MegaRecursiveFlavor_, MegaRecursiveFlavor_>; -template -concept IsRecursiveFlavor = IsAnyOf, - UltraRecursiveFlavor_, +template +concept IsRecursiveFlavor = IsAnyOf, + UltraRecursiveFlavor_, UltraRecursiveFlavor_, MegaRecursiveFlavor_, MegaRecursiveFlavor_, -MegaRecursiveFlavor_, -TranslatorRecursiveFlavor_, -TranslatorRecursiveFlavor_, +MegaRecursiveFlavor_, +TranslatorRecursiveFlavor_, +TranslatorRecursiveFlavor_, TranslatorRecursiveFlavor_, ECCVMRecursiveFlavor_>; @@ -445,14 +445,14 @@ template concept IsECCVMRecursiveFlavor = IsAnyOf concept IsGrumpkinFlavor = IsAnyOf; -template concept IsFoldingFlavor = IsAnyOf concept IsFoldingFlavor = IsAnyOf, - UltraRecursiveFlavor_, + MegaFlavor, + UltraRecursiveFlavor_, + UltraRecursiveFlavor_, UltraRecursiveFlavor_, - MegaRecursiveFlavor_, + MegaRecursiveFlavor_, MegaRecursiveFlavor_, MegaRecursiveFlavor_>; template diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index 2b3a02a7736..34df96e37ed 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -9,6 +9,16 @@ namespace bb { enum class DontZeroMemory { FLAG }; +/** + * @brief Polynomial class that represents the coefficients 'a' of a_0 + a_1 x + a_n x^n of + * a finite field polynomial equation of degree that is at most the size of some zk circuit. + * The polynomial is used to represent the gates of our arithmetized zk programs. + * Polynomials use the majority of the memory in proving, so caution should be used in making sure + * unnecessary copies are avoided, both for avoiding unnecessary memory usage and performance + * due to unnecessary allocations. + * + * @tparam Fr the finite field type. + */ template class Polynomial { public: /** diff --git a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp new file mode 100644 index 00000000000..e6b90c110c1 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include "barretenberg/common/assert.hpp" +#include +#include + +// Shared pointer array of a type (in our case, a field) that is +// conceptually filled with 0's until 'virtual_size_', but with actual memory usage +// proportional to 'size'. +// As well, there is a 'shift_' member that can be used when we want to share the underlying array. +// Everything is public as this is intended to be wrapped by another class, namely Polynomial +// The name is a mouthful, but again as an internal bundling of details it is intended to be wrapped by +// something more ergonomic. +template struct SharedShiftedVirtualZeroesArray { + // Method to set the value at a specific index + void set(size_t index, const T& value) + { + ASSERT(index < size()); + data()[index] = value; + } + + // Method to get the value at a specific index + T get(size_t index) const + { + ASSERT(index < virtual_size()); + if (index < size()) { + return data()[index]; + } + return T{}; // Return default element when index is out of the actual filled size + } + + // Method to get the memory-backed size such that we can set index 0..size()-1. + size_t size() const { return size_ - shift_; } + // Method to get virtual size such that we can get index 0..virtual_size()-1. + size_t virtual_size() const { return virtual_size_ - shift_; }; + + T* data() { return backing_memory_.get() + shift_; } + const T* data() const { return backing_memory_.get() + shift_; } + + // MEMBERS: + // The actual size of the array allocation + size_t size_ = 0; + // The logical size of the vector, indices size_ to virtual_size - 1 return T{} when indexed. + // This is really mainly used for a debug check that we never index >= virtual_size_; + size_t virtual_size_ = 0; + // An offset into the array, used to implement shifted polynomials. + size_t shift_ = 0; + + // The memory + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) + std::shared_ptr backing_memory_; +}; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp new file mode 100644 index 00000000000..04cb8aef25f --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp @@ -0,0 +1,466 @@ +#include "sparse_polynomial.hpp" +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/slab_allocator.hpp" +#include "barretenberg/common/thread.hpp" +#include "barretenberg/numeric/bitop/pow.hpp" +#include "polynomial_arithmetic.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bb { + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) +template std::shared_ptr _allocate_aligned_memory(size_t n_elements) +{ + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) + return std::static_pointer_cast(get_mem_slab(sizeof(Fr) * n_elements)); +} + +template void SparsePolynomial::allocate_backing_memory(size_t size, size_t virtual_size) +{ + coefficients_ = SharedShiftedVirtualZeroesArray{ + size, /* actual memory size */ + virtual_size, /* virtual size, i.e. until what size do we conceptually have zeroes */ + 0, /* shift, initially 0 */ + _allocate_aligned_memory(size) /* our backing memory, since shift is 0 it is equal to our memory size */ + }; +} + +/** + * Constructors / Destructors + **/ + +/** + * @brief Initialize a SparsePolynomial to size 'size', zeroing memory. + * + * @param size The size of the polynomial. + */ +template SparsePolynomial::SparsePolynomial(size_t size, size_t virtual_size) +{ + allocate_backing_memory(size, virtual_size); + memset(static_cast(coefficients_.data()), 0, sizeof(Fr) * size); +} + +/** + * @brief Initialize a SparsePolynomial to size 'size'. + * Important: This does NOT zero memory. + * + * @param size The initial size of the polynomial. + * @param flag Signals that we do not zero memory. + */ +template SparsePolynomial::SparsePolynomial(size_t size, size_t virtual_size, DontZeroMemory flag) +{ + // Flag is unused, but we don't memset 0 if passed. + (void)flag; + allocate_backing_memory(size, virtual_size); +} + +template +SparsePolynomial::SparsePolynomial(const SparsePolynomial& other) + : SparsePolynomial(other, other.size()) +{} + +// fully copying "expensive" constructor +template +SparsePolynomial::SparsePolynomial(const SparsePolynomial& other, const size_t target_size) +{ + allocate_backing_memory(std::max(target_size, other.size()), other.virtual_size()); + + memcpy(static_cast(coefficients_.data()), + static_cast(other.coefficients_.data()), + sizeof(Fr) * other.size()); +} + +// interpolation constructor +template +SparsePolynomial::SparsePolynomial(std::span interpolation_points, + std::span evaluations, + size_t virtual_size) + : SparsePolynomial(interpolation_points.size(), virtual_size) +{ + ASSERT(coefficients_.size() > 0); + + polynomial_arithmetic::compute_efficient_interpolation( + evaluations.data(), coefficients_.data(), interpolation_points.data(), coefficients_.size()); +} + +template SparsePolynomial::SparsePolynomial(std::span coefficients, size_t virtual_size) +{ + allocate_backing_memory(coefficients.size(), virtual_size); + + memcpy(static_cast(data()), static_cast(coefficients.data()), sizeof(Fr) * coefficients.size()); +} + +// Assignments + +// full copy "expensive" assignment +template SparsePolynomial& SparsePolynomial::operator=(const SparsePolynomial& other) +{ + if (this == &other) { + return *this; + } + allocate_backing_memory(other.coefficients_.size(), other.coefficients_.virtual_size()); + memcpy(static_cast(coefficients_.data()), + static_cast(other.coefficients_.data()), + sizeof(Fr) * other.coefficients_.size()); + return *this; +} + +template SparsePolynomial SparsePolynomial::share() const +{ + SparsePolynomial p; + p.coefficients_ = coefficients_; + return p; +} + +template bool SparsePolynomial::operator==(SparsePolynomial const& rhs) const +{ + // If either is empty, both must be + if (is_empty() || rhs.is_empty()) { + return is_empty() && rhs.is_empty(); + } + // Size must agree + if (virtual_size() != rhs.virtual_size()) { + return false; + } + // Each coefficient must agree + for (size_t i = 0; i < std::max(size(), rhs.size()); i++) { + if (coefficients_.get(i) != rhs.coefficients_.get(i)) { + return false; + } + } + return true; +} + +template SparsePolynomial& SparsePolynomial::operator+=(std::span other) +{ + const size_t other_size = other.size(); + ASSERT(in_place_operation_viable(other_size)); + + size_t num_threads = calculate_num_threads(other_size); + size_t range_per_thread = other_size / num_threads; + size_t leftovers = other_size - (range_per_thread * num_threads); + parallel_for(num_threads, [&](size_t j) { + size_t offset = j * range_per_thread; + size_t end = (j == num_threads - 1) ? offset + range_per_thread + leftovers : offset + range_per_thread; + for (size_t i = offset; i < end; ++i) { + coefficients_.data()[i] += other[i]; + } + }); + + return *this; +} + +template Fr SparsePolynomial::evaluate(const Fr& z, const size_t target_size) const +{ + return polynomial_arithmetic::evaluate(data(), z, target_size); +} + +template Fr SparsePolynomial::evaluate(const Fr& z) const +{ + return polynomial_arithmetic::evaluate(data(), z, size()); +} + +template Fr SparsePolynomial::evaluate_mle(std::span evaluation_points, bool shift) const +{ + const size_t m = evaluation_points.size(); + + // To simplify handling of edge cases, we assume that size_ is always a power of 2 + ASSERT(size() == static_cast(1 << m)); + + // we do m rounds l = 0,...,m-1. + // in round l, n_l is the size of the buffer containing the SparsePolynomial partially evaluated + // at u₀,..., u_l. + // in round 0, this is half the size of n + size_t n_l = 1 << (m - 1); + + // temporary buffer of half the size of the SparsePolynomial + // TODO(AD): Make this a SparsePolynomial with DontZeroMemory::FLAG + auto tmp_ptr = _allocate_aligned_memory(sizeof(Fr) * n_l); + auto tmp = tmp_ptr.get(); + + const Fr* prev = data(); + if (shift) { + ASSERT(prev[0] == Fr::zero()); + prev++; + } + + Fr u_l = evaluation_points[0]; + for (size_t i = 0; i < n_l; ++i) { + // curr[i] = (Fr(1) - u_l) * prev[i << 1] + u_l * prev[(i << 1) + 1]; + tmp[i] = prev[i << 1] + u_l * (prev[(i << 1) + 1] - prev[i << 1]); + } + // partially evaluate the m-1 remaining points + for (size_t l = 1; l < m; ++l) { + n_l = 1 << (m - l - 1); + u_l = evaluation_points[l]; + for (size_t i = 0; i < n_l; ++i) { + tmp[i] = tmp[i << 1] + u_l * (tmp[(i << 1) + 1] - tmp[i << 1]); + } + } + Fr result = tmp[0]; + return result; +} + +template +SparsePolynomial SparsePolynomial::partial_evaluate_mle(std::span evaluation_points) const +{ + // Get size of partial evaluation point u = (u_0,...,u_{m-1}) + const size_t m = evaluation_points.size(); + + // Assert that the size of the SparsePolynomial being evaluated is a power of 2 greater than (1 << m) + ASSERT(numeric::is_power_of_two(size())); + ASSERT(size() >= static_cast(1 << m)); + size_t n = numeric::get_msb(size()); + + // Partial evaluation is done in m rounds l = 0,...,m-1. At the end of round l, the SparsePolynomial has been + // partially evaluated at u_{m-l-1}, ..., u_{m-1} in variables X_{n-l-1}, ..., X_{n-1}. The size of this + // SparsePolynomial is n_l. + size_t n_l = 1 << (n - 1); + + // Temporary buffer of half the size of the SparsePolynomial + SparsePolynomial intermediate(n_l, n_l, DontZeroMemory::FLAG); + + // Evaluate variable X_{n-1} at u_{m-1} + Fr u_l = evaluation_points[m - 1]; + + for (size_t i = 0; i < n_l; i++) { + // Initiate our intermediate results using this SparsePolynomial. + intermediate[i] = get(i) + u_l * (get(i + n_l) - get(i)); + } + // Evaluate m-1 variables X_{n-l-1}, ..., X_{n-2} at m-1 remaining values u_0,...,u_{m-2}) + for (size_t l = 1; l < m; ++l) { + n_l = 1 << (n - l - 1); + u_l = evaluation_points[m - l - 1]; + for (size_t i = 0; i < n_l; ++i) { + intermediate[i] += u_l * (intermediate[i + n_l] - intermediate[i]); + } + } + + // Construct resulting SparsePolynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) from buffer + SparsePolynomial result(n_l, n_l, DontZeroMemory::FLAG); + for (size_t idx = 0; idx < n_l; ++idx) { + result[idx] = intermediate[idx]; + } + + return result; +} + +/** + * FFTs + **/ + +template +void SparsePolynomial::fft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::fft(data(), domain); +} + +template +void SparsePolynomial::partial_fft(const EvaluationDomain& domain, Fr constant, bool is_coset) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::partial_fft(data(), domain, constant, is_coset); +} + +template +void SparsePolynomial::coset_fft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::coset_fft(data(), domain); +} + +template +void SparsePolynomial::coset_fft(const EvaluationDomain& domain, + const EvaluationDomain& large_domain, + const size_t domain_extension) + requires polynomial_arithmetic::SupportsFFT +{ + size_t extended_size = domain.size * domain_extension; + + ASSERT(in_place_operation_viable(extended_size)); + zero_memory_beyond(extended_size); + + polynomial_arithmetic::coset_fft(data(), domain, large_domain, domain_extension); +} + +template +void SparsePolynomial::coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::coset_fft_with_constant(data(), domain, constant); +} + +template +void SparsePolynomial::coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::coset_fft_with_generator_shift(data(), domain, constant); +} + +template +void SparsePolynomial::ifft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::ifft(data(), domain); +} + +template +void SparsePolynomial::ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::ifft_with_constant(data(), domain, constant); +} + +template +void SparsePolynomial::coset_ifft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT +{ + ASSERT(in_place_operation_viable(domain.size)); + zero_memory_beyond(domain.size); + + polynomial_arithmetic::coset_ifft(data(), domain); +} + +template +Fr SparsePolynomial::compute_kate_opening_coefficients(const Fr& z) + requires polynomial_arithmetic::SupportsFFT +{ + return polynomial_arithmetic::compute_kate_opening_coefficients(data(), data(), z, size()); +} + +template +Fr SparsePolynomial::compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT +{ + return polynomial_arithmetic::compute_barycentric_evaluation(data(), domain.size, z, domain); +} + +template +Fr SparsePolynomial::evaluate_from_fft(const EvaluationDomain& large_domain, + const Fr& z, + const EvaluationDomain& small_domain) + requires polynomial_arithmetic::SupportsFFT + +{ + return polynomial_arithmetic::evaluate_from_fft(data(), large_domain, z, small_domain); +} + +template SparsePolynomial& SparsePolynomial::operator-=(std::span other) +{ + const size_t other_size = other.size(); + ASSERT(in_place_operation_viable(other_size)); + + size_t num_threads = calculate_num_threads(other_size); + size_t range_per_thread = other_size / num_threads; + size_t leftovers = other_size - (range_per_thread * num_threads); + parallel_for(num_threads, [&](size_t j) { + size_t offset = j * range_per_thread; + size_t end = (j == num_threads - 1) ? offset + range_per_thread + leftovers : offset + range_per_thread; + for (size_t i = offset; i < end; ++i) { + coefficients_.data()[i] -= other[i]; + } + }); + + return *this; +} + +template SparsePolynomial& SparsePolynomial::operator*=(const Fr scaling_factor) +{ + ASSERT(in_place_operation_viable()); + + size_t num_threads = calculate_num_threads(size()); + size_t range_per_thread = size() / num_threads; + size_t leftovers = size() - (range_per_thread * num_threads); + parallel_for(num_threads, [&](size_t j) { + size_t offset = j * range_per_thread; + size_t end = (j == num_threads - 1) ? offset + range_per_thread + leftovers : offset + range_per_thread; + for (size_t i = offset; i < end; ++i) { + coefficients_.data()[i] *= scaling_factor; + } + }); + + return *this; +} + +template void SparsePolynomial::add_scaled(std::span other, Fr scaling_factor) +{ + const size_t other_size = other.size(); + ASSERT(in_place_operation_viable(other_size)); + + size_t num_threads = calculate_num_threads(other_size); + size_t range_per_thread = other_size / num_threads; + size_t leftovers = other_size - (range_per_thread * num_threads); + parallel_for(num_threads, [&](size_t j) { + size_t offset = j * range_per_thread; + size_t end = (j == num_threads - 1) ? offset + range_per_thread + leftovers : offset + range_per_thread; + for (size_t i = offset; i < end; ++i) { + data()[i] += scaling_factor * other[i]; + } + }); +} + +/** + * @brief Returns a SparsePolynomial the left-shift of self. + * + * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), + * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). + */ +template SparsePolynomial SparsePolynomial::shifted() const +{ + SparsePolynomial result; + result.coefficients_ = coefficients_; + result.coefficients_.shift_ += 1; + // We only expect to shift by 1 + ASSERT(data()[0].is_zero()); + ASSERT(result.coefficients_.shift_ == 1); + return result; +} + +/** + * @brief sets a block of memory to all zeroes + * Used, for example, when one Polynomioal is instantiated from another one with size_>= other.size_. + */ +template void SparsePolynomial::zero_memory_beyond(const size_t start_position) +{ + size_t end = size(); + ASSERT(end >= start_position); + + size_t delta = end - start_position; + if (delta > 0) { + memset(static_cast(&data()[start_position]), 0, sizeof(Fr) * delta); + } +} + +template class SparsePolynomial; +template class SparsePolynomial; + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp new file mode 100644 index 00000000000..c62395b44b5 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp @@ -0,0 +1,279 @@ +#pragma once +#include "barretenberg/common/mem.hpp" +#include "barretenberg/crypto/sha256/sha256.hpp" +#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +#include "barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp" +#include "evaluation_domain.hpp" +#include "polynomial_arithmetic.hpp" +#include + +namespace bb { + +/** + * @brief Sparse polynomial class that represents the coefficients 'a' of a_0 + a_1 x + a_n x^n of + * a finite field polynomial equation of degree that is at most the size of some zk circuit. + * Past 'n' it has a virtual size where it conceptually has coefficients all equal to 0. + * Notably, we allow indexing past 'n' up to our virtual size (checked only in a debug build, however). + * The polynomial is used to represent the gates of our arithmetized zk programs. + * Polynomials use the majority of the memory in proving, so caution should be used in making sure + * unnecessary copies are avoided, both for avoiding unnecessary memory usage and performance + * due to unnecessary allocations. + * The polynomial has a maximum degree in the underlying SharedShiftedVirtualZeroesArray, dictated by the circuit size, + * this is just used for debugging as we represent. + * + * @tparam Fr the finite field type. + */ +template class SparsePolynomial { + public: + using FF = Fr; + enum class DontZeroMemory { FLAG }; + + SparsePolynomial(size_t size, size_t virtual_size); + // Intended just for plonk, where size == virtual_size always + SparsePolynomial(size_t size) + : SparsePolynomial(size, size) + {} + // Constructor that does not initialize values, use with caution to save time. + SparsePolynomial(size_t size, size_t virtual_size, DontZeroMemory flag); + SparsePolynomial(const SparsePolynomial& other); + SparsePolynomial(const SparsePolynomial& other, size_t target_size); + + SparsePolynomial(SparsePolynomial&& other) noexcept = default; + + SparsePolynomial(std::span coefficients, size_t virtual_size); + + SparsePolynomial(std::span coefficients) + : SparsePolynomial(coefficients, coefficients.size()) + {} + + // Allow polynomials to be entirely reset/dormant + SparsePolynomial() = default; + + /** + * @brief Create the degree-(m-1) polynomial T(X) that interpolates the given evaluations. + * We have T(xⱼ) = yⱼ for j=1,...,m + * + * @param interpolation_points (x₁,…,xₘ) + * @param evaluations (y₁,…,yₘ) + */ + SparsePolynomial(std::span interpolation_points, std::span evaluations, size_t virtual_size); + + // move assignment + SparsePolynomial& operator=(SparsePolynomial&& other) noexcept = default; + SparsePolynomial& operator=(const SparsePolynomial& other); + ~SparsePolynomial() = default; + + /** + * Return a shallow clone of the polynomial. i.e. underlying memory is shared. + */ + SparsePolynomial share() const; + + void clear() { coefficients_ = SharedShiftedVirtualZeroesArray{}; } + + /** + * @brief Check whether or not a polynomial is identically zero + * + */ + bool is_zero() const + { + if (is_empty()) { + ASSERT(false); + info("Checking is_zero on an empty SparsePolynomial!"); + } + for (size_t i = 0; i < size(); i++) { + if (coefficients_.data()[i] != 0) { + return false; + } + } + return true; + } + + bool operator==(SparsePolynomial const& rhs) const; + + void set(size_t i, const Fr& value) { coefficients_.set(i, value); }; + Fr get(size_t i) const { return coefficients_.get(i); }; + + bool is_empty() const { return coefficients_.size() == 0; } + + Fr* begin() { return data(); } + Fr* end() { return data() + size(); } + const Fr* begin() const { return data(); } + const Fr* end() const { return data() + size(); } + + /** + * @brief Returns a SparsePolynomial the left-shift of self. + * + * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), + * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). + */ + SparsePolynomial shifted() const; + + /** + * @brief evaluates p(X) = ∑ᵢ aᵢ⋅Xⁱ considered as multi-linear extension p(X₀,…,Xₘ₋₁) = ∑ᵢ aᵢ⋅Lᵢ(X₀,…,Xₘ₋₁) + * at u = (u₀,…,uₘ₋₁) + * + * @details this function allocates a temporary buffer of size n/2 + * + * @param evaluation_points an MLE evaluation point u = (u₀,…,uₘ₋₁) + * @param shift evaluates p'(X₀,…,Xₘ₋₁) = 1⋅L₀(X₀,…,Xₘ₋₁) + ∑ᵢ˲₁ aᵢ₋₁⋅Lᵢ(X₀,…,Xₘ₋₁) if true + * @return Fr p(u₀,…,uₘ₋₁) + */ + Fr evaluate_mle(std::span evaluation_points, bool shift = false) const; + + /** + * @brief Partially evaluates in the last k variables a polynomial interpreted as a multilinear extension. + * + * @details Partially evaluates p(X) = (a_0, ..., a_{2^n-1}) considered as multilinear extension p(X_0,…,X_{n-1}) = + * \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,…,u_{m-1}), m < n, in the last m variables X_n-m,…,X_{n-1}. The result + * is a multilinear polynomial in n-m variables g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}). + * + * @note Intuitively, partially evaluating in one variable collapses the hypercube in one dimension, halving the + * number of coefficients needed to represent the result. To partially evaluate starting with the first variable (as + * is done in evaluate_mle), the vector of coefficents is halved by combining adjacent rows in a pairwise + * fashion (similar to what is done in Sumcheck via "edges"). To evaluate starting from the last variable, we + * instead bisect the whole vector and combine the two halves. I.e. rather than coefficents being combined with + * their immediate neighbor, they are combined with the coefficient that lives n/2 indices away. + * + * @param evaluation_points an MLE partial evaluation point u = (u_0,…,u_{m-1}) + * @return DensePolynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) + */ + SparsePolynomial partial_evaluate_mle(std::span evaluation_points) const; + + Fr compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT; + Fr evaluate_from_fft(const EvaluationDomain& large_domain, + const Fr& z, + const EvaluationDomain& small_domain) + requires polynomial_arithmetic::SupportsFFT; + void fft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT; + void partial_fft(const EvaluationDomain& domain, Fr constant = 1, bool is_coset = false) + requires polynomial_arithmetic::SupportsFFT; + void coset_fft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT; + void coset_fft(const EvaluationDomain& domain, + const EvaluationDomain& large_domain, + size_t domain_extension) + requires polynomial_arithmetic::SupportsFFT; + void coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) + requires polynomial_arithmetic::SupportsFFT; + void coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) + requires polynomial_arithmetic::SupportsFFT; + void ifft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT; + void ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) + requires polynomial_arithmetic::SupportsFFT; + void coset_ifft(const EvaluationDomain& domain) + requires polynomial_arithmetic::SupportsFFT; + Fr compute_kate_opening_coefficients(const Fr& z) + requires polynomial_arithmetic::SupportsFFT; + + /** + * @brief Divides p(X) by (X-r₁)⋯(X−rₘ) in-place. + * Assumes that p(rⱼ)=0 for all j + * + * @details we specialize the method when only a single root is given. + * if one of the roots is 0, then we first factor all other roots. + * dividing by X requires only a left shift of all coefficient. + * + * @param roots list of roots (r₁,…,rₘ) + */ + void factor_roots(std::span roots) { polynomial_arithmetic::factor_roots(std::span{ *this }, roots); }; + void factor_roots(const Fr& root) { polynomial_arithmetic::factor_roots(std::span{ *this }, root); }; + + Fr evaluate(const Fr& z, size_t target_size) const; + Fr evaluate(const Fr& z) const; + + /** + * @brief adds the polynomial q(X) 'other', multiplied by a scaling factor. + * + * @param other q(X) + * @param scaling_factor scaling factor by which all coefficients of q(X) are multiplied + */ + void add_scaled(std::span other, Fr scaling_factor); + + /** + * @brief adds the polynomial q(X) 'other'. + * + * @param other q(X) + */ + SparsePolynomial& operator+=(std::span other); + + /** + * @brief subtracts the polynomial q(X) 'other'. + * + * @param other q(X) + */ + SparsePolynomial& operator-=(std::span other); + + /** + * @brief sets this = p(X) to s⋅p(X) + * + * @param scaling_factor s + */ + SparsePolynomial& operator*=(Fr scaling_factor); + + std::span as_span() const + { + return { coefficients_.data(), coefficients_.data() + coefficients_.size() }; + } + std::span as_span() { return { coefficients_.data(), coefficients_.data() + coefficients_.size() }; } + std::size_t size() const { return coefficients_.size(); } + std::size_t virtual_size() const { return coefficients_.virtual_size(); } + + Fr* data() { return coefficients_.data(); } + const Fr* data() const { return coefficients_.data(); } + Fr& operator[](size_t i) + { + ASSERT(i < size()); + return coefficients_.data()[i]; + } + const Fr& operator[](size_t i) const + { + ASSERT(i < size()); + return coefficients_.data()[i]; + } + + static SparsePolynomial random(size_t size, size_t virtual_size) + { + SparsePolynomial p(size, virtual_size, DontZeroMemory::FLAG); + std::generate_n(p.coefficients_.data(), size, []() { return Fr::random_element(); }); + return p; + } + + private: + // allocate a fresh memory pointer for backing memory + // DOES NOT initialize memory + void allocate_backing_memory(size_t size, size_t virtual_size); + + // safety check for in place operations + bool in_place_operation_viable(size_t domain_size = 0) { return (size() >= domain_size); } + + void zero_memory_beyond(size_t start_position); + // When a polynomial is instantiated from a size alone, the memory allocated corresponds to + // input size + MAXIMUM_COEFFICIENT_SHIFT to support 'shifted' coefficients efficiently. + const static size_t MAXIMUM_COEFFICIENT_SHIFT = 1; + + // The underlying memory, with a bespoke (but minimal) shared array struct that fits our needs. + // Namely, it supports polynomial shifts and 'virtual' zeroes past a size up until a 'virtual' size. + SharedShiftedVirtualZeroesArray coefficients_; +}; + +template inline std::ostream& operator<<(std::ostream& os, SparsePolynomial const& p) +{ + if (p.size() == 0) { + return os << "[]"; + } + if (p.size() == 1) { + return os << "[ data " << p[0] << "]"; + } + return os << "[ data\n" + << " " << p[0] << ",\n" + << " " << p[1] << ",\n" + << " ... ,\n" + << " " << p[p.size() - 2] << ",\n" + << " " << p[p.size() - 1] << ",\n" + << "]"; +} + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp new file mode 100644 index 00000000000..5f564f1d1b0 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp @@ -0,0 +1,61 @@ +#include +#include + +#include "barretenberg/polynomials/polynomial.hpp" + +using namespace bb; + +// Simple test/demonstration of shifted functionality +TEST(SparsePolynomial, Shifted) +{ + using FF = bb::fr; + using Polynomial = Polynomial; + const size_t SIZE = 10; + auto poly = Polynomial::random(SIZE); + poly[0] = 0; // make it shiftable + + // Instantiate the shift via the shited method + auto poly_shifted = poly.shifted(); + + EXPECT_EQ(poly_shifted.size(), poly.size()); + + // The shift is indeed the shift + for (size_t i = 0; i < poly_shifted.size(); ++i) { + EXPECT_EQ(poly_shifted.at(i), poly.at(i + 1)); + } + + // If I change the original polynomial, the shift is updated accordingly + poly[3] = 25; + for (size_t i = 0; i < poly_shifted.size(); ++i) { + EXPECT_EQ(poly_shifted.at(i), poly.at(i + 1)); + } +} + +// Simple test/demonstration of share functionality +TEST(SparsePolynomial, Share) +{ + using FF = bb::fr; + using Polynomial = Polynomial; + const size_t SIZE = 10; + auto poly = Polynomial::random(SIZE); + + // "clone" the poly via the share method + auto poly_clone = poly.share(); + + // The two are indeed equal + EXPECT_EQ(poly_clone, poly); + + // Changing one changes the other + poly[3] = 25; + EXPECT_EQ(poly_clone, poly); + + poly_clone[2] = 13; + EXPECT_EQ(poly_clone, poly); + + // If reset the original poly, it will no longer be equal to the clone made earlier + // Note: if we had not made a clone, the memory from the original poly would be leaked + auto poly2 = Polynomial::random(SIZE); + poly = poly2.share(); + + EXPECT_NE(poly_clone, poly); +} diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index dfda4a2a24e..451dd2609c0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -8,6 +8,7 @@ #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" @@ -30,6 +31,7 @@ class UltraFlavor { using Commitment = Curve::AffineElement; using PCS = KZG; using Polynomial = bb::Polynomial; + using SparsePolynomial = bb::SparsePolynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; @@ -232,7 +234,7 @@ class UltraFlavor { * @brief A container for polynomials handles. */ // TODO(https://github.com/AztecProtocol/barretenberg/issues/966): use inheritance - class ProverPolynomials : public AllEntities { + class ProverPolynomials : public AllEntities { public: // Define all operations as default, except copy construction/assignment ProverPolynomials() = default; @@ -240,7 +242,8 @@ class UltraFlavor { { // Initialize all unshifted polynomials to the zero polynomial and initialize the // shifted polys for (auto& poly : get_unshifted()) { - poly = Polynomial{ circuit_size }; + // WORKTODO(sparse): proper lower bound on size + poly = SparsePolynomial{ circuit_size, circuit_size }; } set_shifted(); } diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs index b55fc902214..1a29dcedbfb 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs @@ -41,7 +41,7 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: namespace bb { class {{name}}Flavor { - public: + public: using Curve = {{name}}FlavorSettings::Curve; using G1 = {{name}}FlavorSettings::G1; using PCS = {{name}}FlavorSettings::PCS; @@ -56,7 +56,7 @@ class {{name}}Flavor { using VerifierCommitmentKey = {{name}}FlavorSettings::VerifierCommitmentKey; using RelationSeparator = {{name}}FlavorSettings::RelationSeparator; - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = {{len fixed}}; + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = {{len fixed}}; static constexpr size_t NUM_WITNESS_ENTITIES = {{len witness}}; 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 @@ -138,7 +138,7 @@ class {{name}}Flavor { , public ShiftedEntities { public: DEFINE_COMPOUND_GET_ALL(PrecomputedEntities, WitnessEntities, ShiftedEntities) - + auto get_unshifted() { return concatenate(PrecomputedEntities::get_all(), WitnessEntities::get_all()); } @@ -154,7 +154,7 @@ class {{name}}Flavor { using Base = ProvingKeyAvm_, WitnessEntities, CommitmentKey>; using Base::Base; - auto get_to_be_shifted() { + auto get_to_be_shifted() { return {{name}}Flavor::get_to_be_shifted(*this); } }; @@ -174,7 +174,7 @@ class {{name}}Flavor { using BaseDataType = const FF; using DataType = BaseDataType&; - {{!-- + {{!-- We define the flavor members here again to avoid having to make this class inherit from AllEntities. If we did inherit from AllEntities, we have to define a special constructor for AllEntities, and all the classes that AllEntities inherits from, in cascade. @@ -196,7 +196,7 @@ class {{name}}Flavor { ProverPolynomials(ProverPolynomials&& o) noexcept = default; ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default; ~ProverPolynomials() = default; - + ProverPolynomials(ProvingKey& proving_key); [[nodiscard]] size_t get_polynomial_size() const { return {{witness.0}}.size(); } From df0846ebb7adb3807f1486fa1485e9dbe1fc0721 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 9 Aug 2024 16:00:42 +0000 Subject: [PATCH 02/15] More sparse poly weaving --- barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp | 1 + .../barretenberg/plonk_honk_shared/composer/composer_lib.hpp | 2 +- barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp | 2 +- .../src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 2 ++ .../cpp/src/barretenberg/translator_vm/translator_flavor.hpp | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index b57873289f4..980dd3becd9 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -31,6 +31,7 @@ class ECCVMFlavor { using FF = typename Curve::ScalarField; using BF = typename Curve::BaseField; using Polynomial = bb::Polynomial; + using SparsePolynomial = bb::SparsePolynomial; using GroupElement = typename G1::element; using Commitment = typename G1::affine_element; using CommitmentKey = bb::CommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index d4e75dc9e14..37aded22798 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -9,7 +9,7 @@ namespace bb { template -void construct_lookup_table_polynomials(RefArray table_polynomials, +void construct_lookup_table_polynomials(const RefArray& table_polynomials, const typename Flavor::CircuitBuilder& circuit, size_t dyadic_circuit_size, size_t additional_offset = 0) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index 34df96e37ed..5bb51b503e9 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -7,7 +7,6 @@ #include namespace bb { -enum class DontZeroMemory { FLAG }; /** * @brief Polynomial class that represents the coefficients 'a' of a_0 + a_1 x + a_n x^n of @@ -33,6 +32,7 @@ template class Polynomial { using iterator = Fr*; using const_iterator = Fr const*; using FF = Fr; + enum class DontZeroMemory { FLAG }; Polynomial(size_t initial_size); // Constructor that does not initialize values, use with caution to save time. diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index ec085459272..93141cfbf4a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -7,6 +7,7 @@ #include "barretenberg/honk/proof_system/types/proof.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/databus_lookup_relation.hpp" @@ -33,6 +34,7 @@ class MegaFlavor { using Commitment = Curve::AffineElement; using PCS = KZG; using Polynomial = bb::Polynomial; + using SparsePolynomial = bb::SparsePolynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 6abd04d0661..63926ecc7b8 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -32,6 +32,7 @@ class TranslatorFlavor { using FF = Curve::ScalarField; using BF = Curve::BaseField; using Polynomial = bb::Polynomial; + using SparsePolynomial = bb::SparsePolynomial; using RelationSeparator = FF; static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; From e374c7977edd53cf031affa82bc2344e139fd9e8 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 13:57:40 +0000 Subject: [PATCH 03/15] temp fork --- .../src/barretenberg/eccvm/eccvm_flavor.hpp | 1 + .../composer/composer_lib.hpp | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 980dd3becd9..29bb5d22139 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -7,6 +7,7 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/flavor/relation_definitions.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/ecc_vm/ecc_bools_relation.hpp" #include "barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 37aded22798..05e24336d79 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -38,6 +38,37 @@ void construct_lookup_table_polynomials(const RefArray +void construct_lookup_table_polynomials(const RefArray& table_polynomials, + const typename Flavor::CircuitBuilder& circuit, + size_t dyadic_circuit_size, + size_t additional_offset = 0) +{ + // Create lookup selector polynomials which interpolate each table column. + // Our selector polys always need to interpolate the full subgroup size, so here we offset so as to + // put the table column's values at the end. (The first gates are for non-lookup constraints). + // [0, ..., 0, ...table, 0, 0, 0, x] + // ^^^^^^^^^ ^^^^^^^^ ^^^^^^^ ^nonzero to ensure uniqueness and to avoid infinity commitments + // | table randomness + // ignored, as used for regular constraints and padding to the next power of 2. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace + ASSERT(dyadic_circuit_size > circuit.get_tables_size() + additional_offset); + size_t offset = dyadic_circuit_size - circuit.get_tables_size() - additional_offset; + + for (const auto& table : circuit.lookup_tables) { + const fr table_index(table.table_index); + + for (size_t i = 0; i < table.size(); ++i) { + table_polynomials[0][offset] = table.column_1[i]; + table_polynomials[1][offset] = table.column_2[i]; + table_polynomials[2][offset] = table.column_3[i]; + table_polynomials[3][offset] = table_index; + ++offset; + } + } +} + /** * @brief Construct polynomial whose value at index i is the number of times the table entry at that index has been * read. From fb7b8fb841e082ed1af1658f0b62f1dd1401a234 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 16:58:07 +0000 Subject: [PATCH 04/15] try all sparse --- .../cpp/src/barretenberg/eccvm/eccvm_flavor.hpp | 3 +-- .../plonk_honk_shared/composer/composer_lib.hpp | 10 ++++++++-- .../stdlib_circuit_builders/mega_flavor.hpp | 3 +-- .../stdlib_circuit_builders/ultra_flavor.hpp | 3 +-- .../barretenberg/translator_vm/translator_flavor.hpp | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 29bb5d22139..76e31528b28 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -31,8 +31,7 @@ class ECCVMFlavor { using PCS = IPA; using FF = typename Curve::ScalarField; using BF = typename Curve::BaseField; - using Polynomial = bb::Polynomial; - using SparsePolynomial = bb::SparsePolynomial; + using Polynomial = bb::SparsePolynomial; using GroupElement = typename G1::element; using Commitment = typename G1::affine_element; using CommitmentKey = bb::CommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 05e24336d79..1bf7b913196 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -17,6 +17,7 @@ void construct_lookup_table_polynomials(const RefArray -void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, - typename Flavor::Polynomial& read_tags, +void construct_lookup_read_counts(typename Flavor::SparsePolynomial& read_counts, + typename Flavor::SparsePolynomial& read_tags, typename Flavor::CircuitBuilder& circuit, size_t dyadic_circuit_size) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace size_t offset = dyadic_circuit_size - circuit.get_tables_size(); + // read_counts = + // typename Flavor::SparsePolynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); + // read_tags = + // typename Flavor::SparsePolynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); + // WORKTODO(sparse) circuit.get_tables_size() is the actual size of our structured polynomial; size_t table_offset = offset; // offset of the present table in the table polynomials // loop over all tables used in the circuit; each table contains data about the lookups made on it diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 93141cfbf4a..30c478f9d82 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -33,8 +33,7 @@ class MegaFlavor { using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using PCS = KZG; - using Polynomial = bb::Polynomial; - using SparsePolynomial = bb::SparsePolynomial; + using Polynomial = bb::SparsePolynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 451dd2609c0..b19d534a746 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -30,8 +30,7 @@ class UltraFlavor { using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using PCS = KZG; - using Polynomial = bb::Polynomial; - using SparsePolynomial = bb::SparsePolynomial; + using Polynomial = bb::SparsePolynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 63926ecc7b8..59a63a526ee 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -7,6 +7,7 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/flavor/relation_definitions.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/translator_vm/translator_decomposition_relation.hpp" @@ -31,8 +32,7 @@ class TranslatorFlavor { using VerifierCommitmentKey = bb::VerifierCommitmentKey; using FF = Curve::ScalarField; using BF = Curve::BaseField; - using Polynomial = bb::Polynomial; - using SparsePolynomial = bb::SparsePolynomial; + using Polynomial = bb::SparsePolynomial; using RelationSeparator = FF; static constexpr size_t MINIMUM_MINI_CIRCUIT_SIZE = 2048; From 10e1ef302bc52c2e152c8d0f69bb94a4a405c2a7 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 17:33:29 +0000 Subject: [PATCH 05/15] polynomial replacement! --- .../barretenberg/commitment_schemes/claim.hpp | 4 +-- .../commitment_key.test.hpp | 2 +- .../commitment_schemes/gemini/gemini.cpp | 2 +- .../commitment_schemes/gemini/gemini.hpp | 6 ++-- .../commitment_schemes/ipa/ipa.hpp | 4 +-- .../commitment_schemes/ipa/ipa.test.cpp | 2 +- .../commitment_schemes/kzg/kzg.hpp | 2 +- .../commitment_schemes/kzg/kzg.test.cpp | 2 +- .../commitment_schemes/shplonk/shplonk.hpp | 2 +- .../sparse_commitment.test.cpp | 4 +-- .../zeromorph/zeromorph.hpp | 6 ++-- .../zeromorph/zeromorph.test.cpp | 10 +++--- .../eccvm/eccvm_circuit_builder.hpp | 3 +- .../eccvm/eccvm_trace_checker.cpp | 2 +- .../src/barretenberg/flavor/flavor.test.cpp | 2 +- .../cpp/src/barretenberg/goblin/goblin.hpp | 1 + .../composer/composer_lib.hpp | 35 ++----------------- .../grand_product_library.test.cpp | 2 +- .../stdlib_circuit_builders/ultra_flavor.hpp | 4 +-- .../stdlib_circuit_builders/ultra_keccak.hpp | 2 +- .../relation_correctness.test.cpp | 10 +++--- .../vm/avm/generated/flavor_settings.hpp | 2 +- .../templates/flavor_settings.hpp.hbs | 2 +- 23 files changed, 41 insertions(+), 70 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp index 61f32b8d6d1..075d030416d 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/commitment_schemes/commitment_key.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" namespace bb { /** @@ -26,7 +26,7 @@ template class OpeningPair { */ template class ProverOpeningClaim { using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; public: Polynomial polynomial; // p diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp index e91b61bbad5..d5eac6bb30f 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp @@ -61,7 +61,7 @@ template class CommitmentTest : public ::testing::Test { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; public: CommitmentTest() diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.cpp index 19e815f8ab5..4422abdee0d 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.cpp @@ -53,7 +53,7 @@ namespace bb { * @return std::vector */ template -std::vector> GeminiProver_::compute_gemini_polynomials( +std::vector::Polynomial> GeminiProver_::compute_gemini_polynomials( std::span mle_opening_point, Polynomial&& batched_unshifted, Polynomial&& batched_to_be_shifted) { const size_t num_variables = mle_opening_point.size(); // m diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp index 94fbd5c43c7..5ac133f41d0 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp @@ -1,7 +1,7 @@ #pragma once #include "../claim.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include @@ -59,7 +59,7 @@ namespace bb { */ template struct GeminiProverOutput { std::vector> opening_pairs; - std::vector> witnesses; + std::vector> witnesses; }; namespace gemini { @@ -101,7 +101,7 @@ template inline std::vector squares_of_r(const Fr r, const size_t template class GeminiProver_ { using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; public: static std::vector compute_gemini_polynomials(std::span mle_opening_point, diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp index 0fcc7c65841..6035289000f 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp @@ -79,7 +79,7 @@ template class IPA { using Commitment = typename Curve::AffineElement; using CK = CommitmentKey; using VK = VerifierCommitmentKey; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using VerifierAccumulator = bool; // These allow access to internal functions so that we can never use a mock transcript unless it's fuzzing or testing of IPA specifically @@ -127,7 +127,7 @@ template class IPA { * 7. Compute \f$\vec{b}_{i-1}=\vec{b}_{i\_low}+u_{i-1}^{-1}\cdot \vec{b}_{i\_high}\f$​ * *7. Send the final \f$\vec{a}_{0} = (a_0)\f$ to the verifier - */ + */ template static void compute_opening_proof_internal(const std::shared_ptr& ck, const ProverOpeningClaim& opening_claim, diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp index db8a2597a5b..69ae8239096 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp @@ -22,7 +22,7 @@ class IPATest : public CommitmentTest { using GroupElement = typename Curve::Element; using CK = CommitmentKey; using VK = VerifierCommitmentKey; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; }; } // namespace diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp index 1c403dc22cc..2ff3ed5480b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp @@ -19,7 +19,7 @@ template class KZG { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; using GroupElement = typename Curve::Element; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using VerifierAccumulator = std::array; /** diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp index 5dd1fa892c4..c0acae1abcf 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -19,7 +19,7 @@ template class KZGTest : public CommitmentTest { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; using GroupElement = typename Curve::Element; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; }; TYPED_TEST_SUITE(KZGTest, CommitmentSchemeParams); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp index 9eac7b4a48c..32746eb049e 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp @@ -27,7 +27,7 @@ namespace bb { */ template class ShplonkProver_ { using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; public: /** diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp index f555d437d08..dd586f7b0c8 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp @@ -11,7 +11,7 @@ template class CommitmentKeyTest : public ::testing::Test { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; public: template inline std::shared_ptr create_commitment_key(size_t num_points); @@ -46,7 +46,7 @@ TYPED_TEST(CommitmentKeyTest, CommitSparse) using CK = CommitmentKey; using G1 = Curve::AffineElement; using Fr = Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; const size_t num_points = 1 << 12; // large enough to ensure normal pippenger logic is used const size_t num_nonzero = 7; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp index 4f66c019c89..7056d3b1146 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp @@ -5,7 +5,7 @@ #include "barretenberg/common/ref_span.hpp" #include "barretenberg/common/ref_vector.hpp" #include "barretenberg/common/zip_view.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" #include "barretenberg/transcript/transcript.hpp" @@ -38,7 +38,7 @@ template inline std::vector powers_of_challenge(const FF challeng template class ZeroMorphProver_ { using FF = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using OpeningClaim = ProverOpeningClaim; // TODO(#742): Set this N_max to be the number of G1 elements in the mocked zeromorph SRS once it's in place. @@ -90,7 +90,7 @@ template class ZeroMorphProver_ { std::vector f_k; f_k.resize(size_q); - std::vector g(polynomial.data().get(), polynomial.data().get() + size_q); + std::vector g(polynomial.data(), polynomial.data() + size_q); // Compute q_k in reverse order from k= n-2, i.e. q_{n-2}, ..., q_0 for (size_t k = 1; k < log_N; ++k) { diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp index 146ce53b461..85393c785bd 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp @@ -10,7 +10,7 @@ template class ZeroMorphTest : public CommitmentTest; + using Polynomial = bb::SparsePolynomial; using Commitment = typename Curve::AffineElement; using GroupElement = typename Curve::Element; using VerifierAccumulator = typename PCS::VerifierAccumulator; @@ -326,7 +326,7 @@ TYPED_TEST(ZeroMorphTest, QuotientConstruction) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; // Define size parameters size_t N = 16; @@ -374,7 +374,7 @@ TYPED_TEST(ZeroMorphTest, BatchedLiftedDegreeQuotient) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; const size_t N = 8; @@ -419,7 +419,7 @@ TYPED_TEST(ZeroMorphTest, PartiallyEvaluatedQuotientZeta) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; const size_t N = 8; @@ -503,7 +503,7 @@ TYPED_TEST(ZeroMorphTest, PartiallyEvaluatedQuotientZ) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; const size_t N = 8; size_t log_N = numeric::get_msb(N); diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp index 815659ee3aa..6c3a495fd71 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp @@ -8,6 +8,7 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/stdlib_circuit_builders/op_queue/ecc_op_queue.hpp" @@ -17,7 +18,7 @@ class ECCVMCircuitBuilder { public: using CycleGroup = bb::g1; using FF = grumpkin::fr; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using CycleScalar = typename CycleGroup::subgroup_field; using Element = typename CycleGroup::element; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp index 65c99f076ae..772188086ce 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp @@ -34,7 +34,7 @@ bool ECCVMTraceChecker::check(Builder& builder, numeric::RNG* engine_ptr) compute_logderivative_inverse>(polynomials, params, num_rows); compute_grand_product>(polynomials, params); - polynomials.z_perm_shift = Polynomial(polynomials.z_perm.shifted()); + polynomials.z_perm_shift = SparsePolynomial(polynomials.z_perm.shifted()); const auto evaluate_relation = [&](const std::string& relation_name) { typename Relation::SumcheckArrayOfValuesOverSubrelations result; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 06d24472a9a..3817cf660c1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -47,7 +47,7 @@ TEST(Flavor, AllEntitiesSpecialMemberFunctions) using Flavor = UltraFlavor; using FF = Flavor::FF; using PartiallyEvaluatedMultivariates = Flavor::PartiallyEvaluatedMultivariates; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; PartiallyEvaluatedMultivariates polynomials_A; auto random_poly = Polynomial(10); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index e9a073d559e..36be5bde8bb 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -7,6 +7,7 @@ #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/goblin/types.hpp" #include "barretenberg/plonk_honk_shared/instance_inspector.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/stdlib/honk_recursion/verifier/merge_recursive_verifier.hpp" #include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp" diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 1bf7b913196..c9e403baeb0 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -8,37 +8,6 @@ namespace bb { -template -void construct_lookup_table_polynomials(const RefArray& table_polynomials, - const typename Flavor::CircuitBuilder& circuit, - size_t dyadic_circuit_size, - size_t additional_offset = 0) -{ - // Create lookup selector polynomials which interpolate each table column. - // Our selector polys always need to interpolate the full subgroup size, so here we offset so as to - // put the table column's values at the end. (The first gates are for non-lookup constraints). - // WORKTODO(sparse) comment that this is just for plonk - // [0, ..., 0, ...table, 0, 0, 0, x] - // ^^^^^^^^^ ^^^^^^^^ ^^^^^^^ ^nonzero to ensure uniqueness and to avoid infinity commitments - // | table randomness - // ignored, as used for regular constraints and padding to the next power of 2. - // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace - ASSERT(dyadic_circuit_size > circuit.get_tables_size() + additional_offset); - size_t offset = dyadic_circuit_size - circuit.get_tables_size() - additional_offset; - - for (const auto& table : circuit.lookup_tables) { - const fr table_index(table.table_index); - - for (size_t i = 0; i < table.size(); ++i) { - table_polynomials[0][offset] = table.column_1[i]; - table_polynomials[1][offset] = table.column_2[i]; - table_polynomials[2][offset] = table.column_3[i]; - table_polynomials[3][offset] = table_index; - ++offset; - } - } -} - // TODO temporary fork WORKTODO(sparse) template void construct_lookup_table_polynomials(const RefArray& table_polynomials, @@ -78,8 +47,8 @@ void construct_lookup_table_polynomials(const RefArray -void construct_lookup_read_counts(typename Flavor::SparsePolynomial& read_counts, - typename Flavor::SparsePolynomial& read_tags, +void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, + typename Flavor::Polynomial& read_tags, typename Flavor::CircuitBuilder& circuit, size_t dyadic_circuit_size) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp index 0bf80a8db8c..d2e24289361 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp @@ -10,7 +10,7 @@ using namespace bb; template class GrandProductTests : public testing::Test { - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; public: void SetUp() { srs::init_crs_factory("../srs_db/ignition"); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index b19d534a746..857f91dda29 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -233,7 +233,7 @@ class UltraFlavor { * @brief A container for polynomials handles. */ // TODO(https://github.com/AztecProtocol/barretenberg/issues/966): use inheritance - class ProverPolynomials : public AllEntities { + class ProverPolynomials : public AllEntities { public: // Define all operations as default, except copy construction/assignment ProverPolynomials() = default; @@ -242,7 +242,7 @@ class UltraFlavor { // shifted polys for (auto& poly : get_unshifted()) { // WORKTODO(sparse): proper lower bound on size - poly = SparsePolynomial{ circuit_size, circuit_size }; + poly = Polynomial{ circuit_size }; } set_shifted(); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index 30db8636251..0827776c0d5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -30,7 +30,7 @@ class UltraKeccakFlavor { using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using PCS = KZG; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp index 14336957ea7..528021668f6 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp @@ -43,7 +43,7 @@ TEST_F(TranslatorRelationCorrectnessTests, Permutation) using Flavor = TranslatorFlavor; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; auto& engine = numeric::get_debug_randomness(); const size_t mini_circuit_size = 2048; auto full_circuit_size = mini_circuit_size * Flavor::CONCATENATION_GROUP_SIZE; @@ -160,7 +160,7 @@ TEST_F(TranslatorRelationCorrectnessTests, DeltaRangeConstraint) using Flavor = TranslatorFlavor; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; auto& engine = numeric::get_debug_randomness(); const size_t mini_circuit_size = 2048; const auto circuit_size = Flavor::CONCATENATION_GROUP_SIZE * mini_circuit_size; @@ -241,7 +241,7 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness) using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; auto& engine = numeric::get_debug_randomness(); @@ -344,7 +344,7 @@ TEST_F(TranslatorRelationCorrectnessTests, Decomposition) using BF = typename Flavor::BF; using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; auto& engine = numeric::get_debug_randomness(); constexpr size_t mini_circuit_size = 2048; @@ -719,7 +719,7 @@ TEST_F(TranslatorRelationCorrectnessTests, NonNative) using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; using GroupElement = typename Flavor::GroupElement; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; constexpr size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS; constexpr auto mini_circuit_size = 2048; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp index 98b3085f4ff..b62a8641eee 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp @@ -16,7 +16,7 @@ class AvmFlavorSettings { using PCS = KZG; using FF = G1::subgroup_field; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using PolynomialHandle = std::span; using GroupElement = G1::element; using Commitment = G1::affine_element; diff --git a/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs index 93039d496a5..2d6d37748fe 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs @@ -16,7 +16,7 @@ class {{name}}FlavorSettings { using PCS = KZG; using FF = G1::subgroup_field; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using PolynomialHandle = std::span; using GroupElement = G1::element; using Commitment = G1::affine_element; From a5e2b3a963190fc20d8e3015784b201909842e99 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 17:35:14 +0000 Subject: [PATCH 06/15] tests --- .../protogalaxy/protogalaxy.test.cpp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 474391a6f19..828405b676f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -28,10 +28,10 @@ template class ProtoGalaxyTests : public testing::Test { using Builder = typename Flavor::CircuitBuilder; using Polynomial = typename Flavor::Polynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; - using RelationParameters = bb::RelationParameters; + using RelationParameters = RelationParameters; using WitnessCommitments = typename Flavor::WitnessCommitments; using CommitmentKey = typename Flavor::CommitmentKey; - using PowPolynomial = bb::PowPolynomial; + using PowPolynomial = PowPolynomial; using DeciderProver = DeciderProver_; using DeciderVerifier = DeciderVerifier_; using FoldingProver = ProtoGalaxyProver_; @@ -40,7 +40,7 @@ template class ProtoGalaxyTests : public testing::Test { using TupleOfInstances = std::tuple>, std::vector>>; - static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } + static void SetUpTestSuite() { srs::init_crs_factory("../srs_db/ignition"); } static void construct_circuit(Builder& builder) { @@ -185,10 +185,10 @@ template class ProtoGalaxyTests : public testing::Test { // Construct fully random prover polynomials ProverPolynomials full_polynomials; for (auto& poly : full_polynomials.get_all()) { - poly = bb::Polynomial::random(instance_size); + poly = SparsePolynomial::random(instance_size); } - auto relation_parameters = bb::RelationParameters::get_random(); + auto relation_parameters = RelationParameters::get_random(); RelationSeparator alphas; for (auto& alpha : alphas) { alpha = FF::random_element(); @@ -202,7 +202,7 @@ template class ProtoGalaxyTests : public testing::Test { } // Construct pow(\vec{betas}) as in the paper - auto pow_beta = bb::PowPolynomial(betas); + auto pow_beta = PowPolynomial(betas); pow_beta.compute_values(); // Compute the corresponding target sum and create a dummy accumulator @@ -233,12 +233,12 @@ template class ProtoGalaxyTests : public testing::Test { static void test_combiner_quotient() { auto compressed_perturbator = FF(2); // F(\alpha) in the paper - auto combiner = bb::Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); + auto combiner = Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); auto combiner_quotient = ProtoGalaxyProver::compute_combiner_quotient(compressed_perturbator, combiner); // K(i) = (G(i) - ( L_0(i) * F(\alpha)) / Z(i), i = {2,.., 13} for ProverInstances::NUM = 2 // K(i) = (G(i) - (1 - i) * F(\alpha)) / i * (i - 1) - auto expected_evals = bb::Univariate(std::array{ + auto expected_evals = Univariate(std::array{ (FF(22) - (FF(1) - FF(2)) * compressed_perturbator) / (FF(2) * FF(2 - 1)), (FF(23) - (FF(1) - FF(3)) * compressed_perturbator) / (FF(3) * FF(3 - 1)), (FF(24) - (FF(1) - FF(4)) * compressed_perturbator) / (FF(4) * FF(4 - 1)), @@ -275,7 +275,7 @@ template class ProtoGalaxyTests : public testing::Test { ProverInstances instances{ { instance1, instance2 } }; ProtoGalaxyProver::combine_relation_parameters(instances); - bb::Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } }; + Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } }; EXPECT_EQ(instances.relation_parameters.eta, expected_eta); // Optimised relation parameters are the same, we just don't compute any values for non-used indices when // deriving values from them @@ -302,7 +302,7 @@ template class ProtoGalaxyTests : public testing::Test { ProverInstances instances{ { instance1, instance2 } }; ProtoGalaxyProver::combine_alpha(instances); - bb::Univariate expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } }; + Univariate expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } }; for (const auto& alpha : instances.alphas) { EXPECT_EQ(alpha, expected_alpha); } @@ -338,7 +338,7 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add some arithmetic gates - bb::MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4); + MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4); check_fold_and_decide(builder1, builder2); } @@ -352,7 +352,7 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add some arithmetic gates with public inputs to the first circuit - bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); + MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); check_fold_and_decide(builder1, builder2); } @@ -366,8 +366,8 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add a different number of lookup gates to each circuit - bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table - bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table + MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table + MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table check_fold_and_decide(builder1, builder2); } @@ -386,8 +386,8 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add a different number of lookup gates to each circuit - bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table - bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table + MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table + MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table // Erroneously set a non-zero wire value to zero in one of the lookup gates for (auto& wire_3_witness_idx : builder1.blocks.lookup.w_o()) { From c2c70733235d1f23cd48b5613f143577120de9b2 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 17:53:14 +0000 Subject: [PATCH 07/15] all targets building --- .../benchmark/ipa_bench/ipa.bench.cpp | 4 ++- .../commitment_schemes/gemini/gemini.test.cpp | 4 +-- .../commitment_schemes/kzg/kzg.test.cpp | 2 +- .../sparse_commitment.test.cpp | 2 +- .../zeromorph.test.cpp | 2 +- .../src/barretenberg/flavor/flavor.test.cpp | 2 +- .../polynomials/sparse_polynomial.hpp | 2 ++ .../protogalaxy/protogalaxy.test.cpp | 32 ++++++++--------- .../barretenberg/sumcheck/sumcheck.test.cpp | 36 ++++++++++--------- 9 files changed, 46 insertions(+), 40 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp index fac0f30f3b5..d6a486b27ff 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp @@ -1,4 +1,5 @@ #include "barretenberg/commitment_schemes/ipa/ipa.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include using namespace benchmark; @@ -7,6 +8,7 @@ using namespace bb; namespace { using Curve = curve::Grumpkin; using Fr = Curve::ScalarField; +using Polynomial = SparsePolynomial; constexpr size_t MIN_POLYNOMIAL_DEGREE_LOG2 = 10; constexpr size_t MAX_POLYNOMIAL_DEGREE_LOG2 = 16; @@ -31,7 +33,7 @@ void ipa_open(State& state) noexcept state.PauseTiming(); size_t n = 1 << static_cast(state.range(0)); // Construct the polynomial - Polynomial poly(n); + Polynomial poly(n); for (size_t i = 0; i < n; ++i) { poly[i] = Fr::random_element(&engine); } diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp index 7e378bba250..2f5e04d3c3f 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp @@ -1,7 +1,7 @@ #include "gemini.hpp" #include "../commitment_key.test.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include #include @@ -14,7 +14,7 @@ template class GeminiTest : public CommitmentTest { using GeminiVerifier = GeminiVerifier_; using Fr = typename Curve::ScalarField; using GroupElement = typename Curve::Element; - using Polynomial = typename bb::Polynomial; + using Polynomial = typename bb::SparsePolynomial; public: void execute_gemini_and_verify_claims(size_t log_n, diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp index c0acae1abcf..e26cdac79a1 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -64,7 +64,7 @@ TYPED_TEST(KZGTest, GeminiShplonkKzgWithShift) using KZG = KZG; using Fr = typename TypeParam::ScalarField; using GroupElement = typename TypeParam::Element; - using Polynomial = typename bb::Polynomial; + using Polynomial = typename bb::SparsePolynomial; const size_t n = 16; const size_t log_n = 4; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp index dd586f7b0c8..728ecfee7cf 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp @@ -1,5 +1,5 @@ #include "barretenberg/commitment_schemes/commitment_key.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp index 93cfbc82d89..fe6847e7476 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp @@ -36,7 +36,7 @@ TEST(ZeroMorphRecursionTest, ProveAndVerifySingle) using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; using NativeFr = typename Curve::NativeCurve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::SparsePolynomial; using ZeroMorphVerifier = ZeroMorphVerifier_; using Transcript = bb::BaseTranscript>; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 3817cf660c1..446596965f7 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -78,7 +78,7 @@ TEST(Flavor, GetRow) }); Flavor::ProverPolynomials prover_polynomials; for (auto [poly, entry] : zip_view(prover_polynomials.get_all(), data)) { - poly = entry; + poly = Flavor::Polynomial(entry); } auto row0 = prover_polynomials.get_row(0); auto row1 = prover_polynomials.get_row(1); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp index c62395b44b5..e655c08ead5 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp @@ -234,6 +234,8 @@ template class SparsePolynomial { return coefficients_.data()[i]; } + static SparsePolynomial random(size_t size) { return random(size, size); } + static SparsePolynomial random(size_t size, size_t virtual_size) { SparsePolynomial p(size, virtual_size, DontZeroMemory::FLAG); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 828405b676f..4ee685df09e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -28,10 +28,10 @@ template class ProtoGalaxyTests : public testing::Test { using Builder = typename Flavor::CircuitBuilder; using Polynomial = typename Flavor::Polynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; - using RelationParameters = RelationParameters; + using RelationParameters = bb::RelationParameters; using WitnessCommitments = typename Flavor::WitnessCommitments; using CommitmentKey = typename Flavor::CommitmentKey; - using PowPolynomial = PowPolynomial; + using PowPolynomial = bb::PowPolynomial; using DeciderProver = DeciderProver_; using DeciderVerifier = DeciderVerifier_; using FoldingProver = ProtoGalaxyProver_; @@ -40,7 +40,7 @@ template class ProtoGalaxyTests : public testing::Test { using TupleOfInstances = std::tuple>, std::vector>>; - static void SetUpTestSuite() { srs::init_crs_factory("../srs_db/ignition"); } + static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } static void construct_circuit(Builder& builder) { @@ -185,10 +185,10 @@ template class ProtoGalaxyTests : public testing::Test { // Construct fully random prover polynomials ProverPolynomials full_polynomials; for (auto& poly : full_polynomials.get_all()) { - poly = SparsePolynomial::random(instance_size); + poly = bb::SparsePolynomial::random(instance_size); } - auto relation_parameters = RelationParameters::get_random(); + auto relation_parameters = bb::RelationParameters::get_random(); RelationSeparator alphas; for (auto& alpha : alphas) { alpha = FF::random_element(); @@ -202,7 +202,7 @@ template class ProtoGalaxyTests : public testing::Test { } // Construct pow(\vec{betas}) as in the paper - auto pow_beta = PowPolynomial(betas); + auto pow_beta = bb::PowPolynomial(betas); pow_beta.compute_values(); // Compute the corresponding target sum and create a dummy accumulator @@ -233,12 +233,12 @@ template class ProtoGalaxyTests : public testing::Test { static void test_combiner_quotient() { auto compressed_perturbator = FF(2); // F(\alpha) in the paper - auto combiner = Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); + auto combiner = bb::Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); auto combiner_quotient = ProtoGalaxyProver::compute_combiner_quotient(compressed_perturbator, combiner); // K(i) = (G(i) - ( L_0(i) * F(\alpha)) / Z(i), i = {2,.., 13} for ProverInstances::NUM = 2 // K(i) = (G(i) - (1 - i) * F(\alpha)) / i * (i - 1) - auto expected_evals = Univariate(std::array{ + auto expected_evals = bb::Univariate(std::array{ (FF(22) - (FF(1) - FF(2)) * compressed_perturbator) / (FF(2) * FF(2 - 1)), (FF(23) - (FF(1) - FF(3)) * compressed_perturbator) / (FF(3) * FF(3 - 1)), (FF(24) - (FF(1) - FF(4)) * compressed_perturbator) / (FF(4) * FF(4 - 1)), @@ -275,7 +275,7 @@ template class ProtoGalaxyTests : public testing::Test { ProverInstances instances{ { instance1, instance2 } }; ProtoGalaxyProver::combine_relation_parameters(instances); - Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } }; + bb::Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } }; EXPECT_EQ(instances.relation_parameters.eta, expected_eta); // Optimised relation parameters are the same, we just don't compute any values for non-used indices when // deriving values from them @@ -302,7 +302,7 @@ template class ProtoGalaxyTests : public testing::Test { ProverInstances instances{ { instance1, instance2 } }; ProtoGalaxyProver::combine_alpha(instances); - Univariate expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } }; + bb::Univariate expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } }; for (const auto& alpha : instances.alphas) { EXPECT_EQ(alpha, expected_alpha); } @@ -338,7 +338,7 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add some arithmetic gates - MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4); + bb::MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4); check_fold_and_decide(builder1, builder2); } @@ -352,7 +352,7 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add some arithmetic gates with public inputs to the first circuit - MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); + bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); check_fold_and_decide(builder1, builder2); } @@ -366,8 +366,8 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add a different number of lookup gates to each circuit - MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table - MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table + bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table + bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table check_fold_and_decide(builder1, builder2); } @@ -386,8 +386,8 @@ template class ProtoGalaxyTests : public testing::Test { construct_circuit(builder2); // Add a different number of lookup gates to each circuit - MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table - MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table + bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table + bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table // Erroneously set a non-zero wire value to zero in one of the lookup gates for (auto& wire_3_witness_idx : builder1.blocks.lookup.w_o()) { diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index bfc9b0facac..0164f1b5f11 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -1,5 +1,6 @@ #include "sumcheck.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" @@ -15,13 +16,14 @@ using namespace bb; namespace { using Flavor = UltraFlavor; using FF = typename Flavor::FF; +using Polynomial = SparsePolynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; using RelationSeparator = Flavor::RelationSeparator; const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; -Polynomial random_poly(size_t size) +Polynomial random_poly(size_t size) { - auto poly = bb::Polynomial(size); + auto poly = Polynomial(size); for (auto& coeff : poly) { coeff = FF::random_element(); } @@ -51,7 +53,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -114,7 +116,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // full polynomials at challenge u via the evaluate_mle() function std::vector u_challenge = { u_0, u_1, u_2 }; for (auto [full_poly, claimed_eval] : zip_view(full_polynomials.get_all(), output.claimed_evaluations.get_all())) { - Polynomial poly(full_poly); + SparsePolynomial poly(full_poly); auto v_expected = poly.evaluate_mle(u_challenge); EXPECT_EQ(v_expected, claimed_eval); } @@ -127,7 +129,7 @@ TEST_F(SumcheckTests, Prover) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -174,9 +176,9 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) // Construct prover polynomials where each is the zero polynomial. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> zero_polynomials; + std::array, NUM_POLYNOMIALS> zero_polynomials; for (auto& poly : zero_polynomials) { - poly = Polynomial(multivariate_n); + poly = SparsePolynomial(multivariate_n); } auto full_polynomials = construct_ultra_full_polynomials(zero_polynomials); @@ -199,16 +201,16 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) std::array q_arith = { 0, 1, 1, 0 }; // Setting all of these to 0 ensures the GrandProductRelation is satisfied - full_polynomials.w_l = w_l; - full_polynomials.w_r = w_r; - full_polynomials.w_o = w_o; - full_polynomials.w_4 = w_4; - full_polynomials.q_m = q_m; - full_polynomials.q_l = q_l; - full_polynomials.q_r = q_r; - full_polynomials.q_o = q_o; - full_polynomials.q_c = q_c; - full_polynomials.q_arith = q_arith; + full_polynomials.w_l = SparsePolynomial(w_l); + full_polynomials.w_r = SparsePolynomial(w_r); + full_polynomials.w_o = SparsePolynomial(w_o); + full_polynomials.w_4 = SparsePolynomial(w_4); + full_polynomials.q_m = SparsePolynomial(q_m); + full_polynomials.q_l = SparsePolynomial(q_l); + full_polynomials.q_r = SparsePolynomial(q_r); + full_polynomials.q_o = SparsePolynomial(q_o); + full_polynomials.q_c = SparsePolynomial(q_c); + full_polynomials.q_arith = SparsePolynomial(q_arith); // Set aribitrary random relation parameters RelationParameters relation_parameters{ From d641a137e77958a92dd1f6d6ea3e9ef337273f58 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 18:57:47 +0000 Subject: [PATCH 08/15] Plonk polynomial class => legacy polynomial --- .../benchmark/basics_bench/basics.bench.cpp | 2 +- .../barretenberg/commitment_schemes/claim.hpp | 2 +- .../commitment_schemes/commit.bench.cpp | 12 +-- .../commitment_schemes/commitment_key.hpp | 2 +- .../commitment_key.test.hpp | 2 +- .../commitment_schemes/ipa/ipa.fuzzer.cpp | 2 +- .../commitment_schemes/ipa/ipa.test.cpp | 2 +- .../commitment_schemes/kzg/kzg.hpp | 2 +- .../commitment_schemes/kzg/kzg.test.cpp | 2 +- .../shplonk/shplonk.test.cpp | 2 +- .../commitment_schemes/verification_key.hpp | 2 +- .../eccvm/eccvm_composer.test.cpp | 2 +- .../src/barretenberg/eccvm/eccvm_prover.cpp | 2 +- .../src/barretenberg/flavor/flavor.test.cpp | 2 +- .../src/barretenberg/flavor/plonk_flavors.hpp | 4 +- .../honk/proof_system/permutation_library.hpp | 2 +- .../src/barretenberg/honk/utils/testing.hpp | 2 +- .../plonk/composer/standard_composer.cpp | 2 +- .../commitment_scheme/commitment_scheme.hpp | 2 +- .../commitment_scheme.test.cpp | 2 +- .../plonk/proof_system/prover/prover.cpp | 2 +- .../proof_system/proving_key/proving_key.hpp | 2 +- .../utils/generalized_permutation.hpp | 2 +- .../plonk/proof_system/utils/permutation.hpp | 2 +- .../permutation_widget_impl.hpp | 2 +- .../plonk/work_queue/work_queue.cpp | 2 +- .../composer/permutation_lib.hpp | 9 +- .../library/grand_product_library.hpp | 2 +- .../{polynomial.cpp => legacy_polynomial.cpp} | 102 +++++++++--------- .../{polynomial.hpp => legacy_polynomial.hpp} | 50 ++++----- ...al.test.cpp => legacy_polynomial.test.cpp} | 6 +- ...bench.cpp => legacy_polynomials.bench.cpp} | 0 .../polynomial_arithmetic.test.cpp | 32 +++--- .../polynomials/polynomial_store.cpp | 4 +- .../polynomials/polynomial_store.hpp | 4 +- .../polynomials/polynomial_store.test.cpp | 18 ++-- .../polynomials/polynomial_store_cache.hpp | 4 +- .../polynomials/polynomial_store_wasm.cpp | 4 +- .../polynomials/polynomial_store_wasm.hpp | 4 +- .../barretenberg/polynomials/serialize.hpp | 2 +- .../polynomials/sparse_polynomial.test.cpp | 6 +- .../protogalaxy/protogalaxy_prover.hpp | 8 +- .../protogalaxy/protogalaxy_prover_impl.hpp | 3 +- .../protogalaxy/protogalaxy_verifier.cpp | 2 +- .../relations/databus_lookup_relation.hpp | 2 +- .../relations/ecc_vm/ecc_lookup_relation.hpp | 2 +- .../relations/ecc_vm/ecc_set_relation.hpp | 2 +- .../generic_lookup_relation.hpp | 2 +- .../generic_permutation_relation.hpp | 2 +- .../relations/logderiv_lookup_relation.hpp | 2 +- .../protogalaxy_recursive_verifier.cpp | 2 +- .../protogalaxy_recursive_verifier.test.cpp | 2 +- .../grand_product_library.test.cpp | 2 +- .../mega_recursive_flavor.hpp | 2 +- .../ultra_circuit_builder.hpp | 2 +- .../stdlib_circuit_builders/ultra_flavor.hpp | 2 +- .../stdlib_circuit_builders/ultra_keccak.hpp | 2 +- .../ultra_recursive_flavor.hpp | 2 +- .../barretenberg/vm/avm/generated/flavor.hpp | 2 +- .../barretenberg/vm/avm/generated/prover.cpp | 2 +- .../vm/avm/generated/verifier.cpp | 2 +- .../bb-pil-backend/templates/flavor.hpp.hbs | 2 +- .../bb-pil-backend/templates/prover.cpp.hbs | 2 +- .../bb-pil-backend/templates/verifier.cpp.hbs | 2 +- 64 files changed, 185 insertions(+), 179 deletions(-) rename barretenberg/cpp/src/barretenberg/polynomials/{polynomial.cpp => legacy_polynomial.cpp} (77%) rename barretenberg/cpp/src/barretenberg/polynomials/{polynomial.hpp => legacy_polynomial.hpp} (89%) rename barretenberg/cpp/src/barretenberg/polynomials/{polynomial.test.cpp => legacy_polynomial.test.cpp} (91%) rename barretenberg/cpp/src/barretenberg/polynomials/{polynomials.bench.cpp => legacy_polynomials.bench.cpp} (100%) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp index a4cd2917cd0..f8563de10a0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp @@ -452,7 +452,7 @@ void pippenger(State& state) for (auto _ : state) { state.PauseTiming(); size_t num_cycles = 1 << static_cast(state.range(0)); - Polynomial pol(num_cycles); + LegacyPolynomial pol(num_cycles); for (size_t i = 0; i < num_cycles; i++) { *(uint256_t*)&pol[i] = engine.get_random_uint256(); pol[i].self_reduce_once(); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp index 075d030416d..2a6b6414dbf 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp @@ -59,7 +59,7 @@ template class OpeningClaim { * @param polynomial the claimed witness polynomial p(X) * @return C = Commit(p(X)) && p(r) = v */ - bool verify(std::shared_ptr ck, const bb::Polynomial& polynomial) const + bool verify(std::shared_ptr ck, const bb::LegacyPolynomial& polynomial) const { Fr real_eval = polynomial.evaluate(opening_pair.challenge); if (real_eval != opening_pair.evaluation) { diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp index 88a27cd1b6c..31e30998ead 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp @@ -13,10 +13,10 @@ template std::shared_ptr> create_commitmen } // Generate a polynomial with a specified number of nonzero random coefficients -template Polynomial sparse_random_poly(const size_t size, const size_t num_nonzero) +template LegacyPolynomial sparse_random_poly(const size_t size, const size_t num_nonzero) { auto& engine = numeric::get_debug_randomness(); - auto polynomial = Polynomial(size); + auto polynomial = LegacyPolynomial(size); for (size_t i = 0; i < num_nonzero; i++) { size_t idx = engine.get_random_uint32() % size; @@ -37,7 +37,7 @@ template void bench_commit_zero(::benchmark::State& state) auto key = create_commitment_key(MAX_NUM_POINTS); const size_t num_points = 1 << state.range(0); - const auto polynomial = Polynomial(num_points); + const auto polynomial = LegacyPolynomial(num_points); for (auto _ : state) { key->commit(polynomial); } @@ -52,7 +52,7 @@ template void bench_commit_sparse(::benchmark::State& state) const size_t num_points = 1 << state.range(0); const size_t num_nonzero = SPARSE_NUM_NONZERO; - auto polynomial = Polynomial(num_points); + auto polynomial = LegacyPolynomial(num_points); for (size_t i = 0; i < num_nonzero; i++) { polynomial[i] = 1; } @@ -71,7 +71,7 @@ template void bench_commit_sparse_preprocessed(::benchmark::Sta const size_t num_points = 1 << state.range(0); const size_t num_nonzero = SPARSE_NUM_NONZERO; - auto polynomial = Polynomial(num_points); + auto polynomial = LegacyPolynomial(num_points); for (size_t i = 0; i < num_nonzero; i++) { polynomial[i] = 1; } @@ -120,7 +120,7 @@ template void bench_commit_random(::benchmark::State& state) auto key = create_commitment_key(MAX_NUM_POINTS); const size_t num_points = 1 << state.range(0); - auto polynomial = Polynomial(num_points); + auto polynomial = LegacyPolynomial(num_points); for (auto& coeff : polynomial) { coeff = Fr::random_element(); } diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index c6b23b071e7..16925a4ea1b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -10,7 +10,7 @@ #include "barretenberg/common/op_count.hpp" #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" #include "barretenberg/numeric/bitop/pow.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp index d5eac6bb30f..f593dbbe706 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp @@ -3,7 +3,7 @@ #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include "claim.hpp" diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp index df6c3ec3115..65af51fea62 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp @@ -3,7 +3,7 @@ #include "./mock_transcript.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp index 69ae8239096..a4394f52ae3 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp @@ -6,7 +6,7 @@ #include "barretenberg/common/mem.hpp" #include "barretenberg/ecc/curves/bn254/fq12.hpp" #include "barretenberg/ecc/curves/types.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp index 2ff3ed5480b..99503cf410a 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp @@ -3,7 +3,7 @@ #include "../claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp index e26cdac79a1..eb296da12f3 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -5,7 +5,7 @@ #include "../commitment_key.test.hpp" #include "barretenberg/commitment_schemes/claim.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp index 299ee846a2a..606f2e3cc6b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp @@ -9,7 +9,7 @@ #include "../commitment_key.test.hpp" #include "barretenberg/commitment_schemes/claim.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb { template class ShplonkTest : public CommitmentTest {}; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp index 909a40cd439..fd455e1f0f8 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp @@ -11,7 +11,7 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" #include "barretenberg/numeric/bitop/pow.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "barretenberg/srs/global_crs.hpp" diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp index c3ae908ff71..04c49f70e5b 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp @@ -8,7 +8,7 @@ #include "barretenberg/eccvm/eccvm_verifier.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/sumcheck_round.hpp" diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp index 830eb760683..d008388a869 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp @@ -6,7 +6,7 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 446596965f7..54ebf6c4a25 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/flavor/plonk_flavors.hpp b/barretenberg/cpp/src/barretenberg/flavor/plonk_flavors.hpp index bad2062b805..c215edb0695 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/plonk_flavors.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/plonk_flavors.hpp @@ -12,7 +12,7 @@ class Standard { using ProvingKey = plonk::proving_key; using Curve = curve::BN254; using FF = Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::LegacyPolynomial; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // Whether or not the first row of the execution trace is reserved for 0s to enable shifts static constexpr bool has_zero_row = false; @@ -24,7 +24,7 @@ class Ultra { using ProvingKey = plonk::proving_key; using Curve = curve::BN254; using FF = Curve::ScalarField; - using Polynomial = bb::Polynomial; + using Polynomial = bb::LegacyPolynomial; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // Whether or not the first row of the execution trace is reserved for 0s to enable shifts static constexpr bool has_zero_row = false; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp index e42d5e41d98..17e5061a187 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/common/ref_vector.hpp" #include "barretenberg/common/zip_view.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index b9f1fb8f4d8..a1dfb085f54 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/common/zip_view.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb { /** diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp b/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp index aa47b807998..fdfb2903590 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp @@ -6,7 +6,7 @@ #include "barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp" #include "barretenberg/plonk_honk_shared/composer/composer_lib.hpp" #include "barretenberg/plonk_honk_shared/composer/permutation_lib.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.hpp index 800af9d672d..88cba1adddd 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../../../polynomials/polynomial.hpp" +#include "../../../polynomials/legacy_polynomial.hpp" #include "../../../polynomials/polynomial_arithmetic.hpp" #include "../types/commitment_open_proof.hpp" #include "../types/program_settings.hpp" diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp index 299b1f83e1b..bcc58f7abe8 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp @@ -5,7 +5,7 @@ #include "../types/program_settings.hpp" #include "barretenberg/common/mem.hpp" #include "barretenberg/plonk/work_queue/work_queue.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp index 07a0dadbf2c..3011122a4e3 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp @@ -3,7 +3,7 @@ #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" #include "barretenberg/plonk/proof_system/types/prover_settings.hpp" #include "barretenberg/polynomials/iterate_over_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.hpp index 817f4b2d1f1..3952179f12b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.hpp @@ -8,7 +8,7 @@ #include "barretenberg/plonk/proof_system/types/polynomial_manifest.hpp" #include "barretenberg/plonk_honk_shared/types/aggregation_object_type.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" #ifdef __wasm__ diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/generalized_permutation.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/generalized_permutation.hpp index eeb09526502..ca154eb88f6 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/generalized_permutation.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/generalized_permutation.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/polynomials/iterate_over_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb::plonk { template diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/permutation.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/permutation.hpp index ad50503df8d..ab95ddb05cd 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/permutation.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/permutation.hpp @@ -3,7 +3,7 @@ #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/polynomials/iterate_over_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb::plonk { diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/permutation_widget_impl.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/permutation_widget_impl.hpp index 387ed72dc56..9947a38baa0 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/permutation_widget_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/permutation_widget_impl.hpp @@ -4,7 +4,7 @@ #include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" #include "barretenberg/plonk/proof_system/public_inputs/public_inputs.hpp" #include "barretenberg/polynomials/iterate_over_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "barretenberg/transcript/transcript.hpp" diff --git a/barretenberg/cpp/src/barretenberg/plonk/work_queue/work_queue.cpp b/barretenberg/cpp/src/barretenberg/plonk/work_queue/work_queue.cpp index 9128f542457..571876b06c6 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/work_queue/work_queue.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/work_queue/work_queue.cpp @@ -1,6 +1,6 @@ #include "work_queue.hpp" #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" namespace bb::plonk { diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp index 52bd04ec97d..1592149cc6e 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp @@ -13,7 +13,7 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" #include "barretenberg/polynomials/iterate_over_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include @@ -347,10 +347,11 @@ void compute_monomial_and_coset_fft_polynomials_from_lagrange(std::string label, * @brief Compute Lagrange Polynomials L_0 and L_{n-1} and put them in the polynomial cache */ template -inline std::tuple, Polynomial> compute_first_and_last_lagrange_polynomials(const size_t circuit_size) +inline std::tuple, LegacyPolynomial> compute_first_and_last_lagrange_polynomials( + const size_t circuit_size) { - Polynomial lagrange_polynomial_0(circuit_size); - Polynomial lagrange_polynomial_n_min_1(circuit_size); + LegacyPolynomial lagrange_polynomial_0(circuit_size); + LegacyPolynomial lagrange_polynomial_n_min_1(circuit_size); lagrange_polynomial_0[0] = 1; lagrange_polynomial_n_min_1[circuit_size - 1] = 1; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp index 43d01587541..b20e53e0bd5 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp @@ -3,7 +3,7 @@ #include "barretenberg/common/thread.hpp" #include "barretenberg/common/zip_view.hpp" #include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp similarity index 77% rename from barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp index 9971d6943cf..717a10e44eb 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp @@ -1,4 +1,4 @@ -#include "polynomial.hpp" +#include "legacy_polynomial.hpp" #include "barretenberg/common/assert.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/common/thread.hpp" @@ -22,7 +22,7 @@ template std::shared_ptr _allocate_aligned_memory(const size return std::static_pointer_cast(get_mem_slab(sizeof(Fr) * n_elements)); } -template void Polynomial::allocate_backing_memory(size_t n_elements) +template void LegacyPolynomial::allocate_backing_memory(size_t n_elements) { size_ = n_elements; // capacity() is size_ plus padding for shifted polynomials @@ -39,7 +39,7 @@ template void Polynomial::allocate_backing_memory(size_t n_ele * * @param initial_size The initial size of the polynomial. */ -template Polynomial::Polynomial(size_t initial_size) +template LegacyPolynomial::LegacyPolynomial(size_t initial_size) { allocate_backing_memory(initial_size); memset(static_cast(coefficients_), 0, sizeof(Fr) * capacity()); @@ -52,7 +52,7 @@ template Polynomial::Polynomial(size_t initial_size) * @param initial_size The initial size of the polynomial. * @param flag Signals that we do not zero memory. */ -template Polynomial::Polynomial(size_t initial_size, DontZeroMemory flag) +template LegacyPolynomial::LegacyPolynomial(size_t initial_size, DontZeroMemory flag) { // Flag is unused, but we don't memset 0 if passed. (void)flag; @@ -60,12 +60,13 @@ template Polynomial::Polynomial(size_t initial_size, DontZeroM } template -Polynomial::Polynomial(const Polynomial& other) - : Polynomial(other, other.size()) +LegacyPolynomial::LegacyPolynomial(const LegacyPolynomial& other) + : LegacyPolynomial(other, other.size()) {} // fully copying "expensive" constructor -template Polynomial::Polynomial(const Polynomial& other, const size_t target_size) +template +LegacyPolynomial::LegacyPolynomial(const LegacyPolynomial& other, const size_t target_size) { allocate_backing_memory(std::max(target_size, other.size())); @@ -75,14 +76,14 @@ template Polynomial::Polynomial(const Polynomial& other, c // move constructor template -Polynomial::Polynomial(Polynomial&& other) noexcept +LegacyPolynomial::LegacyPolynomial(LegacyPolynomial&& other) noexcept : backing_memory_(std::exchange(other.backing_memory_, nullptr)) , coefficients_(std::exchange(other.coefficients_, nullptr)) , size_(std::exchange(other.size_, 0)) {} // span constructor -template Polynomial::Polynomial(std::span coefficients) +template LegacyPolynomial::LegacyPolynomial(std::span coefficients) { allocate_backing_memory(coefficients.size()); memcpy(static_cast(coefficients_), @@ -93,8 +94,8 @@ template Polynomial::Polynomial(std::span coefficien // interpolation constructor template -Polynomial::Polynomial(std::span interpolation_points, std::span evaluations) - : Polynomial(interpolation_points.size()) +LegacyPolynomial::LegacyPolynomial(std::span interpolation_points, std::span evaluations) + : LegacyPolynomial(interpolation_points.size()) { ASSERT(size_ > 0); @@ -105,7 +106,7 @@ Polynomial::Polynomial(std::span interpolation_points, std::span Polynomial& Polynomial::operator=(const Polynomial& other) +template LegacyPolynomial& LegacyPolynomial::operator=(const LegacyPolynomial& other) { if (this == &other) { return *this; @@ -116,15 +117,15 @@ template Polynomial& Polynomial::operator=(const Polynomia return *this; } -template Polynomial& Polynomial::operator=(std::span coefficients) noexcept +template LegacyPolynomial& LegacyPolynomial::operator=(std::span coefficients) noexcept { // move assign a Polynomial constructed with the span - *this = Polynomial{ coefficients }; + *this = LegacyPolynomial{ coefficients }; return *this; } // ####### -template Polynomial& Polynomial::operator=(Polynomial&& other) noexcept +template LegacyPolynomial& LegacyPolynomial::operator=(LegacyPolynomial&& other) noexcept { if (&other == this) { return *this; @@ -137,26 +138,26 @@ template Polynomial& Polynomial::operator=(Polynomial&& ot return *this; } -template Polynomial Polynomial::share() const +template LegacyPolynomial LegacyPolynomial::share() const { - Polynomial p; + LegacyPolynomial p; p.backing_memory_ = backing_memory_; p.size_ = size_; p.coefficients_ = coefficients_; return p; } -template Fr Polynomial::evaluate(const Fr& z, const size_t target_size) const +template Fr LegacyPolynomial::evaluate(const Fr& z, const size_t target_size) const { return polynomial_arithmetic::evaluate(coefficients_, z, target_size); } -template Fr Polynomial::evaluate(const Fr& z) const +template Fr LegacyPolynomial::evaluate(const Fr& z) const { return polynomial_arithmetic::evaluate(coefficients_, z, size_); } -template bool Polynomial::operator==(Polynomial const& rhs) const +template bool LegacyPolynomial::operator==(LegacyPolynomial const& rhs) const { // If either is empty, both must be if (is_empty() || rhs.is_empty()) { @@ -185,7 +186,7 @@ template bool Polynomial::operator==(Polynomial const& rhs) co * @param commitment_data Describes each polynomial being opened: its commitment, the opening points used and the * polynomial evaluations */ -template void Polynomial::zero_memory_beyond(const size_t start_position) +template void LegacyPolynomial::zero_memory_beyond(const size_t start_position) { size_t end = capacity(); ASSERT(end >= start_position); @@ -202,7 +203,7 @@ template void Polynomial::zero_memory_beyond(const size_t star **/ template -void Polynomial::fft(const EvaluationDomain& domain) +void LegacyPolynomial::fft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -212,7 +213,7 @@ void Polynomial::fft(const EvaluationDomain& domain) } template -void Polynomial::partial_fft(const EvaluationDomain& domain, Fr constant, bool is_coset) +void LegacyPolynomial::partial_fft(const EvaluationDomain& domain, Fr constant, bool is_coset) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -222,7 +223,7 @@ void Polynomial::partial_fft(const EvaluationDomain& domain, Fr constant } template -void Polynomial::coset_fft(const EvaluationDomain& domain) +void LegacyPolynomial::coset_fft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -232,9 +233,9 @@ void Polynomial::coset_fft(const EvaluationDomain& domain) } template -void Polynomial::coset_fft(const EvaluationDomain& domain, - const EvaluationDomain& large_domain, - const size_t domain_extension) +void LegacyPolynomial::coset_fft(const EvaluationDomain& domain, + const EvaluationDomain& large_domain, + const size_t domain_extension) requires polynomial_arithmetic::SupportsFFT { size_t extended_size = domain.size * domain_extension; @@ -246,7 +247,7 @@ void Polynomial::coset_fft(const EvaluationDomain& domain, } template -void Polynomial::coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) +void LegacyPolynomial::coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -256,7 +257,7 @@ void Polynomial::coset_fft_with_constant(const EvaluationDomain& domain, } template -void Polynomial::coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) +void LegacyPolynomial::coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -266,7 +267,7 @@ void Polynomial::coset_fft_with_generator_shift(const EvaluationDomain& } template -void Polynomial::ifft(const EvaluationDomain& domain) +void LegacyPolynomial::ifft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -276,7 +277,7 @@ void Polynomial::ifft(const EvaluationDomain& domain) } template -void Polynomial::ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) +void LegacyPolynomial::ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -286,7 +287,7 @@ void Polynomial::ifft_with_constant(const EvaluationDomain& domain, cons } template -void Polynomial::coset_ifft(const EvaluationDomain& domain) +void LegacyPolynomial::coset_ifft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -296,35 +297,35 @@ void Polynomial::coset_ifft(const EvaluationDomain& domain) } template -Fr Polynomial::compute_kate_opening_coefficients(const Fr& z) +Fr LegacyPolynomial::compute_kate_opening_coefficients(const Fr& z) requires polynomial_arithmetic::SupportsFFT { return polynomial_arithmetic::compute_kate_opening_coefficients(coefficients_, coefficients_, z, size_); } template -Fr Polynomial::compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) +Fr LegacyPolynomial::compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { return polynomial_arithmetic::compute_barycentric_evaluation(coefficients_, domain.size, z, domain); } template -Fr Polynomial::evaluate_from_fft(const EvaluationDomain& large_domain, - const Fr& z, - const EvaluationDomain& small_domain) +Fr LegacyPolynomial::evaluate_from_fft(const EvaluationDomain& large_domain, + const Fr& z, + const EvaluationDomain& small_domain) requires polynomial_arithmetic::SupportsFFT { return polynomial_arithmetic::evaluate_from_fft(coefficients_, large_domain, z, small_domain); } -template Polynomial Polynomial::shifted() const +template LegacyPolynomial LegacyPolynomial::shifted() const { ASSERT(size_ > 0); ASSERT(coefficients_[0].is_zero()); ASSERT(coefficients_[size_].is_zero()); // relies on MAXIMUM_COEFFICIENT_SHIFT >= 1 - Polynomial p; + LegacyPolynomial p; p.backing_memory_ = backing_memory_; p.size_ = size_; p.coefficients_ = coefficients_ + 1; @@ -334,7 +335,7 @@ template Polynomial Polynomial::shifted() const // TODO(#723): This method is used for the transcript aggregation protocol. For convenience we currently enforce that // the shift is the same size as the input but this does not need to be the case. Revisit the logic/assertions in this // method when that issue is addressed. -template void Polynomial::set_to_right_shifted(std::span coeffs_in, size_t shift_size) +template void LegacyPolynomial::set_to_right_shifted(std::span coeffs_in, size_t shift_size) { // Ensure we're not trying to shift self ASSERT(coefficients_ != coeffs_in.data()); @@ -363,7 +364,7 @@ template void Polynomial::set_to_right_shifted(std::span c zero_memory_beyond(size_); } -template void Polynomial::add_scaled(std::span other, Fr scaling_factor) +template void LegacyPolynomial::add_scaled(std::span other, Fr scaling_factor) { const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); @@ -380,7 +381,7 @@ template void Polynomial::add_scaled(std::span other }); } -template Polynomial& Polynomial::operator+=(std::span other) +template LegacyPolynomial& LegacyPolynomial::operator+=(std::span other) { const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); @@ -399,7 +400,7 @@ template Polynomial& Polynomial::operator+=(std::span Polynomial& Polynomial::operator-=(std::span other) +template LegacyPolynomial& LegacyPolynomial::operator-=(std::span other) { const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); @@ -418,7 +419,7 @@ template Polynomial& Polynomial::operator-=(std::span Polynomial& Polynomial::operator*=(const Fr scaling_factor) +template LegacyPolynomial& LegacyPolynomial::operator*=(const Fr scaling_factor) { ASSERT(in_place_operation_viable()); @@ -436,7 +437,7 @@ template Polynomial& Polynomial::operator*=(const Fr scali return *this; } -template Fr Polynomial::evaluate_mle(std::span evaluation_points, bool shift) const +template Fr LegacyPolynomial::evaluate_mle(std::span evaluation_points, bool shift) const { const size_t m = evaluation_points.size(); @@ -477,7 +478,8 @@ template Fr Polynomial::evaluate_mle(std::span evalu return result; } -template Polynomial Polynomial::partial_evaluate_mle(std::span evaluation_points) const +template +LegacyPolynomial LegacyPolynomial::partial_evaluate_mle(std::span evaluation_points) const { // Get size of partial evaluation point u = (u_0,...,u_{m-1}) const size_t m = evaluation_points.size(); @@ -492,7 +494,7 @@ template Polynomial Polynomial::partial_evaluate_mle(std:: size_t n_l = 1 << (n - 1); // Temporary buffer of half the size of the polynomial - Polynomial intermediate(n_l, DontZeroMemory::FLAG); + LegacyPolynomial intermediate(n_l, DontZeroMemory::FLAG); // Evaluate variable X_{n-1} at u_{m-1} Fr u_l = evaluation_points[m - 1]; @@ -511,7 +513,7 @@ template Polynomial Polynomial::partial_evaluate_mle(std:: } // Construct resulting polynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) from buffer - Polynomial result(n_l, DontZeroMemory::FLAG); + LegacyPolynomial result(n_l, DontZeroMemory::FLAG); for (size_t idx = 0; idx < n_l; ++idx) { result[idx] = intermediate[idx]; } @@ -519,7 +521,7 @@ template Polynomial Polynomial::partial_evaluate_mle(std:: return result; } -template class Polynomial; -template class Polynomial; +template class LegacyPolynomial; +template class LegacyPolynomial; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp similarity index 89% rename from barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp rename to barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp index 5bb51b503e9..28a5afe69ce 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp @@ -15,10 +15,12 @@ namespace bb { * Polynomials use the majority of the memory in proving, so caution should be used in making sure * unnecessary copies are avoided, both for avoiding unnecessary memory usage and performance * due to unnecessary allocations. + * Note: This should not be used for new code, hence the Legacy name. This is only used in older plonk-centric code + * as opposed to newer honk-centric code. * * @tparam Fr the finite field type. */ -template class Polynomial { +template class LegacyPolynomial { public: /** * Implements requirements of `std::ranges::contiguous_range` and `std::ranges::sized_range` @@ -34,19 +36,19 @@ template class Polynomial { using FF = Fr; enum class DontZeroMemory { FLAG }; - Polynomial(size_t initial_size); + LegacyPolynomial(size_t initial_size); // Constructor that does not initialize values, use with caution to save time. - Polynomial(size_t initial_size, DontZeroMemory flag); - Polynomial(const Polynomial& other); - Polynomial(const Polynomial& other, size_t target_size); + LegacyPolynomial(size_t initial_size, DontZeroMemory flag); + LegacyPolynomial(const LegacyPolynomial& other); + LegacyPolynomial(const LegacyPolynomial& other, size_t target_size); - Polynomial(Polynomial&& other) noexcept; + LegacyPolynomial(LegacyPolynomial&& other) noexcept; // Create a polynomial from the given fields. - Polynomial(std::span coefficients); + LegacyPolynomial(std::span coefficients); // Allow polynomials to be entirely reset/dormant - Polynomial() = default; + LegacyPolynomial() = default; /** * @brief Create the degree-(m-1) polynomial T(X) that interpolates the given evaluations. @@ -55,18 +57,18 @@ template class Polynomial { * @param interpolation_points (x₁,…,xₘ) * @param evaluations (y₁,…,yₘ) */ - Polynomial(std::span interpolation_points, std::span evaluations); + LegacyPolynomial(std::span interpolation_points, std::span evaluations); // move assignment - Polynomial& operator=(Polynomial&& other) noexcept; - Polynomial& operator=(std::span coefficients) noexcept; - Polynomial& operator=(const Polynomial& other); - ~Polynomial() = default; + LegacyPolynomial& operator=(LegacyPolynomial&& other) noexcept; + LegacyPolynomial& operator=(std::span coefficients) noexcept; + LegacyPolynomial& operator=(const LegacyPolynomial& other); + ~LegacyPolynomial() = default; /** * Return a shallow clone of the polynomial. i.e. underlying memory is shared. */ - Polynomial share() const; + LegacyPolynomial share() const; std::array hash() const { return crypto::sha256(byte_span()); } @@ -96,7 +98,7 @@ template class Polynomial { return true; } - bool operator==(Polynomial const& rhs) const; + bool operator==(LegacyPolynomial const& rhs) const; // Const and non const versions of coefficient accessors Fr const& operator[](const size_t i) const { return coefficients_[i]; } @@ -155,7 +157,7 @@ template class Polynomial { * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). */ - Polynomial shifted() const; + LegacyPolynomial shifted() const; /** * @brief Set self to the right shift of input coefficients @@ -182,21 +184,21 @@ template class Polynomial { * * @param other q(X) */ - Polynomial& operator+=(std::span other); + LegacyPolynomial& operator+=(std::span other); /** * @brief subtracts the polynomial q(X) 'other'. * * @param other q(X) */ - Polynomial& operator-=(std::span other); + LegacyPolynomial& operator-=(std::span other); /** * @brief sets this = p(X) to s⋅p(X) * * @param scaling_factor s */ - Polynomial& operator*=(Fr scaling_factor); + LegacyPolynomial& operator*=(Fr scaling_factor); /** * @brief evaluates p(X) = ∑ᵢ aᵢ⋅Xⁱ considered as multi-linear extension p(X₀,…,Xₘ₋₁) = ∑ᵢ aᵢ⋅Lᵢ(X₀,…,Xₘ₋₁) @@ -227,7 +229,7 @@ template class Polynomial { * @param evaluation_points an MLE partial evaluation point u = (u_0,…,u_{m-1}) * @return Polynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) */ - Polynomial partial_evaluate_mle(std::span evaluation_points) const; + LegacyPolynomial partial_evaluate_mle(std::span evaluation_points) const; /** * @brief Divides p(X) by (X-r₁)⋯(X−rₘ) in-place. @@ -259,9 +261,9 @@ template class Polynomial { std::size_t size() const { return size_; } std::size_t capacity() const { return size_ + MAXIMUM_COEFFICIENT_SHIFT; } - static Polynomial random(const size_t num_coeffs) + static LegacyPolynomial random(const size_t num_coeffs) { - Polynomial p(num_coeffs); + LegacyPolynomial p(num_coeffs); std::generate_n(p.begin(), num_coeffs, []() { return Fr::random_element(); }); return p; } @@ -291,7 +293,7 @@ template class Polynomial { size_t size_ = 0; }; -template inline std::ostream& operator<<(std::ostream& os, Polynomial const& p) +template inline std::ostream& operator<<(std::ostream& os, LegacyPolynomial const& p) { if (p.size() == 0) { return os << "[]"; @@ -308,7 +310,7 @@ template inline std::ostream& operator<<(std::ostream& os, Polynom << "]"; } -using polynomial = Polynomial; +using polynomial = LegacyPolynomial; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp similarity index 91% rename from barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp index 59e4d5fa747..3952c8cb1b6 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp @@ -1,7 +1,7 @@ #include #include -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" using namespace bb; @@ -9,7 +9,7 @@ using namespace bb; TEST(Polynomial, Shifted) { using FF = bb::fr; - using Polynomial = Polynomial; + using Polynomial = LegacyPolynomial; const size_t SIZE = 10; auto poly = Polynomial::random(SIZE); poly[0] = 0; // make it shiftable @@ -35,7 +35,7 @@ TEST(Polynomial, Shifted) TEST(Polynomial, Share) { using FF = bb::fr; - using Polynomial = Polynomial; + using Polynomial = LegacyPolynomial; const size_t SIZE = 10; auto poly = Polynomial::random(SIZE); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomials.bench.cpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomials.bench.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/polynomials/polynomials.bench.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomials.bench.cpp diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp index 0a58f36b9b3..d400545f063 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp @@ -3,7 +3,7 @@ #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "polynomial.hpp" +#include "legacy_polynomial.hpp" #include #include #include @@ -1058,7 +1058,7 @@ TYPED_TEST(PolynomialTests, interpolation_constructor_single) auto root = std::array{ FF(3) }; auto eval = std::array{ FF(4) }; - Polynomial t(root, eval); + LegacyPolynomial t(root, eval); ASSERT_EQ(t.size(), 1); ASSERT_EQ(t[0], eval[0]); } @@ -1078,7 +1078,7 @@ TYPED_TEST(PolynomialTests, interpolation_constructor) auto roots_copy(roots); auto evaluations_copy(evaluations); - Polynomial interpolated(roots, evaluations); + LegacyPolynomial interpolated(roots, evaluations); ASSERT_EQ(interpolated.size(), N); ASSERT_EQ(roots, roots_copy); @@ -1098,7 +1098,7 @@ TYPED_TEST(PolynomialTests, evaluate_mle) auto& engine = numeric::get_debug_randomness(); const size_t m = numeric::get_msb(N); EXPECT_EQ(N, 1 << m); - Polynomial poly(N); + LegacyPolynomial poly(N); for (size_t i = 1; i < N - 1; ++i) { poly[i] = FF::random_element(&engine); } @@ -1156,7 +1156,7 @@ TYPED_TEST(PolynomialTests, partial_evaluate_mle) // Initialize a random polynomial using FF = TypeParam; size_t N = 32; - Polynomial poly(N); + LegacyPolynomial poly(N); for (auto& coeff : poly) { coeff = FF::random_element(); } @@ -1193,7 +1193,7 @@ TYPED_TEST(PolynomialTests, factor_roots) auto test_case = [&](size_t NUM_ZERO_ROOTS, size_t NUM_NON_ZERO_ROOTS) { const size_t NUM_ROOTS = NUM_NON_ZERO_ROOTS + NUM_ZERO_ROOTS; - Polynomial poly(N); + LegacyPolynomial poly(N); for (size_t i = NUM_ZERO_ROOTS; i < N; ++i) { poly[i] = FF::random_element(); } @@ -1217,7 +1217,7 @@ TYPED_TEST(PolynomialTests, factor_roots) } if (NUM_NON_ZERO_ROOTS > 0) { - Polynomial interpolated(non_zero_roots, non_zero_evaluations); + LegacyPolynomial interpolated(non_zero_roots, non_zero_evaluations); EXPECT_EQ(interpolated.size(), NUM_NON_ZERO_ROOTS); for (size_t i = 0; i < NUM_NON_ZERO_ROOTS; ++i) { poly[NUM_ZERO_ROOTS + i] -= interpolated[i]; @@ -1229,7 +1229,7 @@ TYPED_TEST(PolynomialTests, factor_roots) EXPECT_EQ(poly.evaluate(roots[i]), FF::zero()) << i; } - Polynomial quotient(poly); + LegacyPolynomial quotient(poly); quotient.factor_roots(roots); // check that (t-r)q(t) == p(t) @@ -1246,7 +1246,7 @@ TYPED_TEST(PolynomialTests, factor_roots) EXPECT_EQ(poly, quotient); } if (NUM_ROOTS == 1) { - Polynomial quotient_single(poly); + LegacyPolynomial quotient_single(poly); quotient_single.factor_roots(roots[0]); EXPECT_EQ(quotient_single, quotient); } @@ -1266,13 +1266,13 @@ TYPED_TEST(PolynomialTests, move_construct_and_assign) // construct a poly with some arbitrary data size_t num_coeffs = 64; - Polynomial polynomial_a(num_coeffs); + LegacyPolynomial polynomial_a(num_coeffs); for (auto& coeff : polynomial_a) { coeff = FF::random_element(); } // construct a new poly from the original via the move constructor - Polynomial polynomial_b(std::move(polynomial_a)); + LegacyPolynomial polynomial_b(std::move(polynomial_a)); // verifiy that source poly is appropriately destroyed EXPECT_EQ(polynomial_a.begin(), nullptr); @@ -1286,7 +1286,7 @@ TYPED_TEST(PolynomialTests, move_construct_and_assign) EXPECT_EQ(polynomial_b.size(), 0); // define a poly with some arbitrary coefficients - Polynomial polynomial_d(num_coeffs); + LegacyPolynomial polynomial_d(num_coeffs); for (auto& coeff : polynomial_d) { coeff = FF::random_element(); } @@ -1305,13 +1305,13 @@ TYPED_TEST(PolynomialTests, default_construct_then_assign) // construct an arbitrary but non-empty polynomial size_t num_coeffs = 64; - Polynomial interesting_poly(num_coeffs); + LegacyPolynomial interesting_poly(num_coeffs); for (auto& coeff : interesting_poly) { coeff = FF::random_element(); } // construct an empty poly via the default constructor - Polynomial poly; + LegacyPolynomial poly; EXPECT_EQ(poly.is_empty(), true); @@ -1337,8 +1337,8 @@ TYPED_TEST(PolynomialTests, RightShift) size_t num_coeffs = 32; size_t num_nonzero_coeffs = 7; size_t shift_magnitude = 21; - Polynomial poly(num_coeffs); - Polynomial right_shifted_poly(num_coeffs); + LegacyPolynomial poly(num_coeffs); + LegacyPolynomial right_shifted_poly(num_coeffs); for (size_t idx = 0; idx < num_nonzero_coeffs; ++idx) { poly[idx] = FF::random_element(); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp index d23a6106444..f200df7b1e0 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp @@ -1,6 +1,6 @@ #include "polynomial_store.hpp" #include "barretenberg/common/assert.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include #include @@ -22,7 +22,7 @@ template void PolynomialStore::put(std::string const& key, Pol * @param key string ID of the polynomial * @return Polynomial&; a reference to the polynomial associated with the given key */ -template bb::Polynomial PolynomialStore::get(std::string const& key) +template bb::LegacyPolynomial PolynomialStore::get(std::string const& key) { // info("poly store get: ", key); // Take a shallow copy of the polynomial. Compiler will move the shallow copy to call site. diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.hpp index c18103fefc9..84b67e1e28d 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/common/assert.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include #include @@ -11,7 +11,7 @@ namespace bb { template class PolynomialStore { private: - using Polynomial = bb::Polynomial; + using Polynomial = bb::LegacyPolynomial; std::unordered_map polynomial_map; public: diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.test.cpp index 649dd60191a..7a7231fb2b1 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.test.cpp @@ -1,7 +1,7 @@ #include #include -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "polynomial_store.hpp" using namespace bb; @@ -12,13 +12,13 @@ TEST(PolynomialStore, PutThenGet) PolynomialStore polynomial_store; // Instantiate a polynomial with random coefficients - Polynomial poly(1024); + LegacyPolynomial poly(1024); for (auto& coeff : poly) { coeff = fr::random_element(); } // Make a copy for comparison after original is moved into container - Polynomial poly_copy(poly); + LegacyPolynomial poly_copy(poly); // Move the poly into the container polynomial_store.put("id", std::move(poly)); @@ -32,7 +32,7 @@ TEST(PolynomialStore, NonexistentKey) { PolynomialStore polynomial_store; - polynomial_store.put("id_1", Polynomial(100)); + polynomial_store.put("id_1", LegacyPolynomial(100)); polynomial_store.get("id_1"); // no problem! @@ -47,9 +47,9 @@ TEST(PolynomialStore, Volume) size_t size2 = 10; size_t size3 = 5000; - Polynomial poly1(size1); - Polynomial poly2(size2); - Polynomial poly3(size3); + LegacyPolynomial poly1(size1); + LegacyPolynomial poly2(size2); + LegacyPolynomial poly3(size3); polynomial_store.put("id_1", std::move(poly1)); polynomial_store.put("id_2", std::move(poly2)); @@ -68,8 +68,8 @@ TEST(PolynomialStore, Remove) PolynomialStore polynomial_store; size_t size1 = 100; size_t size2 = 500; - Polynomial poly1(size1); - Polynomial poly2(size2); + LegacyPolynomial poly1(size1); + LegacyPolynomial poly2(size2); polynomial_store.put("id_1", std::move(poly1)); polynomial_store.put("id_2", std::move(poly2)); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_cache.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_cache.hpp index 78b1c7a3e14..0c1c309c5e2 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_cache.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_cache.hpp @@ -1,6 +1,6 @@ #pragma once #include "./polynomial_store_wasm.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include @@ -17,7 +17,7 @@ namespace bb { */ class PolynomialStoreCache { private: - using Polynomial = bb::Polynomial; + using Polynomial = bb::LegacyPolynomial; std::map cache_; std::multimap::iterator> size_map_; PolynomialStoreWasm external_store; diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.cpp index 058770a1dce..491ae841f0e 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.cpp @@ -1,6 +1,6 @@ #include "polynomial_store_wasm.hpp" #include "barretenberg/env/data_store.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb { @@ -11,7 +11,7 @@ template void PolynomialStoreWasm::put(std::string const& key, size_map[key] = value.size(); }; -template bb::Polynomial PolynomialStoreWasm::get(std::string const& key) +template bb::LegacyPolynomial PolynomialStoreWasm::get(std::string const& key) { auto p = Polynomial(size_map[key]); get_data(key.c_str(), (uint8_t*)p.data().get()); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.hpp index ce33260821b..beb704256b6 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store_wasm.hpp @@ -1,5 +1,5 @@ #pragma once -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include @@ -7,7 +7,7 @@ namespace bb { template class PolynomialStoreWasm { private: - using Polynomial = bb::Polynomial; + using Polynomial = bb::LegacyPolynomial; std::unordered_map size_map; public: diff --git a/barretenberg/cpp/src/barretenberg/polynomials/serialize.hpp b/barretenberg/cpp/src/barretenberg/polynomials/serialize.hpp index afbd340e025..c511ac6cfb1 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/serialize.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/serialize.hpp @@ -1,5 +1,5 @@ #pragma once -#include "polynomial.hpp" +#include "legacy_polynomial.hpp" namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp index 5f564f1d1b0..6902ae5a3d5 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp @@ -1,7 +1,7 @@ #include #include -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" using namespace bb; @@ -9,7 +9,7 @@ using namespace bb; TEST(SparsePolynomial, Shifted) { using FF = bb::fr; - using Polynomial = Polynomial; + using Polynomial = LegacyPolynomial; const size_t SIZE = 10; auto poly = Polynomial::random(SIZE); poly[0] = 0; // make it shiftable @@ -35,7 +35,7 @@ TEST(SparsePolynomial, Shifted) TEST(SparsePolynomial, Share) { using FF = bb::fr; - using Polynomial = Polynomial; + using Polynomial = LegacyPolynomial; const size_t SIZE = 10; auto poly = Polynomial::random(SIZE); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index cbfbe35cbda..e45c5448b69 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -18,7 +18,7 @@ template struct ProtogalaxyProofConstructionState { using ProverInstance = typename ProverInstances_::Instance; std::shared_ptr accumulator; - Polynomial perturbator; + LegacyPolynomial perturbator; std::vector deltas; Univariate combiner_quotient; FF compressed_perturbator; @@ -272,8 +272,8 @@ template class ProtoGalaxyProver_ { * * */ - static Polynomial compute_perturbator(const std::shared_ptr accumulator, - const std::vector& deltas) + static LegacyPolynomial compute_perturbator(const std::shared_ptr accumulator, + const std::vector& deltas) { BB_OP_COUNT_TIME(); auto full_honk_evaluations = compute_full_honk_evaluations( @@ -281,7 +281,7 @@ template class ProtoGalaxyProver_ { const auto betas = accumulator->gate_challenges; assert(betas.size() == deltas.size()); auto coeffs = construct_perturbator_coefficients(betas, deltas, full_honk_evaluations); - return Polynomial(coeffs); + return LegacyPolynomial(coeffs); } OptimisedTupleOfTuplesOfUnivariates optimised_univariate_accumulators; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 36774b7c25f..4199e2cf8ed 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -140,7 +140,8 @@ template void ProtoGalaxyProver_::pertu state.accumulator = get_accumulator(); FF delta = transcript->template get_challenge("delta"); state.deltas = compute_round_challenge_pows(state.accumulator->proving_key.log_circuit_size, delta); - state.perturbator = Polynomial(state.accumulator->proving_key.log_circuit_size + 1); // initialize to all zeros + state.perturbator = + LegacyPolynomial(state.accumulator->proving_key.log_circuit_size + 1); // initialize to all zeros // compute perturbator only if this is not the first round and has an accumulator if (state.accumulator->is_accumulator) { state.perturbator = compute_perturbator(state.accumulator, state.deltas); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index 9ffce227620..2bfaa09a7a6 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -57,7 +57,7 @@ std::shared_ptr ProtoGalaxyVerifier_target_sum; - auto perturbator = Polynomial(perturbator_coeffs); + auto perturbator = LegacyPolynomial(perturbator_coeffs); FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); auto perturbator_at_challenge = perturbator.evaluate(perturbator_challenge); diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index 353be1c76ce..a7faed2e5b7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -3,7 +3,7 @@ #include #include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp index 687d81d2f73..472496af59b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp @@ -3,7 +3,7 @@ #include #include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp index d958f7a5481..327ba70b399 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp @@ -3,7 +3,7 @@ #include #include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp index 2f388d0ddbd..138c6a49ace 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp @@ -20,7 +20,7 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp index a34290e7544..b0696f51ed5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp @@ -11,7 +11,7 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 7e39ebc7df8..6bd21460c72 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -4,7 +4,7 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp index 437fb0422bd..99f3face100 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp @@ -1,6 +1,6 @@ #include "protogalaxy_recursive_verifier.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/stdlib/honk_recursion/verifier/recursive_instances.hpp" namespace bb::stdlib::recursion::honk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.test.cpp index 504481a0e7f..1c5a5697ec7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.test.cpp @@ -159,7 +159,7 @@ template class ProtoGalaxyRecursiveTests : public tes coeffs.emplace_back(el); coeffs_ct.emplace_back(fr_ct(&builder, el)); } - Polynomial poly(coeffs); + LegacyPolynomial poly(coeffs); fr point = fr::random_element(); fr_ct point_ct(fr_ct(&builder, point)); auto res1 = poly.evaluate(point); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp index d2e24289361..0d01f94b756 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp @@ -1,7 +1,7 @@ #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp index d0beed7bed2..c433bf15d5e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp @@ -6,7 +6,7 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/stdlib/honk_recursion/transcript/transcript.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index fadbb9a6f16..28edc512dfb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -5,7 +5,7 @@ #include "barretenberg/plonk_honk_shared/types/circuit_type.hpp" #include "barretenberg/plonk_honk_shared/types/merkle_hash_type.hpp" #include "barretenberg/plonk_honk_shared/types/pedersen_commitment_type.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/stdlib_circuit_builders/op_queue/ecc_op_queue.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 857f91dda29..c4a995c6abd 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -7,7 +7,7 @@ #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/sparse_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index 0827776c0d5..20d01db94f4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -8,7 +8,7 @@ #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index b0228d4748b..d59f07a5eec 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -6,7 +6,7 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index 7661951fbda..b04062e97cf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -10,7 +10,7 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include "barretenberg/vm/avm/generated/flavor_settings.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp index d5cbab1767e..12a85a6448a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp @@ -8,7 +8,7 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp index e1375bc8b1b..461e426be04 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp @@ -5,7 +5,7 @@ #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs index 1a29dcedbfb..1153b0755cf 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs @@ -10,7 +10,7 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/transcript/transcript.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/vm/{{snakeCase name}}/generated/flavor_settings.hpp" diff --git a/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs index d053ab7104d..07345186acb 100644 --- a/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs @@ -8,7 +8,7 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs index acc5346c665..9ba1b94a98d 100644 --- a/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs @@ -5,7 +5,7 @@ #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { From b9feb75746dabb474dd0ecae8ec4db222cabe964 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 19:09:12 +0000 Subject: [PATCH 09/15] sparse polynomial is normal now --- .../benchmark/ipa_bench/ipa.bench.cpp | 4 +- .../barretenberg/commitment_schemes/claim.hpp | 4 +- .../commitment_key.test.hpp | 2 +- .../commitment_schemes/gemini/gemini.hpp | 6 +- .../commitment_schemes/gemini/gemini.test.cpp | 4 +- .../commitment_schemes/ipa/ipa.hpp | 2 +- .../commitment_schemes/ipa/ipa.test.cpp | 2 +- .../commitment_schemes/kzg/kzg.hpp | 2 +- .../commitment_schemes/kzg/kzg.test.cpp | 4 +- .../commitment_schemes/shplonk/shplonk.hpp | 2 +- .../sparse_commitment.test.cpp | 6 +- .../zeromorph/zeromorph.hpp | 4 +- .../zeromorph/zeromorph.test.cpp | 10 +- .../zeromorph.test.cpp | 2 +- .../eccvm/eccvm_circuit_builder.hpp | 4 +- .../src/barretenberg/eccvm/eccvm_flavor.hpp | 4 +- .../eccvm/eccvm_trace_checker.cpp | 2 +- .../src/barretenberg/flavor/flavor.test.cpp | 2 +- .../cpp/src/barretenberg/goblin/goblin.hpp | 2 +- .../{sparse_polynomial.cpp => polynomial.cpp} | 96 +++++++++---------- .../{sparse_polynomial.hpp => polynomial.hpp} | 56 +++++------ ...olynomial.test.cpp => polynomial.test.cpp} | 0 .../protogalaxy/protogalaxy.test.cpp | 2 +- .../grand_product_library.test.cpp | 2 +- .../stdlib_circuit_builders/mega_flavor.hpp | 4 +- .../stdlib_circuit_builders/ultra_flavor.hpp | 4 +- .../stdlib_circuit_builders/ultra_keccak.hpp | 2 +- .../barretenberg/sumcheck/sumcheck.test.cpp | 34 +++---- .../relation_correctness.test.cpp | 10 +- .../translator_vm/translator_flavor.hpp | 4 +- 30 files changed, 140 insertions(+), 142 deletions(-) rename barretenberg/cpp/src/barretenberg/polynomials/{sparse_polynomial.cpp => polynomial.cpp} (76%) rename barretenberg/cpp/src/barretenberg/polynomials/{sparse_polynomial.hpp => polynomial.hpp} (85%) rename barretenberg/cpp/src/barretenberg/polynomials/{sparse_polynomial.test.cpp => polynomial.test.cpp} (100%) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp index d6a486b27ff..e099e100826 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp @@ -1,5 +1,5 @@ #include "barretenberg/commitment_schemes/ipa/ipa.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include using namespace benchmark; @@ -8,7 +8,7 @@ using namespace bb; namespace { using Curve = curve::Grumpkin; using Fr = Curve::ScalarField; -using Polynomial = SparsePolynomial; +using Polynomial = Polynomial; constexpr size_t MIN_POLYNOMIAL_DEGREE_LOG2 = 10; constexpr size_t MAX_POLYNOMIAL_DEGREE_LOG2 = 16; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp index 2a6b6414dbf..f2474384111 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/commitment_schemes/commitment_key.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" namespace bb { /** @@ -26,7 +26,7 @@ template class OpeningPair { */ template class ProverOpeningClaim { using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; public: Polynomial polynomial; // p diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp index f593dbbe706..209a202b3d5 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp @@ -61,7 +61,7 @@ template class CommitmentTest : public ::testing::Test { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; public: CommitmentTest() diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp index 5ac133f41d0..23142078def 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.hpp @@ -1,7 +1,7 @@ #pragma once #include "../claim.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include @@ -59,7 +59,7 @@ namespace bb { */ template struct GeminiProverOutput { std::vector> opening_pairs; - std::vector> witnesses; + std::vector> witnesses; }; namespace gemini { @@ -101,7 +101,7 @@ template inline std::vector squares_of_r(const Fr r, const size_t template class GeminiProver_ { using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; public: static std::vector compute_gemini_polynomials(std::span mle_opening_point, diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp index 2f5e04d3c3f..7e378bba250 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp @@ -1,7 +1,7 @@ #include "gemini.hpp" #include "../commitment_key.test.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include #include @@ -14,7 +14,7 @@ template class GeminiTest : public CommitmentTest { using GeminiVerifier = GeminiVerifier_; using Fr = typename Curve::ScalarField; using GroupElement = typename Curve::Element; - using Polynomial = typename bb::SparsePolynomial; + using Polynomial = typename bb::Polynomial; public: void execute_gemini_and_verify_claims(size_t log_n, diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp index 6035289000f..bdb31f2eac5 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.hpp @@ -79,7 +79,7 @@ template class IPA { using Commitment = typename Curve::AffineElement; using CK = CommitmentKey; using VK = VerifierCommitmentKey; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using VerifierAccumulator = bool; // These allow access to internal functions so that we can never use a mock transcript unless it's fuzzing or testing of IPA specifically diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp index a4394f52ae3..9bf59cd76d4 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp @@ -22,7 +22,7 @@ class IPATest : public CommitmentTest { using GroupElement = typename Curve::Element; using CK = CommitmentKey; using VK = VerifierCommitmentKey; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; }; } // namespace diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp index 99503cf410a..eda38cb2582 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp @@ -19,7 +19,7 @@ template class KZG { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; using GroupElement = typename Curve::Element; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using VerifierAccumulator = std::array; /** diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp index eb296da12f3..4f272c1d430 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -19,7 +19,7 @@ template class KZGTest : public CommitmentTest { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; using GroupElement = typename Curve::Element; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; }; TYPED_TEST_SUITE(KZGTest, CommitmentSchemeParams); @@ -64,7 +64,7 @@ TYPED_TEST(KZGTest, GeminiShplonkKzgWithShift) using KZG = KZG; using Fr = typename TypeParam::ScalarField; using GroupElement = typename TypeParam::Element; - using Polynomial = typename bb::SparsePolynomial; + using Polynomial = typename bb::Polynomial; const size_t n = 16; const size_t log_n = 4; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp index 32746eb049e..9eac7b4a48c 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp @@ -27,7 +27,7 @@ namespace bb { */ template class ShplonkProver_ { using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; public: /** diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp index 728ecfee7cf..f555d437d08 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/sparse_commitment.test.cpp @@ -1,5 +1,5 @@ #include "barretenberg/commitment_schemes/commitment_key.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include @@ -11,7 +11,7 @@ template class CommitmentKeyTest : public ::testing::Test { using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; public: template inline std::shared_ptr create_commitment_key(size_t num_points); @@ -46,7 +46,7 @@ TYPED_TEST(CommitmentKeyTest, CommitSparse) using CK = CommitmentKey; using G1 = Curve::AffineElement; using Fr = Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; const size_t num_points = 1 << 12; // large enough to ensure normal pippenger logic is used const size_t num_nonzero = 7; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp index 7056d3b1146..aa0cf5b0273 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.hpp @@ -5,7 +5,7 @@ #include "barretenberg/common/ref_span.hpp" #include "barretenberg/common/ref_vector.hpp" #include "barretenberg/common/zip_view.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" #include "barretenberg/transcript/transcript.hpp" @@ -38,7 +38,7 @@ template inline std::vector powers_of_challenge(const FF challeng template class ZeroMorphProver_ { using FF = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using OpeningClaim = ProverOpeningClaim; // TODO(#742): Set this N_max to be the number of G1 elements in the mocked zeromorph SRS once it's in place. diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp index 85393c785bd..146ce53b461 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/zeromorph/zeromorph.test.cpp @@ -10,7 +10,7 @@ template class ZeroMorphTest : public CommitmentTest; + using Polynomial = bb::Polynomial; using Commitment = typename Curve::AffineElement; using GroupElement = typename Curve::Element; using VerifierAccumulator = typename PCS::VerifierAccumulator; @@ -326,7 +326,7 @@ TYPED_TEST(ZeroMorphTest, QuotientConstruction) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; // Define size parameters size_t N = 16; @@ -374,7 +374,7 @@ TYPED_TEST(ZeroMorphTest, BatchedLiftedDegreeQuotient) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; const size_t N = 8; @@ -419,7 +419,7 @@ TYPED_TEST(ZeroMorphTest, PartiallyEvaluatedQuotientZeta) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; const size_t N = 8; @@ -503,7 +503,7 @@ TYPED_TEST(ZeroMorphTest, PartiallyEvaluatedQuotientZ) using Curve = typename TypeParam::Curve; using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; const size_t N = 8; size_t log_N = numeric::get_msb(N); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp index fe6847e7476..93cfbc82d89 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes_recursion/zeromorph.test.cpp @@ -36,7 +36,7 @@ TEST(ZeroMorphRecursionTest, ProveAndVerifySingle) using ZeroMorphProver = ZeroMorphProver_; using Fr = typename Curve::ScalarField; using NativeFr = typename Curve::NativeCurve::ScalarField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using ZeroMorphVerifier = ZeroMorphVerifier_; using Transcript = bb::BaseTranscript>; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp index 6c3a495fd71..5d560639642 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp @@ -8,7 +8,7 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/stdlib_circuit_builders/op_queue/ecc_op_queue.hpp" @@ -18,7 +18,7 @@ class ECCVMCircuitBuilder { public: using CycleGroup = bb::g1; using FF = grumpkin::fr; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using CycleScalar = typename CycleGroup::subgroup_field; using Element = typename CycleGroup::element; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 57fea5ebdf3..89b3b5a1593 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -7,7 +7,7 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/flavor/relation_definitions.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/ecc_vm/ecc_bools_relation.hpp" #include "barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp" @@ -31,7 +31,7 @@ class ECCVMFlavor { using PCS = IPA; using FF = typename Curve::ScalarField; using BF = typename Curve::BaseField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using GroupElement = typename G1::element; using Commitment = typename G1::affine_element; using CommitmentKey = bb::CommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp index 772188086ce..65c99f076ae 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_trace_checker.cpp @@ -34,7 +34,7 @@ bool ECCVMTraceChecker::check(Builder& builder, numeric::RNG* engine_ptr) compute_logderivative_inverse>(polynomials, params, num_rows); compute_grand_product>(polynomials, params); - polynomials.z_perm_shift = SparsePolynomial(polynomials.z_perm.shifted()); + polynomials.z_perm_shift = Polynomial(polynomials.z_perm.shifted()); const auto evaluate_relation = [&](const std::string& relation_name) { typename Relation::SumcheckArrayOfValuesOverSubrelations result; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 54ebf6c4a25..5b77595bca0 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -47,7 +47,7 @@ TEST(Flavor, AllEntitiesSpecialMemberFunctions) using Flavor = UltraFlavor; using FF = Flavor::FF; using PartiallyEvaluatedMultivariates = Flavor::PartiallyEvaluatedMultivariates; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; PartiallyEvaluatedMultivariates polynomials_A; auto random_poly = Polynomial(10); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 36be5bde8bb..dd108df0be6 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -7,7 +7,7 @@ #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/goblin/types.hpp" #include "barretenberg/plonk_honk_shared/instance_inspector.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/stdlib/honk_recursion/verifier/merge_recursive_verifier.hpp" #include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp" diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp similarity index 76% rename from barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp index 04cb8aef25f..a9b8ec99111 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp @@ -1,4 +1,4 @@ -#include "sparse_polynomial.hpp" +#include "polynomial.hpp" #include "barretenberg/common/assert.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/common/thread.hpp" @@ -22,7 +22,7 @@ template std::shared_ptr _allocate_aligned_memory(size_t n_e return std::static_pointer_cast(get_mem_slab(sizeof(Fr) * n_elements)); } -template void SparsePolynomial::allocate_backing_memory(size_t size, size_t virtual_size) +template void Polynomial::allocate_backing_memory(size_t size, size_t virtual_size) { coefficients_ = SharedShiftedVirtualZeroesArray{ size, /* actual memory size */ @@ -41,7 +41,7 @@ template void SparsePolynomial::allocate_backing_memory(size_t * * @param size The size of the polynomial. */ -template SparsePolynomial::SparsePolynomial(size_t size, size_t virtual_size) +template Polynomial::Polynomial(size_t size, size_t virtual_size) { allocate_backing_memory(size, virtual_size); memset(static_cast(coefficients_.data()), 0, sizeof(Fr) * size); @@ -54,7 +54,7 @@ template SparsePolynomial::SparsePolynomial(size_t size, size_ * @param size The initial size of the polynomial. * @param flag Signals that we do not zero memory. */ -template SparsePolynomial::SparsePolynomial(size_t size, size_t virtual_size, DontZeroMemory flag) +template Polynomial::Polynomial(size_t size, size_t virtual_size, DontZeroMemory flag) { // Flag is unused, but we don't memset 0 if passed. (void)flag; @@ -62,13 +62,12 @@ template SparsePolynomial::SparsePolynomial(size_t size, size_ } template -SparsePolynomial::SparsePolynomial(const SparsePolynomial& other) - : SparsePolynomial(other, other.size()) +Polynomial::Polynomial(const Polynomial& other) + : Polynomial(other, other.size()) {} // fully copying "expensive" constructor -template -SparsePolynomial::SparsePolynomial(const SparsePolynomial& other, const size_t target_size) +template Polynomial::Polynomial(const Polynomial& other, const size_t target_size) { allocate_backing_memory(std::max(target_size, other.size()), other.virtual_size()); @@ -79,10 +78,10 @@ SparsePolynomial::SparsePolynomial(const SparsePolynomial& other, const // interpolation constructor template -SparsePolynomial::SparsePolynomial(std::span interpolation_points, - std::span evaluations, - size_t virtual_size) - : SparsePolynomial(interpolation_points.size(), virtual_size) +Polynomial::Polynomial(std::span interpolation_points, + std::span evaluations, + size_t virtual_size) + : Polynomial(interpolation_points.size(), virtual_size) { ASSERT(coefficients_.size() > 0); @@ -90,7 +89,7 @@ SparsePolynomial::SparsePolynomial(std::span interpolation_points, evaluations.data(), coefficients_.data(), interpolation_points.data(), coefficients_.size()); } -template SparsePolynomial::SparsePolynomial(std::span coefficients, size_t virtual_size) +template Polynomial::Polynomial(std::span coefficients, size_t virtual_size) { allocate_backing_memory(coefficients.size(), virtual_size); @@ -100,7 +99,7 @@ template SparsePolynomial::SparsePolynomial(std::span SparsePolynomial& SparsePolynomial::operator=(const SparsePolynomial& other) +template Polynomial& Polynomial::operator=(const Polynomial& other) { if (this == &other) { return *this; @@ -112,14 +111,14 @@ template SparsePolynomial& SparsePolynomial::operator=(con return *this; } -template SparsePolynomial SparsePolynomial::share() const +template Polynomial Polynomial::share() const { - SparsePolynomial p; + Polynomial p; p.coefficients_ = coefficients_; return p; } -template bool SparsePolynomial::operator==(SparsePolynomial const& rhs) const +template bool Polynomial::operator==(Polynomial const& rhs) const { // If either is empty, both must be if (is_empty() || rhs.is_empty()) { @@ -138,7 +137,7 @@ template bool SparsePolynomial::operator==(SparsePolynomial co return true; } -template SparsePolynomial& SparsePolynomial::operator+=(std::span other) +template Polynomial& Polynomial::operator+=(std::span other) { const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); @@ -157,17 +156,17 @@ template SparsePolynomial& SparsePolynomial::operator+=(st return *this; } -template Fr SparsePolynomial::evaluate(const Fr& z, const size_t target_size) const +template Fr Polynomial::evaluate(const Fr& z, const size_t target_size) const { return polynomial_arithmetic::evaluate(data(), z, target_size); } -template Fr SparsePolynomial::evaluate(const Fr& z) const +template Fr Polynomial::evaluate(const Fr& z) const { return polynomial_arithmetic::evaluate(data(), z, size()); } -template Fr SparsePolynomial::evaluate_mle(std::span evaluation_points, bool shift) const +template Fr Polynomial::evaluate_mle(std::span evaluation_points, bool shift) const { const size_t m = evaluation_points.size(); @@ -208,8 +207,7 @@ template Fr SparsePolynomial::evaluate_mle(std::span return result; } -template -SparsePolynomial SparsePolynomial::partial_evaluate_mle(std::span evaluation_points) const +template Polynomial Polynomial::partial_evaluate_mle(std::span evaluation_points) const { // Get size of partial evaluation point u = (u_0,...,u_{m-1}) const size_t m = evaluation_points.size(); @@ -225,7 +223,7 @@ SparsePolynomial SparsePolynomial::partial_evaluate_mle(std::span intermediate(n_l, n_l, DontZeroMemory::FLAG); + Polynomial intermediate(n_l, n_l, DontZeroMemory::FLAG); // Evaluate variable X_{n-1} at u_{m-1} Fr u_l = evaluation_points[m - 1]; @@ -244,7 +242,7 @@ SparsePolynomial SparsePolynomial::partial_evaluate_mle(std::span result(n_l, n_l, DontZeroMemory::FLAG); + Polynomial result(n_l, n_l, DontZeroMemory::FLAG); for (size_t idx = 0; idx < n_l; ++idx) { result[idx] = intermediate[idx]; } @@ -257,7 +255,7 @@ SparsePolynomial SparsePolynomial::partial_evaluate_mle(std::span -void SparsePolynomial::fft(const EvaluationDomain& domain) +void Polynomial::fft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -267,7 +265,7 @@ void SparsePolynomial::fft(const EvaluationDomain& domain) } template -void SparsePolynomial::partial_fft(const EvaluationDomain& domain, Fr constant, bool is_coset) +void Polynomial::partial_fft(const EvaluationDomain& domain, Fr constant, bool is_coset) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -277,7 +275,7 @@ void SparsePolynomial::partial_fft(const EvaluationDomain& domain, Fr co } template -void SparsePolynomial::coset_fft(const EvaluationDomain& domain) +void Polynomial::coset_fft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -287,9 +285,9 @@ void SparsePolynomial::coset_fft(const EvaluationDomain& domain) } template -void SparsePolynomial::coset_fft(const EvaluationDomain& domain, - const EvaluationDomain& large_domain, - const size_t domain_extension) +void Polynomial::coset_fft(const EvaluationDomain& domain, + const EvaluationDomain& large_domain, + const size_t domain_extension) requires polynomial_arithmetic::SupportsFFT { size_t extended_size = domain.size * domain_extension; @@ -301,7 +299,7 @@ void SparsePolynomial::coset_fft(const EvaluationDomain& domain, } template -void SparsePolynomial::coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) +void Polynomial::coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -311,7 +309,7 @@ void SparsePolynomial::coset_fft_with_constant(const EvaluationDomain& d } template -void SparsePolynomial::coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) +void Polynomial::coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -321,7 +319,7 @@ void SparsePolynomial::coset_fft_with_generator_shift(const EvaluationDomain } template -void SparsePolynomial::ifft(const EvaluationDomain& domain) +void Polynomial::ifft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -331,7 +329,7 @@ void SparsePolynomial::ifft(const EvaluationDomain& domain) } template -void SparsePolynomial::ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) +void Polynomial::ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -341,7 +339,7 @@ void SparsePolynomial::ifft_with_constant(const EvaluationDomain& domain } template -void SparsePolynomial::coset_ifft(const EvaluationDomain& domain) +void Polynomial::coset_ifft(const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { ASSERT(in_place_operation_viable(domain.size)); @@ -351,30 +349,30 @@ void SparsePolynomial::coset_ifft(const EvaluationDomain& domain) } template -Fr SparsePolynomial::compute_kate_opening_coefficients(const Fr& z) +Fr Polynomial::compute_kate_opening_coefficients(const Fr& z) requires polynomial_arithmetic::SupportsFFT { return polynomial_arithmetic::compute_kate_opening_coefficients(data(), data(), z, size()); } template -Fr SparsePolynomial::compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) +Fr Polynomial::compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT { return polynomial_arithmetic::compute_barycentric_evaluation(data(), domain.size, z, domain); } template -Fr SparsePolynomial::evaluate_from_fft(const EvaluationDomain& large_domain, - const Fr& z, - const EvaluationDomain& small_domain) +Fr Polynomial::evaluate_from_fft(const EvaluationDomain& large_domain, + const Fr& z, + const EvaluationDomain& small_domain) requires polynomial_arithmetic::SupportsFFT { return polynomial_arithmetic::evaluate_from_fft(data(), large_domain, z, small_domain); } -template SparsePolynomial& SparsePolynomial::operator-=(std::span other) +template Polynomial& Polynomial::operator-=(std::span other) { const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); @@ -393,7 +391,7 @@ template SparsePolynomial& SparsePolynomial::operator-=(st return *this; } -template SparsePolynomial& SparsePolynomial::operator*=(const Fr scaling_factor) +template Polynomial& Polynomial::operator*=(const Fr scaling_factor) { ASSERT(in_place_operation_viable()); @@ -411,7 +409,7 @@ template SparsePolynomial& SparsePolynomial::operator*=(co return *this; } -template void SparsePolynomial::add_scaled(std::span other, Fr scaling_factor) +template void Polynomial::add_scaled(std::span other, Fr scaling_factor) { const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); @@ -434,9 +432,9 @@ template void SparsePolynomial::add_scaled(std::span * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). */ -template SparsePolynomial SparsePolynomial::shifted() const +template Polynomial Polynomial::shifted() const { - SparsePolynomial result; + Polynomial result; result.coefficients_ = coefficients_; result.coefficients_.shift_ += 1; // We only expect to shift by 1 @@ -449,7 +447,7 @@ template SparsePolynomial SparsePolynomial::shifted() cons * @brief sets a block of memory to all zeroes * Used, for example, when one Polynomioal is instantiated from another one with size_>= other.size_. */ -template void SparsePolynomial::zero_memory_beyond(const size_t start_position) +template void Polynomial::zero_memory_beyond(const size_t start_position) { size_t end = size(); ASSERT(end >= start_position); @@ -460,7 +458,7 @@ template void SparsePolynomial::zero_memory_beyond(const size_ } } -template class SparsePolynomial; -template class SparsePolynomial; +template class Polynomial; +template class Polynomial; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp similarity index 85% rename from barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp rename to barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index e655c08ead5..443740ce28f 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -10,7 +10,7 @@ namespace bb { /** - * @brief Sparse polynomial class that represents the coefficients 'a' of a_0 + a_1 x + a_n x^n of + * @brief Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x + a_n x^n of * a finite field polynomial equation of degree that is at most the size of some zk circuit. * Past 'n' it has a virtual size where it conceptually has coefficients all equal to 0. * Notably, we allow indexing past 'n' up to our virtual size (checked only in a debug build, however). @@ -23,31 +23,31 @@ namespace bb { * * @tparam Fr the finite field type. */ -template class SparsePolynomial { +template class Polynomial { public: using FF = Fr; enum class DontZeroMemory { FLAG }; - SparsePolynomial(size_t size, size_t virtual_size); + Polynomial(size_t size, size_t virtual_size); // Intended just for plonk, where size == virtual_size always - SparsePolynomial(size_t size) - : SparsePolynomial(size, size) + Polynomial(size_t size) + : Polynomial(size, size) {} // Constructor that does not initialize values, use with caution to save time. - SparsePolynomial(size_t size, size_t virtual_size, DontZeroMemory flag); - SparsePolynomial(const SparsePolynomial& other); - SparsePolynomial(const SparsePolynomial& other, size_t target_size); + Polynomial(size_t size, size_t virtual_size, DontZeroMemory flag); + Polynomial(const Polynomial& other); + Polynomial(const Polynomial& other, size_t target_size); - SparsePolynomial(SparsePolynomial&& other) noexcept = default; + Polynomial(Polynomial&& other) noexcept = default; - SparsePolynomial(std::span coefficients, size_t virtual_size); + Polynomial(std::span coefficients, size_t virtual_size); - SparsePolynomial(std::span coefficients) - : SparsePolynomial(coefficients, coefficients.size()) + Polynomial(std::span coefficients) + : Polynomial(coefficients, coefficients.size()) {} // Allow polynomials to be entirely reset/dormant - SparsePolynomial() = default; + Polynomial() = default; /** * @brief Create the degree-(m-1) polynomial T(X) that interpolates the given evaluations. @@ -56,17 +56,17 @@ template class SparsePolynomial { * @param interpolation_points (x₁,…,xₘ) * @param evaluations (y₁,…,yₘ) */ - SparsePolynomial(std::span interpolation_points, std::span evaluations, size_t virtual_size); + Polynomial(std::span interpolation_points, std::span evaluations, size_t virtual_size); // move assignment - SparsePolynomial& operator=(SparsePolynomial&& other) noexcept = default; - SparsePolynomial& operator=(const SparsePolynomial& other); - ~SparsePolynomial() = default; + Polynomial& operator=(Polynomial&& other) noexcept = default; + Polynomial& operator=(const Polynomial& other); + ~Polynomial() = default; /** * Return a shallow clone of the polynomial. i.e. underlying memory is shared. */ - SparsePolynomial share() const; + Polynomial share() const; void clear() { coefficients_ = SharedShiftedVirtualZeroesArray{}; } @@ -88,7 +88,7 @@ template class SparsePolynomial { return true; } - bool operator==(SparsePolynomial const& rhs) const; + bool operator==(Polynomial const& rhs) const; void set(size_t i, const Fr& value) { coefficients_.set(i, value); }; Fr get(size_t i) const { return coefficients_.get(i); }; @@ -106,7 +106,7 @@ template class SparsePolynomial { * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). */ - SparsePolynomial shifted() const; + Polynomial shifted() const; /** * @brief evaluates p(X) = ∑ᵢ aᵢ⋅Xⁱ considered as multi-linear extension p(X₀,…,Xₘ₋₁) = ∑ᵢ aᵢ⋅Lᵢ(X₀,…,Xₘ₋₁) @@ -137,7 +137,7 @@ template class SparsePolynomial { * @param evaluation_points an MLE partial evaluation point u = (u_0,…,u_{m-1}) * @return DensePolynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) */ - SparsePolynomial partial_evaluate_mle(std::span evaluation_points) const; + Polynomial partial_evaluate_mle(std::span evaluation_points) const; Fr compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT; @@ -197,21 +197,21 @@ template class SparsePolynomial { * * @param other q(X) */ - SparsePolynomial& operator+=(std::span other); + Polynomial& operator+=(std::span other); /** * @brief subtracts the polynomial q(X) 'other'. * * @param other q(X) */ - SparsePolynomial& operator-=(std::span other); + Polynomial& operator-=(std::span other); /** * @brief sets this = p(X) to s⋅p(X) * * @param scaling_factor s */ - SparsePolynomial& operator*=(Fr scaling_factor); + Polynomial& operator*=(Fr scaling_factor); std::span as_span() const { @@ -234,11 +234,11 @@ template class SparsePolynomial { return coefficients_.data()[i]; } - static SparsePolynomial random(size_t size) { return random(size, size); } + static Polynomial random(size_t size) { return random(size, size); } - static SparsePolynomial random(size_t size, size_t virtual_size) + static Polynomial random(size_t size, size_t virtual_size) { - SparsePolynomial p(size, virtual_size, DontZeroMemory::FLAG); + Polynomial p(size, virtual_size, DontZeroMemory::FLAG); std::generate_n(p.coefficients_.data(), size, []() { return Fr::random_element(); }); return p; } @@ -261,7 +261,7 @@ template class SparsePolynomial { SharedShiftedVirtualZeroesArray coefficients_; }; -template inline std::ostream& operator<<(std::ostream& os, SparsePolynomial const& p) +template inline std::ostream& operator<<(std::ostream& os, Polynomial const& p) { if (p.size() == 0) { return os << "[]"; diff --git a/barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/polynomials/sparse_polynomial.test.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 4ee685df09e..474391a6f19 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -185,7 +185,7 @@ template class ProtoGalaxyTests : public testing::Test { // Construct fully random prover polynomials ProverPolynomials full_polynomials; for (auto& poly : full_polynomials.get_all()) { - poly = bb::SparsePolynomial::random(instance_size); + poly = bb::Polynomial::random(instance_size); } auto relation_parameters = bb::RelationParameters::get_random(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp index 0d01f94b756..dd124e442ab 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp @@ -10,7 +10,7 @@ using namespace bb; template class GrandProductTests : public testing::Test { - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; public: void SetUp() { srs::init_crs_factory("../srs_db/ignition"); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 457221e7891..618b726c2ff 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -7,7 +7,7 @@ #include "barretenberg/honk/proof_system/types/proof.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/databus_lookup_relation.hpp" @@ -33,7 +33,7 @@ class MegaFlavor { using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using PCS = KZG; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 2f431c07f70..ce600c78a31 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -8,7 +8,7 @@ #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/legacy_polynomial.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" @@ -30,7 +30,7 @@ class UltraFlavor { using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using PCS = KZG; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index 20d01db94f4..d01cf49b053 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -30,7 +30,7 @@ class UltraKeccakFlavor { using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using PCS = KZG; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using CommitmentKey = bb::CommitmentKey; using VerifierCommitmentKey = bb::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 0164f1b5f11..e6c1f1539fa 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -1,6 +1,6 @@ #include "sumcheck.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" @@ -16,7 +16,7 @@ using namespace bb; namespace { using Flavor = UltraFlavor; using FF = typename Flavor::FF; -using Polynomial = SparsePolynomial; +using Polynomial = Polynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; using RelationSeparator = Flavor::RelationSeparator; const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; @@ -53,7 +53,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -116,7 +116,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // full polynomials at challenge u via the evaluate_mle() function std::vector u_challenge = { u_0, u_1, u_2 }; for (auto [full_poly, claimed_eval] : zip_view(full_polynomials.get_all(), output.claimed_evaluations.get_all())) { - SparsePolynomial poly(full_poly); + Polynomial poly(full_poly); auto v_expected = poly.evaluate_mle(u_challenge); EXPECT_EQ(v_expected, claimed_eval); } @@ -129,7 +129,7 @@ TEST_F(SumcheckTests, Prover) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -176,9 +176,9 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) // Construct prover polynomials where each is the zero polynomial. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> zero_polynomials; + std::array, NUM_POLYNOMIALS> zero_polynomials; for (auto& poly : zero_polynomials) { - poly = SparsePolynomial(multivariate_n); + poly = Polynomial(multivariate_n); } auto full_polynomials = construct_ultra_full_polynomials(zero_polynomials); @@ -201,16 +201,16 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) std::array q_arith = { 0, 1, 1, 0 }; // Setting all of these to 0 ensures the GrandProductRelation is satisfied - full_polynomials.w_l = SparsePolynomial(w_l); - full_polynomials.w_r = SparsePolynomial(w_r); - full_polynomials.w_o = SparsePolynomial(w_o); - full_polynomials.w_4 = SparsePolynomial(w_4); - full_polynomials.q_m = SparsePolynomial(q_m); - full_polynomials.q_l = SparsePolynomial(q_l); - full_polynomials.q_r = SparsePolynomial(q_r); - full_polynomials.q_o = SparsePolynomial(q_o); - full_polynomials.q_c = SparsePolynomial(q_c); - full_polynomials.q_arith = SparsePolynomial(q_arith); + full_polynomials.w_l = Polynomial(w_l); + full_polynomials.w_r = Polynomial(w_r); + full_polynomials.w_o = Polynomial(w_o); + full_polynomials.w_4 = Polynomial(w_4); + full_polynomials.q_m = Polynomial(q_m); + full_polynomials.q_l = Polynomial(q_l); + full_polynomials.q_r = Polynomial(q_r); + full_polynomials.q_o = Polynomial(q_o); + full_polynomials.q_c = Polynomial(q_c); + full_polynomials.q_arith = Polynomial(q_arith); // Set aribitrary random relation parameters RelationParameters relation_parameters{ diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp index 528021668f6..14336957ea7 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp @@ -43,7 +43,7 @@ TEST_F(TranslatorRelationCorrectnessTests, Permutation) using Flavor = TranslatorFlavor; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; auto& engine = numeric::get_debug_randomness(); const size_t mini_circuit_size = 2048; auto full_circuit_size = mini_circuit_size * Flavor::CONCATENATION_GROUP_SIZE; @@ -160,7 +160,7 @@ TEST_F(TranslatorRelationCorrectnessTests, DeltaRangeConstraint) using Flavor = TranslatorFlavor; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; auto& engine = numeric::get_debug_randomness(); const size_t mini_circuit_size = 2048; const auto circuit_size = Flavor::CONCATENATION_GROUP_SIZE * mini_circuit_size; @@ -241,7 +241,7 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness) using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; auto& engine = numeric::get_debug_randomness(); @@ -344,7 +344,7 @@ TEST_F(TranslatorRelationCorrectnessTests, Decomposition) using BF = typename Flavor::BF; using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; auto& engine = numeric::get_debug_randomness(); constexpr size_t mini_circuit_size = 2048; @@ -719,7 +719,7 @@ TEST_F(TranslatorRelationCorrectnessTests, NonNative) using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; using GroupElement = typename Flavor::GroupElement; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; constexpr size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS; constexpr auto mini_circuit_size = 2048; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 9f55332272c..22bb710e84a 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -7,7 +7,7 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/flavor/relation_definitions.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" -#include "barretenberg/polynomials/sparse_polynomial.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/translator_vm/translator_decomposition_relation.hpp" @@ -32,7 +32,7 @@ class TranslatorFlavor { using VerifierCommitmentKey = bb::VerifierCommitmentKey; using FF = Curve::ScalarField; using BF = Curve::BaseField; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using RelationSeparator = FF; // Indicates that this flavor runs with non-ZK Sumcheck. static constexpr bool HasZK = false; From faa89fe360bf2ecc387f550cb3f6986ddc8098e9 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 19:43:31 +0000 Subject: [PATCH 10/15] fix shift case --- .../barretenberg/polynomials/polynomial.cpp | 16 ++++++---- .../shared_shifted_virtual_zeroes_array.hpp | 7 +++-- .../barretenberg/sumcheck/sumcheck.test.cpp | 30 +++++++++---------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp index a9b8ec99111..40e91a7af18 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp @@ -25,10 +25,12 @@ template std::shared_ptr _allocate_aligned_memory(size_t n_e template void Polynomial::allocate_backing_memory(size_t size, size_t virtual_size) { coefficients_ = SharedShiftedVirtualZeroesArray{ - size, /* actual memory size */ - virtual_size, /* virtual size, i.e. until what size do we conceptually have zeroes */ - 0, /* shift, initially 0 */ - _allocate_aligned_memory(size) /* our backing memory, since shift is 0 it is equal to our memory size */ + size, /* actual memory size */ + virtual_size, /* virtual size, i.e. until what size do we conceptually have zeroes */ + 0, /* shift, initially 0 */ + _allocate_aligned_memory(size + MAXIMUM_COEFFICIENT_SHIFT) + /* Our backing memory, since shift is 0 it is equal to our memory size. + * We add one to the size here to allow for an efficient shift by 1 that retains size. */ }; } @@ -74,6 +76,7 @@ template Polynomial::Polynomial(const Polynomial& other, c memcpy(static_cast(coefficients_.data()), static_cast(other.coefficients_.data()), sizeof(Fr) * other.size()); + zero_memory_beyond(other.size()); } // interpolation constructor @@ -434,12 +437,15 @@ template void Polynomial::add_scaled(std::span other */ template Polynomial Polynomial::shifted() const { + ASSERT(data()[0].is_zero()); Polynomial result; result.coefficients_ = coefficients_; result.coefficients_.shift_ += 1; // We only expect to shift by 1 - ASSERT(data()[0].is_zero()); ASSERT(result.coefficients_.shift_ == 1); + ASSERT(result.size() == size() - 1); + ASSERT(result.virtual_size() == virtual_size() - 1); + ASSERT(result.data()[0] == data()[1]); return result; } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp index e6b90c110c1..bfe38a38a5e 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp @@ -30,9 +30,12 @@ template struct SharedShiftedVirtualZeroesArray { } // Method to get the memory-backed size such that we can set index 0..size()-1. - size_t size() const { return size_ - shift_; } + // Note: We DO NOT reduce our size or virtual size by shift_. This is because + // only support a shift by values that are included in backing_memory_. + // This guarantee is to be upheld by the class that uses SharedShiftedVirtualZeroesArray. + size_t size() const { return size_; } // Method to get virtual size such that we can get index 0..virtual_size()-1. - size_t virtual_size() const { return virtual_size_ - shift_; }; + size_t virtual_size() const { return virtual_size_; }; T* data() { return backing_memory_.get() + shift_; } const T* data() const { return backing_memory_.get() + shift_; } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index e6c1f1539fa..ebbb6b4e191 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -53,7 +53,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -116,7 +116,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // full polynomials at challenge u via the evaluate_mle() function std::vector u_challenge = { u_0, u_1, u_2 }; for (auto [full_poly, claimed_eval] : zip_view(full_polynomials.get_all(), output.claimed_evaluations.get_all())) { - Polynomial poly(full_poly); + bb::Polynomial poly(full_poly); auto v_expected = poly.evaluate_mle(u_challenge); EXPECT_EQ(v_expected, claimed_eval); } @@ -129,7 +129,7 @@ TEST_F(SumcheckTests, Prover) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -176,9 +176,9 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) // Construct prover polynomials where each is the zero polynomial. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> zero_polynomials; + std::array, NUM_POLYNOMIALS> zero_polynomials; for (auto& poly : zero_polynomials) { - poly = Polynomial(multivariate_n); + poly = bb::Polynomial(multivariate_n); } auto full_polynomials = construct_ultra_full_polynomials(zero_polynomials); @@ -201,16 +201,16 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) std::array q_arith = { 0, 1, 1, 0 }; // Setting all of these to 0 ensures the GrandProductRelation is satisfied - full_polynomials.w_l = Polynomial(w_l); - full_polynomials.w_r = Polynomial(w_r); - full_polynomials.w_o = Polynomial(w_o); - full_polynomials.w_4 = Polynomial(w_4); - full_polynomials.q_m = Polynomial(q_m); - full_polynomials.q_l = Polynomial(q_l); - full_polynomials.q_r = Polynomial(q_r); - full_polynomials.q_o = Polynomial(q_o); - full_polynomials.q_c = Polynomial(q_c); - full_polynomials.q_arith = Polynomial(q_arith); + full_polynomials.w_l = bb::Polynomial(w_l); + full_polynomials.w_r = bb::Polynomial(w_r); + full_polynomials.w_o = bb::Polynomial(w_o); + full_polynomials.w_4 = bb::Polynomial(w_4); + full_polynomials.q_m = bb::Polynomial(q_m); + full_polynomials.q_l = bb::Polynomial(q_l); + full_polynomials.q_r = bb::Polynomial(q_r); + full_polynomials.q_o = bb::Polynomial(q_o); + full_polynomials.q_c = bb::Polynomial(q_c); + full_polynomials.q_arith = bb::Polynomial(q_arith); // Set aribitrary random relation parameters RelationParameters relation_parameters{ From 637892304509b613f7d7666b56477ab0a788e0fd Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 19:46:24 +0000 Subject: [PATCH 11/15] shifts --- .../barretenberg/polynomials/polynomial.cpp | 4 ++-- .../shared_shifted_virtual_zeroes_array.hpp | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp index 40e91a7af18..dfa959f5f03 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp @@ -443,8 +443,8 @@ template Polynomial Polynomial::shifted() const result.coefficients_.shift_ += 1; // We only expect to shift by 1 ASSERT(result.coefficients_.shift_ == 1); - ASSERT(result.size() == size() - 1); - ASSERT(result.virtual_size() == virtual_size() - 1); + ASSERT(result.size() == size()); + ASSERT(result.virtual_size() == virtual_size()); ASSERT(result.data()[0] == data()[1]); return result; } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp index bfe38a38a5e..acc99519e00 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp @@ -15,36 +15,33 @@ template struct SharedShiftedVirtualZeroesArray { // Method to set the value at a specific index void set(size_t index, const T& value) { - ASSERT(index < size()); + ASSERT(index < size_); data()[index] = value; } // Method to get the value at a specific index T get(size_t index) const { - ASSERT(index < virtual_size()); - if (index < size()) { + ASSERT(index < virtual_size_); + if (index < size_) { return data()[index]; } return T{}; // Return default element when index is out of the actual filled size } - // Method to get the memory-backed size such that we can set index 0..size()-1. - // Note: We DO NOT reduce our size or virtual size by shift_. This is because - // only support a shift by values that are included in backing_memory_. - // This guarantee is to be upheld by the class that uses SharedShiftedVirtualZeroesArray. - size_t size() const { return size_; } - // Method to get virtual size such that we can get index 0..virtual_size()-1. - size_t virtual_size() const { return virtual_size_; }; - T* data() { return backing_memory_.get() + shift_; } const T* data() const { return backing_memory_.get() + shift_; } // MEMBERS: // The actual size of the array allocation + // Memory-backed size such that we can set index 0..size()-1. + // Note: We DO NOT reduce our size or virtual size by shift_. This is because + // only support a shift by values that are included in backing_memory_. + // This guarantee is to be upheld by the class that uses SharedShiftedVirtualZeroesArray. size_t size_ = 0; // The logical size of the vector, indices size_ to virtual_size - 1 return T{} when indexed. // This is really mainly used for a debug check that we never index >= virtual_size_; + // Virtual size such that we can get index 0..virtual_size()-1. size_t virtual_size_ = 0; // An offset into the array, used to implement shifted polynomials. size_t shift_ = 0; From ea0a36c73a4acc1ebb785312af82c8f40262ef58 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 19:55:05 +0000 Subject: [PATCH 12/15] fixes --- .../composer/composer_lib.hpp | 4 +- .../polynomials/legacy_polynomial.test.cpp | 14 +++--- .../barretenberg/polynomials/polynomial.cpp | 47 ++++++++++--------- .../barretenberg/polynomials/polynomial.hpp | 17 +++---- .../polynomials/polynomial.test.cpp | 4 +- .../vm/avm/generated/flavor_settings.hpp | 2 +- .../templates/flavor_settings.hpp.hbs | 2 +- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index c9e403baeb0..70e35729e01 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -55,9 +55,9 @@ void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace size_t offset = dyadic_circuit_size - circuit.get_tables_size(); // read_counts = - // typename Flavor::SparsePolynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); + // typename Flavor::Polynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); // read_tags = - // typename Flavor::SparsePolynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); + // typename Flavor::Polynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); // WORKTODO(sparse) circuit.get_tables_size() is the actual size of our structured polynomial; size_t table_offset = offset; // offset of the present table in the table polynomials diff --git a/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp index 3952c8cb1b6..79396167c45 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.test.cpp @@ -6,12 +6,12 @@ using namespace bb; // Simple test/demonstration of shifted functionality -TEST(Polynomial, Shifted) +TEST(LegacyPolynomial, Shifted) { using FF = bb::fr; - using Polynomial = LegacyPolynomial; + using LegacyPolynomial = LegacyPolynomial; const size_t SIZE = 10; - auto poly = Polynomial::random(SIZE); + auto poly = LegacyPolynomial::random(SIZE); poly[0] = 0; // make it shiftable // Instantiate the shift via the shited method @@ -32,12 +32,12 @@ TEST(Polynomial, Shifted) } // Simple test/demonstration of share functionality -TEST(Polynomial, Share) +TEST(LegacyPolynomial, Share) { using FF = bb::fr; - using Polynomial = LegacyPolynomial; + using LegacyPolynomial = LegacyPolynomial; const size_t SIZE = 10; - auto poly = Polynomial::random(SIZE); + auto poly = LegacyPolynomial::random(SIZE); // "clone" the poly via the share method auto poly_clone = poly.share(); @@ -54,7 +54,7 @@ TEST(Polynomial, Share) // If reset the original poly, it will no longer be equal to the clone made earlier // Note: if we had not made a clone, the memory from the original poly would be leaked - auto poly2 = Polynomial::random(SIZE); + auto poly2 = LegacyPolynomial::random(SIZE); poly = poly2.share(); EXPECT_NE(poly_clone, poly); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp index dfa959f5f03..5a016ce2a32 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp @@ -32,6 +32,12 @@ template void Polynomial::allocate_backing_memory(size_t size, /* Our backing memory, since shift is 0 it is equal to our memory size. * We add one to the size here to allow for an efficient shift by 1 that retains size. */ }; + // We need to zero the extra padding memory that we reserve for shifts. + // We do this here as generally code that does not zero memory and then + // later initializes it won't generally also initialize the padding. + for (size_t i = 0; i < MAXIMUM_COEFFICIENT_SHIFT; i++) { + data()[size + i] = Fr{}; + } } /** @@ -39,7 +45,7 @@ template void Polynomial::allocate_backing_memory(size_t size, **/ /** - * @brief Initialize a SparsePolynomial to size 'size', zeroing memory. + * @brief Initialize a Polynomial to size 'size', zeroing memory. * * @param size The size of the polynomial. */ @@ -50,7 +56,7 @@ template Polynomial::Polynomial(size_t size, size_t virtual_si } /** - * @brief Initialize a SparsePolynomial to size 'size'. + * @brief Initialize a Polynomial to size 'size'. * Important: This does NOT zero memory. * * @param size The initial size of the polynomial. @@ -86,10 +92,10 @@ Polynomial::Polynomial(std::span interpolation_points, size_t virtual_size) : Polynomial(interpolation_points.size(), virtual_size) { - ASSERT(coefficients_.size() > 0); + ASSERT(coefficients_.size_ > 0); polynomial_arithmetic::compute_efficient_interpolation( - evaluations.data(), coefficients_.data(), interpolation_points.data(), coefficients_.size()); + evaluations.data(), coefficients_.data(), interpolation_points.data(), coefficients_.size_); } template Polynomial::Polynomial(std::span coefficients, size_t virtual_size) @@ -107,10 +113,10 @@ template Polynomial& Polynomial::operator=(const Polynomia if (this == &other) { return *this; } - allocate_backing_memory(other.coefficients_.size(), other.coefficients_.virtual_size()); + allocate_backing_memory(other.coefficients_.size_, other.coefficients_.virtual_size_); memcpy(static_cast(coefficients_.data()), static_cast(other.coefficients_.data()), - sizeof(Fr) * other.coefficients_.size()); + sizeof(Fr) * other.coefficients_.size_); return *this; } @@ -177,13 +183,13 @@ template Fr Polynomial::evaluate_mle(std::span evalu ASSERT(size() == static_cast(1 << m)); // we do m rounds l = 0,...,m-1. - // in round l, n_l is the size of the buffer containing the SparsePolynomial partially evaluated + // in round l, n_l is the size of the buffer containing the Polynomial partially evaluated // at u₀,..., u_l. // in round 0, this is half the size of n size_t n_l = 1 << (m - 1); - // temporary buffer of half the size of the SparsePolynomial - // TODO(AD): Make this a SparsePolynomial with DontZeroMemory::FLAG + // temporary buffer of half the size of the Polynomial + // TODO(AD): Make this a Polynomial with DontZeroMemory::FLAG auto tmp_ptr = _allocate_aligned_memory(sizeof(Fr) * n_l); auto tmp = tmp_ptr.get(); @@ -215,24 +221,24 @@ template Polynomial Polynomial::partial_evaluate_mle(std:: // Get size of partial evaluation point u = (u_0,...,u_{m-1}) const size_t m = evaluation_points.size(); - // Assert that the size of the SparsePolynomial being evaluated is a power of 2 greater than (1 << m) + // Assert that the size of the Polynomial being evaluated is a power of 2 greater than (1 << m) ASSERT(numeric::is_power_of_two(size())); ASSERT(size() >= static_cast(1 << m)); size_t n = numeric::get_msb(size()); - // Partial evaluation is done in m rounds l = 0,...,m-1. At the end of round l, the SparsePolynomial has been + // Partial evaluation is done in m rounds l = 0,...,m-1. At the end of round l, the Polynomial has been // partially evaluated at u_{m-l-1}, ..., u_{m-1} in variables X_{n-l-1}, ..., X_{n-1}. The size of this - // SparsePolynomial is n_l. + // Polynomial is n_l. size_t n_l = 1 << (n - 1); - // Temporary buffer of half the size of the SparsePolynomial + // Temporary buffer of half the size of the Polynomial Polynomial intermediate(n_l, n_l, DontZeroMemory::FLAG); // Evaluate variable X_{n-1} at u_{m-1} Fr u_l = evaluation_points[m - 1]; for (size_t i = 0; i < n_l; i++) { - // Initiate our intermediate results using this SparsePolynomial. + // Initiate our intermediate results using this Polynomial. intermediate[i] = get(i) + u_l * (get(i + n_l) - get(i)); } // Evaluate m-1 variables X_{n-l-1}, ..., X_{n-2} at m-1 remaining values u_0,...,u_{m-2}) @@ -244,7 +250,7 @@ template Polynomial Polynomial::partial_evaluate_mle(std:: } } - // Construct resulting SparsePolynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) from buffer + // Construct resulting Polynomial g(X_0,…,X_{n-m-1})) = p(X_0,…,X_{n-m-1},u_0,...u_{m-1}) from buffer Polynomial result(n_l, n_l, DontZeroMemory::FLAG); for (size_t idx = 0; idx < n_l; ++idx) { result[idx] = intermediate[idx]; @@ -430,7 +436,7 @@ template void Polynomial::add_scaled(std::span other } /** - * @brief Returns a SparsePolynomial the left-shift of self. + * @brief Returns a Polynomial the left-shift of self. * * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). @@ -438,14 +444,13 @@ template void Polynomial::add_scaled(std::span other template Polynomial Polynomial::shifted() const { ASSERT(data()[0].is_zero()); + ASSERT(size() > 0); + ASSERT(data()[size()].is_zero()); // relies on MAXIMUM_COEFFICIENT_SHIFT >= 1 Polynomial result; result.coefficients_ = coefficients_; result.coefficients_.shift_ += 1; - // We only expect to shift by 1 - ASSERT(result.coefficients_.shift_ == 1); - ASSERT(result.size() == size()); - ASSERT(result.virtual_size() == virtual_size()); - ASSERT(result.data()[0] == data()[1]); + // We only expect to shift by MAXIMUM_COEFFICIENT_SHIFT + ASSERT(result.coefficients_.shift_ <= MAXIMUM_COEFFICIENT_SHIFT); return result; } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index 443740ce28f..30dc44df7a0 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -78,7 +78,7 @@ template class Polynomial { { if (is_empty()) { ASSERT(false); - info("Checking is_zero on an empty SparsePolynomial!"); + info("Checking is_zero on an empty Polynomial!"); } for (size_t i = 0; i < size(); i++) { if (coefficients_.data()[i] != 0) { @@ -93,7 +93,7 @@ template class Polynomial { void set(size_t i, const Fr& value) { coefficients_.set(i, value); }; Fr get(size_t i) const { return coefficients_.get(i); }; - bool is_empty() const { return coefficients_.size() == 0; } + bool is_empty() const { return coefficients_.size_ == 0; } Fr* begin() { return data(); } Fr* end() { return data() + size(); } @@ -101,7 +101,7 @@ template class Polynomial { const Fr* end() const { return data() + size(); } /** - * @brief Returns a SparsePolynomial the left-shift of self. + * @brief Returns a Polynomial the left-shift of self. * * @details If the n coefficients of self are (0, a₁, …, aₙ₋₁), * we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁). @@ -213,13 +213,10 @@ template class Polynomial { */ Polynomial& operator*=(Fr scaling_factor); - std::span as_span() const - { - return { coefficients_.data(), coefficients_.data() + coefficients_.size() }; - } - std::span as_span() { return { coefficients_.data(), coefficients_.data() + coefficients_.size() }; } - std::size_t size() const { return coefficients_.size(); } - std::size_t virtual_size() const { return coefficients_.virtual_size(); } + std::span as_span() const { return { coefficients_.data(), coefficients_.data() + coefficients_.size_ }; } + std::span as_span() { return { coefficients_.data(), coefficients_.data() + coefficients_.size_ }; } + std::size_t size() const { return coefficients_.size_; } + std::size_t virtual_size() const { return coefficients_.virtual_size_; } Fr* data() { return coefficients_.data(); } const Fr* data() const { return coefficients_.data(); } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp index 6902ae5a3d5..3952c8cb1b6 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp @@ -6,7 +6,7 @@ using namespace bb; // Simple test/demonstration of shifted functionality -TEST(SparsePolynomial, Shifted) +TEST(Polynomial, Shifted) { using FF = bb::fr; using Polynomial = LegacyPolynomial; @@ -32,7 +32,7 @@ TEST(SparsePolynomial, Shifted) } // Simple test/demonstration of share functionality -TEST(SparsePolynomial, Share) +TEST(Polynomial, Share) { using FF = bb::fr; using Polynomial = LegacyPolynomial; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp index b62a8641eee..98b3085f4ff 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor_settings.hpp @@ -16,7 +16,7 @@ class AvmFlavorSettings { using PCS = KZG; using FF = G1::subgroup_field; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using PolynomialHandle = std::span; using GroupElement = G1::element; using Commitment = G1::affine_element; diff --git a/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs index 2d6d37748fe..93039d496a5 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs @@ -16,7 +16,7 @@ class {{name}}FlavorSettings { using PCS = KZG; using FF = G1::subgroup_field; - using Polynomial = bb::SparsePolynomial; + using Polynomial = bb::Polynomial; using PolynomialHandle = std::span; using GroupElement = G1::element; using Commitment = G1::affine_element; From 4e59754c5aad037f1aac5c187af1dd3980f27434 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Aug 2024 20:15:37 +0000 Subject: [PATCH 13/15] header simplification --- .../benchmark/basics_bench/basics.bench.cpp | 3 ++- .../src/barretenberg/commitment_schemes/claim.hpp | 2 +- .../commitment_schemes/commit.bench.cpp | 13 +++++++------ .../commitment_schemes/commitment_key.hpp | 1 - .../commitment_schemes/commitment_key.test.hpp | 1 - .../commitment_schemes/ipa/ipa.fuzzer.cpp | 3 ++- .../commitment_schemes/ipa/ipa.test.cpp | 1 - .../src/barretenberg/commitment_schemes/kzg/kzg.hpp | 1 - .../commitment_schemes/kzg/kzg.test.cpp | 1 - .../commitment_schemes/shplonk/shplonk.test.cpp | 1 - .../commitment_schemes/verification_key.hpp | 1 - .../src/barretenberg/eccvm/eccvm_composer.test.cpp | 1 - .../cpp/src/barretenberg/eccvm/eccvm_prover.cpp | 1 - .../cpp/src/barretenberg/flavor/flavor.test.cpp | 1 - .../honk/proof_system/permutation_library.hpp | 1 - .../cpp/src/barretenberg/honk/utils/testing.hpp | 1 - .../plonk_honk_shared/composer/permutation_lib.hpp | 1 - .../library/grand_product_library.hpp | 1 - .../barretenberg/polynomials/polynomial.test.cpp | 12 +++++------- .../relations/databus_lookup_relation.hpp | 1 - .../relations/ecc_vm/ecc_lookup_relation.hpp | 1 - .../relations/ecc_vm/ecc_set_relation.hpp | 1 - .../generic_lookup/generic_lookup_relation.hpp | 1 - .../generic_permutation_relation.hpp | 1 - .../relations/logderiv_lookup_relation.hpp | 1 - .../verifier/protogalaxy_recursive_verifier.cpp | 1 - .../grand_product_library.test.cpp | 1 - .../mega_recursive_flavor.hpp | 1 - .../ultra_circuit_builder.hpp | 1 - .../stdlib_circuit_builders/ultra_flavor.hpp | 1 - .../stdlib_circuit_builders/ultra_keccak.hpp | 1 - .../ultra_recursive_flavor.hpp | 1 - .../src/barretenberg/vm/avm/generated/flavor.hpp | 1 - .../src/barretenberg/vm/avm/generated/prover.cpp | 1 - .../src/barretenberg/vm/avm/generated/verifier.cpp | 1 - bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs | 3 +-- bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs | 1 - bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs | 1 - 38 files changed, 18 insertions(+), 50 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp index f8563de10a0..00da0386848 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp @@ -24,6 +24,7 @@ #include "barretenberg/common/op_count.hpp" #include "barretenberg/common/thread.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/srs/global_crs.hpp" #include @@ -452,7 +453,7 @@ void pippenger(State& state) for (auto _ : state) { state.PauseTiming(); size_t num_cycles = 1 << static_cast(state.range(0)); - LegacyPolynomial pol(num_cycles); + Polynomial pol(num_cycles); for (size_t i = 0; i < num_cycles; i++) { *(uint256_t*)&pol[i] = engine.get_random_uint256(); pol[i].self_reduce_once(); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp index f2474384111..61f32b8d6d1 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/claim.hpp @@ -59,7 +59,7 @@ template class OpeningClaim { * @param polynomial the claimed witness polynomial p(X) * @return C = Commit(p(X)) && p(r) = v */ - bool verify(std::shared_ptr ck, const bb::LegacyPolynomial& polynomial) const + bool verify(std::shared_ptr ck, const bb::Polynomial& polynomial) const { Fr real_eval = polynomial.evaluate(opening_pair.challenge); if (real_eval != opening_pair.evaluation) { diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp index 31e30998ead..f0b20c0a03c 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp @@ -1,5 +1,6 @@ #include "barretenberg/commitment_schemes/commitment_key.hpp" +#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/srs/factories/mem_bn254_crs_factory.hpp" #include @@ -13,10 +14,10 @@ template std::shared_ptr> create_commitmen } // Generate a polynomial with a specified number of nonzero random coefficients -template LegacyPolynomial sparse_random_poly(const size_t size, const size_t num_nonzero) +template Polynomial sparse_random_poly(const size_t size, const size_t num_nonzero) { auto& engine = numeric::get_debug_randomness(); - auto polynomial = LegacyPolynomial(size); + auto polynomial = Polynomial(size); for (size_t i = 0; i < num_nonzero; i++) { size_t idx = engine.get_random_uint32() % size; @@ -37,7 +38,7 @@ template void bench_commit_zero(::benchmark::State& state) auto key = create_commitment_key(MAX_NUM_POINTS); const size_t num_points = 1 << state.range(0); - const auto polynomial = LegacyPolynomial(num_points); + const auto polynomial = Polynomial(num_points); for (auto _ : state) { key->commit(polynomial); } @@ -52,7 +53,7 @@ template void bench_commit_sparse(::benchmark::State& state) const size_t num_points = 1 << state.range(0); const size_t num_nonzero = SPARSE_NUM_NONZERO; - auto polynomial = LegacyPolynomial(num_points); + auto polynomial = Polynomial(num_points); for (size_t i = 0; i < num_nonzero; i++) { polynomial[i] = 1; } @@ -71,7 +72,7 @@ template void bench_commit_sparse_preprocessed(::benchmark::Sta const size_t num_points = 1 << state.range(0); const size_t num_nonzero = SPARSE_NUM_NONZERO; - auto polynomial = LegacyPolynomial(num_points); + auto polynomial = Polynomial(num_points); for (size_t i = 0; i < num_nonzero; i++) { polynomial[i] = 1; } @@ -120,7 +121,7 @@ template void bench_commit_random(::benchmark::State& state) auto key = create_commitment_key(MAX_NUM_POINTS); const size_t num_points = 1 << state.range(0); - auto polynomial = LegacyPolynomial(num_points); + auto polynomial = Polynomial(num_points); for (auto& coeff : polynomial) { coeff = Fr::random_element(); } diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index 16925a4ea1b..ab67227424b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -10,7 +10,6 @@ #include "barretenberg/common/op_count.hpp" #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" #include "barretenberg/numeric/bitop/pow.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp index 209a202b3d5..00d7c39343b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp @@ -3,7 +3,6 @@ #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include "claim.hpp" diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp index 65af51fea62..b8893ed4300 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp @@ -3,7 +3,6 @@ #include "./mock_transcript.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" namespace bb { @@ -36,6 +35,8 @@ class ProxyCaller { }; } // namespace bb +using namespace bb; + /** * @brief Initialize SRS, commitment key, verification key * diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp index 9bf59cd76d4..97c701075cc 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp @@ -6,7 +6,6 @@ #include "barretenberg/common/mem.hpp" #include "barretenberg/ecc/curves/bn254/fq12.hpp" #include "barretenberg/ecc/curves/types.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp index eda38cb2582..0a1a873412c 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.hpp @@ -3,7 +3,6 @@ #include "../claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp index 4f272c1d430..42cf6b9f8fb 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -5,7 +5,6 @@ #include "../commitment_key.test.hpp" #include "barretenberg/commitment_schemes/claim.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp index 606f2e3cc6b..73e726ed34c 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp @@ -9,7 +9,6 @@ #include "../commitment_key.test.hpp" #include "barretenberg/commitment_schemes/claim.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb { template class ShplonkTest : public CommitmentTest {}; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp index fd455e1f0f8..953e66b7534 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp @@ -11,7 +11,6 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" #include "barretenberg/numeric/bitop/pow.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "barretenberg/srs/global_crs.hpp" diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp index 04c49f70e5b..d77bb7433c5 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp @@ -8,7 +8,6 @@ #include "barretenberg/eccvm/eccvm_verifier.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/sumcheck_round.hpp" diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp index d008388a869..2bfc2b565ed 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp @@ -6,7 +6,6 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 5b77595bca0..da3681c37ad 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -1,4 +1,3 @@ -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp index 17e5061a187..5ef1cc1bbbd 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -1,7 +1,6 @@ #pragma once #include "barretenberg/common/ref_vector.hpp" #include "barretenberg/common/zip_view.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index a1dfb085f54..7b0de5d5677 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/common/zip_view.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" namespace bb { /** diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp index 1592149cc6e..8ae6aad831c 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp @@ -13,7 +13,6 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" #include "barretenberg/polynomials/iterate_over_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp index b20e53e0bd5..fd988bfd042 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp @@ -3,7 +3,6 @@ #include "barretenberg/common/thread.hpp" #include "barretenberg/common/zip_view.hpp" #include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp index 3952c8cb1b6..cc4843e81de 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp @@ -1,15 +1,13 @@ #include #include -#include "barretenberg/polynomials/legacy_polynomial.hpp" - -using namespace bb; +#include "barretenberg/polynomials/polynomial.hpp" // Simple test/demonstration of shifted functionality TEST(Polynomial, Shifted) { using FF = bb::fr; - using Polynomial = LegacyPolynomial; + using Polynomial = bb::Polynomial; const size_t SIZE = 10; auto poly = Polynomial::random(SIZE); poly[0] = 0; // make it shiftable @@ -21,13 +19,13 @@ TEST(Polynomial, Shifted) // The shift is indeed the shift for (size_t i = 0; i < poly_shifted.size(); ++i) { - EXPECT_EQ(poly_shifted.at(i), poly.at(i + 1)); + EXPECT_EQ(poly_shifted.get(i), poly.get(i + 1)); } // If I change the original polynomial, the shift is updated accordingly poly[3] = 25; for (size_t i = 0; i < poly_shifted.size(); ++i) { - EXPECT_EQ(poly_shifted.at(i), poly.at(i + 1)); + EXPECT_EQ(poly_shifted.get(i), poly.get(i + 1)); } } @@ -35,7 +33,7 @@ TEST(Polynomial, Shifted) TEST(Polynomial, Share) { using FF = bb::fr; - using Polynomial = LegacyPolynomial; + using Polynomial = bb::Polynomial; const size_t SIZE = 10; auto poly = Polynomial::random(SIZE); diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index a7faed2e5b7..519f1031b0a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -3,7 +3,6 @@ #include #include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp index 472496af59b..2ef8c62257f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp @@ -3,7 +3,6 @@ #include #include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp index 327ba70b399..f0c742e24b8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp @@ -3,7 +3,6 @@ #include #include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp index 138c6a49ace..320216495bc 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_lookup/generic_lookup_relation.hpp @@ -20,7 +20,6 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp index b0696f51ed5..9c51976afd0 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp @@ -11,7 +11,6 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 1fa67ab41dc..fe66475aded 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -4,7 +4,6 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp index 99f3face100..91eebe93ddb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp @@ -1,6 +1,5 @@ #include "protogalaxy_recursive_verifier.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/stdlib/honk_recursion/verifier/recursive_instances.hpp" namespace bb::stdlib::recursion::honk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp index dd124e442ab..845a1ea28f6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp @@ -1,7 +1,6 @@ #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp index 0d306d9eb38..2378d7580be 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp @@ -6,7 +6,6 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/stdlib/honk_recursion/transcript/transcript.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 28edc512dfb..931245f7876 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -5,7 +5,6 @@ #include "barretenberg/plonk_honk_shared/types/circuit_type.hpp" #include "barretenberg/plonk_honk_shared/types/merkle_hash_type.hpp" #include "barretenberg/plonk_honk_shared/types/pedersen_commitment_type.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/stdlib_circuit_builders/op_queue/ecc_op_queue.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index ce600c78a31..bbd163e574a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -7,7 +7,6 @@ #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index d01cf49b053..7f28be204a2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -8,7 +8,6 @@ #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index e0b9eb87c1f..c1ef2c14190 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -6,7 +6,6 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index 4ff05d43aa5..4ab4e1ecf90 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -10,7 +10,6 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include "barretenberg/vm/avm/generated/flavor_settings.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp index 12a85a6448a..41e801b4c83 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp @@ -8,7 +8,6 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp index 461e426be04..40137e3d457 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp @@ -5,7 +5,6 @@ #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs index 91a5ae9ccde..8318a084de8 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs @@ -10,7 +10,6 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/transcript/transcript.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/vm/{{snakeCase name}}/generated/flavor_settings.hpp" @@ -59,7 +58,7 @@ class {{name}}Flavor { // This flavor would not be used with ZK Sumcheck static constexpr bool HasZK = false; - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = {{len fixed}}; + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = {{len fixed}}; static constexpr size_t NUM_WITNESS_ENTITIES = {{len witness}}; static constexpr size_t NUM_SHIFTED_ENTITIES = {{len shifted}}; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; diff --git a/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs index 07345186acb..c70f7c36639 100644 --- a/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs @@ -8,7 +8,6 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs index 9ba1b94a98d..57910fa1adb 100644 --- a/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/verifier.cpp.hbs @@ -5,7 +5,6 @@ #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/polynomials/legacy_polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { From 652baf4bbe0b12e868450ef7ccb8116ea5cc59e2 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Aug 2024 00:24:56 +0000 Subject: [PATCH 14/15] nuke ffts --- .../composer/composer_lib.hpp | 1 - .../barretenberg/polynomials/polynomial.cpp | 108 ------------------ .../barretenberg/polynomials/polynomial.hpp | 24 ---- .../stdlib_circuit_builders/ultra_flavor.hpp | 1 - 4 files changed, 134 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 70e35729e01..f128666635b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -8,7 +8,6 @@ namespace bb { -// TODO temporary fork WORKTODO(sparse) template void construct_lookup_table_polynomials(const RefArray& table_polynomials, const typename Flavor::CircuitBuilder& circuit, diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp index 5a016ce2a32..8280d141a66 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp @@ -259,104 +259,6 @@ template Polynomial Polynomial::partial_evaluate_mle(std:: return result; } -/** - * FFTs - **/ - -template -void Polynomial::fft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::fft(data(), domain); -} - -template -void Polynomial::partial_fft(const EvaluationDomain& domain, Fr constant, bool is_coset) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::partial_fft(data(), domain, constant, is_coset); -} - -template -void Polynomial::coset_fft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::coset_fft(data(), domain); -} - -template -void Polynomial::coset_fft(const EvaluationDomain& domain, - const EvaluationDomain& large_domain, - const size_t domain_extension) - requires polynomial_arithmetic::SupportsFFT -{ - size_t extended_size = domain.size * domain_extension; - - ASSERT(in_place_operation_viable(extended_size)); - zero_memory_beyond(extended_size); - - polynomial_arithmetic::coset_fft(data(), domain, large_domain, domain_extension); -} - -template -void Polynomial::coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::coset_fft_with_constant(data(), domain, constant); -} - -template -void Polynomial::coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::coset_fft_with_generator_shift(data(), domain, constant); -} - -template -void Polynomial::ifft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::ifft(data(), domain); -} - -template -void Polynomial::ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::ifft_with_constant(data(), domain, constant); -} - -template -void Polynomial::coset_ifft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT -{ - ASSERT(in_place_operation_viable(domain.size)); - zero_memory_beyond(domain.size); - - polynomial_arithmetic::coset_ifft(data(), domain); -} - template Fr Polynomial::compute_kate_opening_coefficients(const Fr& z) requires polynomial_arithmetic::SupportsFFT @@ -371,16 +273,6 @@ Fr Polynomial::compute_barycentric_evaluation(const Fr& z, const EvaluationD return polynomial_arithmetic::compute_barycentric_evaluation(data(), domain.size, z, domain); } -template -Fr Polynomial::evaluate_from_fft(const EvaluationDomain& large_domain, - const Fr& z, - const EvaluationDomain& small_domain) - requires polynomial_arithmetic::SupportsFFT - -{ - return polynomial_arithmetic::evaluate_from_fft(data(), large_domain, z, small_domain); -} - template Polynomial& Polynomial::operator-=(std::span other) { const size_t other_size = other.size(); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index 30dc44df7a0..7840699dc65 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -141,30 +141,6 @@ template class Polynomial { Fr compute_barycentric_evaluation(const Fr& z, const EvaluationDomain& domain) requires polynomial_arithmetic::SupportsFFT; - Fr evaluate_from_fft(const EvaluationDomain& large_domain, - const Fr& z, - const EvaluationDomain& small_domain) - requires polynomial_arithmetic::SupportsFFT; - void fft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT; - void partial_fft(const EvaluationDomain& domain, Fr constant = 1, bool is_coset = false) - requires polynomial_arithmetic::SupportsFFT; - void coset_fft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT; - void coset_fft(const EvaluationDomain& domain, - const EvaluationDomain& large_domain, - size_t domain_extension) - requires polynomial_arithmetic::SupportsFFT; - void coset_fft_with_constant(const EvaluationDomain& domain, const Fr& constant) - requires polynomial_arithmetic::SupportsFFT; - void coset_fft_with_generator_shift(const EvaluationDomain& domain, const Fr& constant) - requires polynomial_arithmetic::SupportsFFT; - void ifft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT; - void ifft_with_constant(const EvaluationDomain& domain, const Fr& constant) - requires polynomial_arithmetic::SupportsFFT; - void coset_ifft(const EvaluationDomain& domain) - requires polynomial_arithmetic::SupportsFFT; Fr compute_kate_opening_coefficients(const Fr& z) requires polynomial_arithmetic::SupportsFFT; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index bbd163e574a..710f2d7624c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -278,7 +278,6 @@ class UltraFlavor { // shifted polys ZoneScopedN("creating empty prover polys"); for (auto& poly : get_unshifted()) { - // WORKTODO(sparse): proper lower bound on size poly = Polynomial{ circuit_size }; } set_shifted(); From a9866bdaf369e5b827f9624994a44d72023d1047 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Aug 2024 00:26:22 +0000 Subject: [PATCH 15/15] remove commented code --- .../barretenberg/plonk_honk_shared/composer/composer_lib.hpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index f128666635b..543f282fb05 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -53,11 +53,6 @@ void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, { // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace size_t offset = dyadic_circuit_size - circuit.get_tables_size(); - // read_counts = - // typename Flavor::Polynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); - // read_tags = - // typename Flavor::Polynomial(circuit.get_tables_size(), dyadic_circuit_size, /*start index*/ offset); - // WORKTODO(sparse) circuit.get_tables_size() is the actual size of our structured polynomial; size_t table_offset = offset; // offset of the present table in the table polynomials // loop over all tables used in the circuit; each table contains data about the lookups made on it