Skip to content

Commit

Permalink
chore: disable fft functions for polynomials instantiated on Grumpkin (
Browse files Browse the repository at this point in the history
…#1471)

 Disables FFT related methods when the `Polynomial` class and methods in
`polynomial_arithmetic` are instantiated with Grumpkin. Improve testing by checking all the
functionality not related to FFT on both curves (Grumpkin doesn't have
many roots of unity and we can't do FFTs on it)
  • Loading branch information
maramihali authored Aug 10, 2023
1 parent 8e722c3 commit f09909a
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Bn254FqParams {
0x180a96573d3d9f8ULL, 0xf8b21270ddbb927ULL, 0x1d9598e8a7e39857ULL, 0x2ba010aa41eb7786ULL,
};
static constexpr char schema_name[] = "fq";
static constexpr bool has_high_2adicity = false;
};

typedef field<Bn254FqParams> fq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Bn254FrParams {
0x1d9598e8a7e39857ULL, 0x2ba010aa41eb7786ULL, 0x39aa886bdbf356b5ULL, 0x47b5002d75fb35e5ULL,
};
static constexpr char schema_name[] = "fr";
static constexpr bool has_high_2adicity = true;
};

typedef field<Bn254FrParams> fr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#endif

namespace barretenberg {
template <class Params> struct alignas(32) field {
template <class Params_> struct alignas(32) field {
public:
using Params = Params_;
typedef uint8_t const* in_buf;
typedef uint8_t const* vec_in_buf;
typedef uint8_t* out_buf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
#include "barretenberg/polynomials/polynomial_arithmetic.hpp"
#include "barretenberg/srs/factories/file_crs_factory.hpp"
#include "verifier.hpp"
#include <gtest/gtest.h>

namespace verifier_helpers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <utility>

namespace barretenberg {

/**
* Constructors / Destructors
**/
Expand Down Expand Up @@ -150,23 +149,29 @@ template <typename Fr> void Polynomial<Fr>::zero_memory_beyond(const size_t star
* FFTs
**/

template <typename Fr> void Polynomial<Fr>::fft(const EvaluationDomain<Fr>& domain)
template <typename Fr>
void Polynomial<Fr>::fft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);

polynomial_arithmetic::fft(coefficients_.get(), domain);
}

template <typename Fr> void Polynomial<Fr>::partial_fft(const EvaluationDomain<Fr>& domain, Fr constant, bool is_coset)
template <typename Fr>
void Polynomial<Fr>::partial_fft(const EvaluationDomain<Fr>& domain, Fr constant, bool is_coset)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);

polynomial_arithmetic::partial_fft(coefficients_.get(), domain, constant, is_coset);
}

template <typename Fr> void Polynomial<Fr>::coset_fft(const EvaluationDomain<Fr>& domain)
template <typename Fr>
void Polynomial<Fr>::coset_fft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);
Expand All @@ -178,6 +183,7 @@ template <typename Fr>
void Polynomial<Fr>::coset_fft(const EvaluationDomain<Fr>& domain,
const EvaluationDomain<Fr>& large_domain,
const size_t domain_extension)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
size_t extended_size = domain.size * domain_extension;

Expand All @@ -189,6 +195,7 @@ void Polynomial<Fr>::coset_fft(const EvaluationDomain<Fr>& domain,

template <typename Fr>
void Polynomial<Fr>::coset_fft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& constant)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);
Expand All @@ -198,44 +205,54 @@ void Polynomial<Fr>::coset_fft_with_constant(const EvaluationDomain<Fr>& domain,

template <typename Fr>
void Polynomial<Fr>::coset_fft_with_generator_shift(const EvaluationDomain<Fr>& domain, const Fr& constant)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);

polynomial_arithmetic::coset_fft_with_generator_shift(coefficients_.get(), domain, constant);
}

template <typename Fr> void Polynomial<Fr>::ifft(const EvaluationDomain<Fr>& domain)
template <typename Fr>
void Polynomial<Fr>::ifft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);

polynomial_arithmetic::ifft(coefficients_.get(), domain);
}

template <typename Fr> void Polynomial<Fr>::ifft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& constant)
template <typename Fr>
void Polynomial<Fr>::ifft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& constant)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);

polynomial_arithmetic::ifft_with_constant(coefficients_.get(), domain, constant);
}

template <typename Fr> void Polynomial<Fr>::coset_ifft(const EvaluationDomain<Fr>& domain)
template <typename Fr>
void Polynomial<Fr>::coset_ifft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
ASSERT(in_place_operation_viable(domain.size));
zero_memory_beyond(domain.size);

polynomial_arithmetic::coset_ifft(coefficients_.get(), domain);
}

template <typename Fr> Fr Polynomial<Fr>::compute_kate_opening_coefficients(const Fr& z)
template <typename Fr>
Fr Polynomial<Fr>::compute_kate_opening_coefficients(const Fr& z)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
return polynomial_arithmetic::compute_kate_opening_coefficients(coefficients_.get(), coefficients_.get(), z, size_);
}

template <typename Fr>
Fr Polynomial<Fr>::compute_barycentric_evaluation(const Fr& z, const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>
{
return polynomial_arithmetic::compute_barycentric_evaluation(coefficients_.get(), domain.size, z, domain);
}
Expand All @@ -244,6 +261,8 @@ template <typename Fr>
Fr Polynomial<Fr>::evaluate_from_fft(const EvaluationDomain<Fr>& large_domain,
const Fr& z,
const EvaluationDomain<Fr>& small_domain)
requires polynomial_arithmetic::SupportsFFT<Fr>

{
return polynomial_arithmetic::evaluate_from_fft(coefficients_.get(), large_domain, z, small_domain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include <cstddef>
#include <fstream>
#include <span>

namespace barretenberg {

template <typename Fr> class Polynomial {
public:
/**
Expand Down Expand Up @@ -107,27 +105,35 @@ template <typename Fr> class Polynomial {

Fr evaluate(const Fr& z, const size_t target_size) const;
Fr evaluate(const Fr& z) const;
Fr compute_barycentric_evaluation(const Fr& z, const EvaluationDomain<Fr>& domain);

Fr compute_barycentric_evaluation(const Fr& z, const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>;
Fr evaluate_from_fft(const EvaluationDomain<Fr>& large_domain,
const Fr& z,
const EvaluationDomain<Fr>& small_domain);

void fft(const EvaluationDomain<Fr>& domain);
void partial_fft(const EvaluationDomain<Fr>& domain, Fr constant = 1, bool is_coset = false);
void coset_fft(const EvaluationDomain<Fr>& domain);
const EvaluationDomain<Fr>& small_domain)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void fft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void partial_fft(const EvaluationDomain<Fr>& domain, Fr constant = 1, bool is_coset = false)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void coset_fft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void coset_fft(const EvaluationDomain<Fr>& domain,
const EvaluationDomain<Fr>& large_domain,
const size_t domain_extension);

void coset_fft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& costant);
void coset_fft_with_generator_shift(const EvaluationDomain<Fr>& domain, const Fr& constant);

void ifft(const EvaluationDomain<Fr>& domain);
void ifft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& constant);
void coset_ifft(const EvaluationDomain<Fr>& domain);

Fr compute_kate_opening_coefficients(const Fr& z);
const size_t domain_extension)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void coset_fft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& costant)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void coset_fft_with_generator_shift(const EvaluationDomain<Fr>& domain, const Fr& constant)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void ifft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void ifft_with_constant(const EvaluationDomain<Fr>& domain, const Fr& constant)
requires polynomial_arithmetic::SupportsFFT<Fr>;
void coset_ifft(const EvaluationDomain<Fr>& domain)
requires polynomial_arithmetic::SupportsFFT<Fr>;
Fr compute_kate_opening_coefficients(const Fr& z)
requires polynomial_arithmetic::SupportsFFT<Fr>;

bool is_empty() const { return (coefficients_ == nullptr) || (size_ == 0); }

Expand Down Expand Up @@ -252,6 +258,7 @@ template <typename Fr> inline std::ostream& operator<<(std::ostream& os, Polynom
<< "]";
}

// Done
// N.B. grumpkin polynomials don't support fast fourier transforms using roots of unity!
// TODO: use template junk to disable fft methods if Fr::SUPPORTS_FFTS == false
// extern template class Polynomial<grumpkin::fr>;
Expand Down
Loading

0 comments on commit f09909a

Please sign in to comment.