Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up Plonk widgets #3305

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ void plookup_auxiliary_kernel(::benchmark::State& state) noexcept
for (auto _ : state) {
// NOTE: this simply calls the following 3 functions it does NOT try to replicate ProverPlookupAuxiliaryWidget
// logic exactly
widget::containers::coefficient_array<barretenberg::fr> linear_terms;
FFTKernel::compute_linear_terms(polynomials, challenges, linear_terms, 0);
barretenberg::fr sum_of_linear_terms = FFTKernel::sum_linear_terms(polynomials, challenges, linear_terms, 0);
FFTKernel::compute_non_linear_terms(polynomials, challenges, sum_of_linear_terms, 0);
barretenberg::fr result{ 0 };
FFTKernel::accumulate_contribution(polynomials, challenges, result, 0);
}
}
BENCHMARK(plookup_auxiliary_kernel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "../widgets/random_widgets/random_widget.hpp"
#include "../widgets/transition_widgets/arithmetic_widget.hpp"
#include "../widgets/transition_widgets/elliptic_widget.hpp"
#include "../widgets/transition_widgets/fixed_base_widget.hpp"
#include "../widgets/transition_widgets/genperm_sort_widget.hpp"
#include "../widgets/transition_widgets/logic_widget.hpp"
#include "../widgets/transition_widgets/plookup_arithmetic_widget.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ template <class Field, class Getters, typename PolyContainer> class ArithmeticKe
private:
// A structure with various challenges, even though only alpha is used here.
typedef containers::challenge_array<Field, num_independent_relations> challenge_array;
// Type for the linear terms of the transition
typedef containers::coefficient_array<Field> coefficient_array;

public:
inline static std::set<PolynomialIndex> const& get_required_polynomial_ids()
Expand All @@ -51,10 +49,10 @@ template <class Field, class Getters, typename PolyContainer> class ArithmeticKe
* @param linear_terms Container for results of computation
* @param i Index at which the wire values are sampled.
*/
inline static void compute_linear_terms(PolyContainer& polynomials,
const challenge_array&,
coefficient_array& linear_terms,
const size_t i = 0)
inline static void accumulate_contribution(PolyContainer& polynomials,
const challenge_array& challenges,
Field& quotient,
const size_t i = 0)
{
const Field& w_1 =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_1>(polynomials, i);
Expand All @@ -63,34 +61,6 @@ template <class Field, class Getters, typename PolyContainer> class ArithmeticKe
const Field& w_3 =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_3>(polynomials, i);

linear_terms[0] = w_1 * w_2;
linear_terms[1] = w_1;
linear_terms[2] = w_2;
linear_terms[3] = w_3;
}

/**
* @brief Not being used in arithmetic_widget because there are none
*
*/
inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {}

/**
* @brief Scale and sum the linear terms for the final equation.
*
* @details Multiplies the linear terms by selector values and scale the whole sum by alpha before returning
*
* @param polynomials Container with polynomials or their simulation
* @param challenges A structure with various challenges
* @param linear_terms Precomuputed linear terms to be scaled and summed
* @param i The index at which selector/witness values are sampled
* @return Field Scaled sum of values
*/
inline static Field sum_linear_terms(PolyContainer& polynomials,
const challenge_array& challenges,
coefficient_array& linear_terms,
const size_t i = 0)
{
const Field& alpha = challenges.alpha_powers[0];
const Field& q_1 =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_1>(polynomials, i);
Expand All @@ -103,32 +73,13 @@ template <class Field, class Getters, typename PolyContainer> class ArithmeticKe
const Field& q_c =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_C>(polynomials, i);

Field result = linear_terms[0] * q_m;
result += (linear_terms[1] * q_1);
result += (linear_terms[2] * q_2);
result += (linear_terms[3] * q_3);
Field result = (w_1 * w_2) * q_m;
result += w_1 * q_1;
result += w_2 * q_2;
result += w_3 * q_3;
result += q_c;
result *= alpha;
return result;
}

/**
* @brief Compute the scaled values of openings
*
* @param linear_terms The original computed linear terms of the product and wires
* @param scalars A map where we put the values
* @param challenges Challenges where we get the alpha
*/
inline static void update_kate_opening_scalars(coefficient_array& linear_terms,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function (implemented in each widget) was part of the linearization trick and was no longer used at all.

std::map<std::string, Field>& scalars,
const challenge_array& challenges)
{
const Field& alpha = challenges.alpha_powers[0];
scalars["Q_M"] += linear_terms[0] * alpha;
scalars["Q_1"] += linear_terms[1] * alpha;
scalars["Q_2"] += linear_terms[2] * alpha;
scalars["Q_3"] += linear_terms[3] * alpha;
scalars["Q_C"] += alpha;
quotient += result;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ template <class Field, class Getters, typename PolyContainer> class EllipticKern

private:
typedef containers::challenge_array<Field, num_independent_relations> challenge_array;
typedef containers::coefficient_array<Field> coefficient_array;

public:
inline static std::set<PolynomialIndex> const& get_required_polynomial_ids()
Expand All @@ -93,10 +92,10 @@ template <class Field, class Getters, typename PolyContainer> class EllipticKern
* @param linear_terms Output array
* @param i Gate index
*/
inline static void compute_linear_terms(PolyContainer& polynomials,
const challenge_array& challenges,
coefficient_array& linear_terms,
const size_t i = 0)
inline static void accumulate_contribution(PolyContainer& polynomials,
const challenge_array& challenges,
Field& quotient,
const size_t i = 0)
{
const Field& x_1 =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_2>(polynomials, i);
Expand All @@ -106,6 +105,8 @@ template <class Field, class Getters, typename PolyContainer> class EllipticKern
const Field& y_2 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_4>(polynomials, i);
const Field& x_3 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_2>(polynomials, i);
const Field& y_3 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_3>(polynomials, i);
const Field& q_elliptic =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_ELLIPTIC>(polynomials, i);

// sign
const Field& q_sign =
Expand Down Expand Up @@ -139,41 +140,9 @@ template <class Field, class Getters, typename PolyContainer> class EllipticKern
(q_is_double * (x_identity_double - x_identity_add) + x_identity_add) * challenges.alpha_powers[0];
auto y_identity =
(q_is_double * (y_identity_double - y_identity_add) + y_identity_add) * challenges.alpha_powers[1];
linear_terms[0] = x_identity + y_identity;
}
Field identity = x_identity + y_identity;

/**
* @brief Return the linear term multiplied by elliptic curve addition selector value at gate
*
* @param polynomials Polynomial container or simulator
* @param linear_terms Array of linear terms
* @param i Gate index
* @return Field
*/
inline static Field sum_linear_terms(PolyContainer& polynomials,
const challenge_array&,
coefficient_array& linear_terms,
const size_t i = 0)
{
const Field& q_elliptic =
Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_ELLIPTIC>(polynomials, i);

return linear_terms[0] * q_elliptic;
}

inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {}

/**
* @brief Update opening scalars with the linear term from elliptic gate
*
* @param linear_terms Contains input scalar
* @param scalars Output map for updates
*/
inline static void update_kate_opening_scalars(coefficient_array& linear_terms,
std::map<std::string, Field>& scalars,
const challenge_array&)
{
scalars["Q_ELLIPTIC"] += linear_terms[0];
quotient += identity * q_elliptic;
}
};

Expand Down
Loading