Skip to content

Commit

Permalink
chore: clean up Plonk widgets (#3305)
Browse files Browse the repository at this point in the history
The "linearization trick" in Plonk required the splitting of the widget
(relation) contributions into "linear" an "nonlinear" parts. The trick
is no longer in use and there's no need for this structure to remain.
This work

1. Cleans up and consolidates the quotient contribution logic in the
widgets into a single `accumulate_contribution` method which more
closely resembles the structure of the Honk relations.
2. Deletes entirely the fixed base and logic widgets which were no
longer being used at all.

This is good cleanup regardless but was done with an eye towards
eventually utilizing the relations in Plonk. Below are the UltraPlonk
Bench results. I didn't expect anything to change but they seem a bit
noisy. After deleting the logic widget, case log_n = 17 seems to
consistently show a minor increase but 18 does not. Not sure what to
make of this.

<img width="1206" alt="bench_new"
src="https://github.com/AztecProtocol/aztec-packages/assets/98505400/7290f15a-4e07-4f1e-9f67-0c987406294c">
  • Loading branch information
ledwards2225 authored Nov 14, 2023
1 parent 13f1a1d commit 4623d91
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 733 deletions.
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 @@ -23,7 +23,6 @@ enum PolynomialIndex {
Q_FIXED_BASE,
Q_RANGE,
Q_SORT,
Q_LOGIC,
TABLE_1,
TABLE_2,
TABLE_3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#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"
#include "../widgets/transition_widgets/plookup_auxiliary_widget.hpp"
#include "./prover_settings.hpp"
Expand Down Expand Up @@ -64,7 +62,6 @@ class ultra_verifier_settings : public ultra_settings {
typedef transcript::StandardTranscript Transcript;
typedef VerifierPlookupArithmeticWidget<fr, g1::affine_element, Transcript, ultra_settings> PlookupArithmeticWidget;
typedef VerifierGenPermSortWidget<fr, g1::affine_element, Transcript, ultra_settings> GenPermSortWidget;
typedef VerifierLogicWidget<fr, g1::affine_element, Transcript, ultra_settings> LogicWidget;
typedef VerifierPermutationWidget<fr, g1::affine_element, Transcript> PermutationWidget;
typedef VerifierPlookupWidget<fr, g1::affine_element, Transcript> PlookupWidget;
typedef VerifierEllipticWidget<fr, g1::affine_element, Transcript, ultra_settings> EllipticWidget;
Expand Down Expand Up @@ -120,7 +117,6 @@ class ultra_to_standard_verifier_settings : public ultra_verifier_settings {
typedef VerifierPlookupArithmeticWidget<fr, g1::affine_element, Transcript, ultra_to_standard_settings>
PlookupArithmeticWidget;
typedef VerifierGenPermSortWidget<fr, g1::affine_element, Transcript, ultra_to_standard_settings> GenPermSortWidget;
typedef VerifierLogicWidget<fr, g1::affine_element, Transcript, ultra_to_standard_settings> LogicWidget;
typedef VerifierPermutationWidget<fr, g1::affine_element, Transcript> PermutationWidget;
typedef VerifierPlookupWidget<fr, g1::affine_element, Transcript> PlookupWidget;
typedef VerifierEllipticWidget<fr, g1::affine_element, Transcript, ultra_to_standard_settings> EllipticWidget;
Expand All @@ -136,7 +132,6 @@ class ultra_with_keccak_verifier_settings : public ultra_verifier_settings {
typedef VerifierPlookupArithmeticWidget<fr, g1::affine_element, Transcript, ultra_with_keccak_settings>
PlookupArithmeticWidget;
typedef VerifierGenPermSortWidget<fr, g1::affine_element, Transcript, ultra_with_keccak_settings> GenPermSortWidget;
typedef VerifierLogicWidget<fr, g1::affine_element, Transcript, ultra_with_keccak_settings> LogicWidget;
typedef VerifierPermutationWidget<fr, g1::affine_element, Transcript> PermutationWidget;
typedef VerifierPlookupWidget<fr, g1::affine_element, Transcript> PlookupWidget;
typedef VerifierEllipticWidget<fr, g1::affine_element, Transcript, ultra_with_keccak_settings> EllipticWidget;
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,
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

0 comments on commit 4623d91

Please sign in to comment.