Skip to content

Commit

Permalink
disable fft for polynomial functions instantiated with grumpkin and i…
Browse files Browse the repository at this point in the history
…mprove testing
  • Loading branch information
maramihali committed Aug 10, 2023
1 parent 8e722c3 commit 28e5000
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 317 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "verifier.hpp"
#include "../../../transcript/transcript.hpp"
#include "../prover/prover.hpp"
#include "../utils/permutation.hpp"
Expand All @@ -9,7 +10,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,10 +8,9 @@
#include <cstddef>
#include <fstream>
#include <span>

namespace barretenberg {

template <typename Fr> class Polynomial {

public:
/**
* Implements requirements of `std::ranges::contiguous_range` and `std::ranges::sized_range`
Expand Down Expand Up @@ -107,27 +106,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 +259,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 28e5000

Please sign in to comment.