From c33e5d493286c2a9b3549bc28a28914de815c7f8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 13 Nov 2023 18:11:49 +0000 Subject: [PATCH 1/6] delete fixed base widget --- .../proof_system/types/program_settings.hpp | 1 - .../transition_widgets/fixed_base_widget.hpp | 295 ------------------ 2 files changed, 296 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/fixed_base_widget.hpp diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp index 2b5d6b899bf..a9d20a7474f 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp @@ -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" diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/fixed_base_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/fixed_base_widget.hpp deleted file mode 100644 index a9071279bfa..00000000000 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/fixed_base_widget.hpp +++ /dev/null @@ -1,295 +0,0 @@ -#pragma once - -#include "./transition_widget.hpp" - -namespace proof_system::plonk { -namespace widget { - -/** - * This gate computes 2-bit NAF elliptic curve addition (aka fixed-based scalar multiplication). - * The theory is explained in detail in [1]. Suppose the (n+1) gates are strutured as following: - * - * +---------+---------+-----------+---------+ - * | w_1 | w_2 | w_3 | w_4 | - * |---------|---------|-----------|---------| - * | x_0 | y_0 | c | a_0 | - * | x_1 | y_1 | x_{α,0} | a_1 | - * | . | . | . | . | - * | . | . | . | . | - * | . | . | . | . | - * | x_i | y_i | x_{α,i-1} | a_i |<- i th gate - * | x_{i+1} | y_{i+1} | x_{α,i} | a_{i+1} | - * | . | . | . | . | - * | . | . | . | . | - * | . | . | . | . | - * | x_n | y_n | x_{α,n-1} | a_n | - * +---------+---------+-----------+---------+ - * - * Here, (x_{i+1}, y_{i+1}) = [(x_i, y_i)] + b_i.[(x_{α,i}, y_{α,i})] for i = {0, 1, ..., n-1}. - * Since the values (a_i) are intermediate sums, the actual quad value b_i is: - * b_i := a_{i+1} - 4 * a_i. - * - * In the implementation below, we call b_i as delta (δ). - * Let P_0 = 4^{n-1}.[g] and P_1 = (1 + 4^{n-1}).[g]. - * We need the following constraints: - * - * - * 0. Quad value is either of {-3, -1, 1, 3}. See page 6 of [1]. - * => (b_i + 3)(b_i + 1)(b_i - 1)(b_i - 3) = 0 - * - * 1. Check if x-coordinate of the point to be added is correct. See page 5 of [1]. - * => q_1 * b_i^2 + q_2 = x_{α,i} - * - * 2. Check if x-coordinate of new point is correct. See page 7 of [1]. - * => (x_{i+1} + x_i + x_{α,i}) * (x_{α,i} - x_i)^2 + - * (2.b_i.y_1) * (q_3.x_{α,i} + q_{ecc,1}) - - * (x_{α,i}^3 + y_i^2 + b_{grumpkin}) = 0 - * - * 3. Check if y-coordinate of new point is correct. See page 7 of [1]. - * => (y_{i+1} + y_i) * (x_{α,i} - x_i) - - * (b_i.(q_3.x_{α,i} + q_{ecc,1}) - y_i) * (x_i - x_{i+1}) = 0 - * - * 4. Initialization: a_0 must be either 1 or (1 + 4^{-n}). See page 7 of [1]. - * => q_c * (1 - a_0).(1 - a_0 - 4^{-n}) = 0 - * - * 5. Initialization: x_0 must be x-coordinate of either P_0 or P_1. - * => q_c * (c.(q_4 - x_0) + q_5.(1 - a_0)) = 0 - * - * 6. Initialization: y_0 must be y-coordinate of either P_0 or P_1. - * => q_c * (c.(q_m - y_0) + q_c.(1 - a_0)) = 0 - * - * - * We combine all of these constraints using powers of the challenge α. Further, the linear and non-linear parts in - * the constraines are computed separately in the functions `compute_linear_terms` and `compute_linear_terms` - * respectively. More details on how selector values for i=0 are specially chosen are explained in [3]. - * - * References: - * [1] The Turbo-PLONK program syntax for specifying SNARK programs, Ariel G and Zac W. - * Link: https://docs.zkproof.org/pages/standards/accepted-workshop3/proposal-turbo_plonk.pdf - * [2] Constant b_{grumpkin} = -17. - * [3] Fixed-base Multiplication gate, Cody G. - * Link: https://hackmd.io/MCmV2bipRYelT1WUNLj02g - * - **/ -template class FixedBaseKernel { - public: - // UltraPlonkComposer only needs 6 independent relations, (α^5 is not added), but we accept the tiny inefficiency - // of computing and storing an extra power of α (we use power 0,1,2,3,4 and 6) to minimize code changes. - static constexpr size_t num_independent_relations = 7; - // We state the challenges required for linear/nonlinear terms computation - static constexpr uint8_t quotient_required_challenges = CHALLENGE_BIT_ALPHA; - // We state the challenges required for updating kate opening scalars - static constexpr uint8_t update_required_challenges = CHALLENGE_BIT_ALPHA; - - private: - typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; - - public: - inline static std::set const& get_required_polynomial_ids() - { - static const std::set required_polynomial_ids = { - PolynomialIndex::Q_1, PolynomialIndex::Q_2, PolynomialIndex::Q_3, PolynomialIndex::Q_4, - PolynomialIndex::Q_5, PolynomialIndex::Q_M, PolynomialIndex::Q_C, PolynomialIndex::Q_FIXED_BASE, - PolynomialIndex::W_1, PolynomialIndex::W_2, PolynomialIndex::W_3, PolynomialIndex::W_4 - }; - return required_polynomial_ids; - } - - /** - * @brief Quickly checks if the result of all computation will be zero because of the selector or not - * - * @param polynomials Polynomial or simulated container - * @param i Gate index - * @return q_ecc_1[i] != 0 - */ - inline static bool gate_enabled(PolyContainer& polynomials, const size_t i = 0) - { - const Field& q_ecc_1 = - Getters::template get_value(polynomials, i); - return !q_ecc_1.is_zero(); - } - - inline static void compute_linear_terms(PolyContainer& polynomials, - const challenge_array& challenges, - coefficient_array& linear_terms, - const size_t i = 0) - { - - const Field& w_1 = - Getters::template get_value(polynomials, i); - const Field& w_2 = - Getters::template get_value(polynomials, i); - const Field& w_3 = - Getters::template get_value(polynomials, i); - const Field& w_4 = - Getters::template get_value(polynomials, i); - const Field& w_1_omega = - Getters::template get_value(polynomials, i); - const Field& w_3_omega = - Getters::template get_value(polynomials, i); - const Field& w_4_omega = - Getters::template get_value(polynomials, i); - const Field& q_c = - Getters::template get_value(polynomials, i); - const Field& q_fixed_base = - Getters::template get_value(polynomials, i); - - Field delta = w_4_omega - (w_4 + w_4 + w_4 + w_4); - - Field delta_squared = delta.sqr(); - - Field q_1_multiplicand = delta_squared * q_fixed_base * challenges.alpha_powers[1]; - - Field q_2_multiplicand = challenges.alpha_powers[1] * q_fixed_base; - - Field q_3_multiplicand = (w_1_omega - w_1) * delta * w_3_omega * challenges.alpha_powers[3] * q_fixed_base; - Field T1 = delta * w_3_omega * w_2 * challenges.alpha_powers[2]; - q_3_multiplicand = q_3_multiplicand + (T1 + T1) * q_fixed_base; - - Field q_4_multiplicand; - - Field q_5_multiplicand; - - Field q_m_multiplicand = w_3 * q_fixed_base * q_c * challenges.alpha_powers[6]; - - linear_terms[0] = q_m_multiplicand; // α^6 q_fixed_base q_c w_3 - linear_terms[1] = q_1_multiplicand; // α q_fixed_base δ^2 - linear_terms[2] = q_2_multiplicand; // α q_fixed_base - linear_terms[3] = q_3_multiplicand; // α^3 q_fixed_base δ * (w_1,ω - w_1) * w_3,ω - } - - inline static Field sum_linear_terms(PolyContainer& polynomials, - const challenge_array&, - coefficient_array& linear_terms, - const size_t i = 0) - { - const Field& q_1 = - Getters::template get_value(polynomials, i); - const Field& q_2 = - Getters::template get_value(polynomials, i); - const Field& q_3 = - Getters::template get_value(polynomials, i); - const Field& q_4 = - Getters::template get_value(polynomials, i); - const Field& q_m = - Getters::template get_value(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); - return result; - } - - inline static void compute_non_linear_terms(PolyContainer& polynomials, - const challenge_array& challenges, - Field& quotient, - const size_t i = 0) - { - constexpr barretenberg::fr grumpkin_curve_b(-17); - - const Field& w_1 = - Getters::template get_value(polynomials, i); - const Field& w_2 = - Getters::template get_value(polynomials, i); - const Field& w_3 = - Getters::template get_value(polynomials, i); - const Field& w_4 = - Getters::template get_value(polynomials, i); - const Field& w_1_omega = - Getters::template get_value(polynomials, i); - const Field& w_2_omega = - Getters::template get_value(polynomials, i); - const Field& w_3_omega = - Getters::template get_value(polynomials, i); - const Field& w_4_omega = - Getters::template get_value(polynomials, i); - const Field& q_c = - Getters::template get_value(polynomials, i); - const Field& q_fixed_base = - Getters::template get_value(polynomials, i); - - Field delta = w_4_omega - (w_4 + w_4 + w_4 + w_4); - const Field three = Field(3); - Field T1 = (delta + Field(1)); - Field T2 = (delta + three); - Field T3 = (delta - Field(1)); - Field T4 = (delta - three); - - // accumulator_identity = (δ + 3)(δ + 1)(δ - 1)(δ - 3) - Field accumulator_identity = T1 * T2 * T3 * T4 * challenges.alpha_powers[0]; - - // x_alpha_identity = -α w_3,ω - Field x_alpha_identity = -(w_3_omega * challenges.alpha_powers[1]); - - Field T0 = w_1_omega + w_1 + w_3_omega; - T1 = (w_3_omega - w_1).sqr(); - T0 = T0 * T1; - - T1 = w_3_omega.sqr() * w_3_omega; - T2 = w_2.sqr(); - T1 = T1 + T2; - T1 = -(T1 + grumpkin_curve_b); - - T2 = delta * w_2 * q_fixed_base; - T2 = T2 + T2; - - // x_accumulator_identity = α^2 * - // [(w_1,ω + w_1 + w_3,ω) * (w_3,ω - w_1)^2 - (b + w_3,ω^3 + w_2^2) + 2δ * w_2 * q_fixed_base] - Field x_accumulator_identity = (T0 + T1 + T2) * challenges.alpha_powers[2]; - - T0 = (w_2_omega + w_2) * (w_3_omega - w_1); - - T1 = w_1 - w_1_omega; - T2 = w_2 - (q_fixed_base * delta); - T1 = T1 * T2; - - // y_accumulator_identity = α^3 * - // [(w_2,ω + w_2) * (w_3,ω - w_1) + (w_1 - w_1,ω) * (w_2 - q_fixed_base * δ)] - Field y_accumulator_identity = (T0 + T1) * challenges.alpha_powers[3]; - - // accumulator_init_identity = α^4 * (w_4 - 1)(w_4 - 1 - w_3) - T0 = w_4 - Field(1); - T1 = T0 - w_3; - Field accumulator_init_identity = T0 * T1 * challenges.alpha_powers[4]; - - Field x_init_identity; - - // y_init_identity = α^6 * (q_c * (1 - w_4) - w_2 * w_3) - T0 = Field(1) - w_4; - T0 = T0 * q_c; - T1 = w_2 * w_3; - Field y_init_identity = (T0 - T1) * challenges.alpha_powers[6]; - - Field gate_identity = accumulator_init_identity + y_init_identity; - gate_identity = gate_identity * q_c; - gate_identity = - gate_identity + accumulator_identity + x_alpha_identity + x_accumulator_identity + y_accumulator_identity; - gate_identity = gate_identity * q_fixed_base; - - quotient += gate_identity; - } - - inline static void update_kate_opening_scalars(coefficient_array& linear_terms, - std::map& scalars, - const challenge_array&) - { - scalars["Q_M"] += linear_terms[0]; - scalars["Q_1"] += linear_terms[1]; - scalars["Q_2"] += linear_terms[2]; - scalars["Q_3"] += linear_terms[3]; - } -}; - -template -using UltraFixedBaseKernel = FixedBaseKernel; -} // namespace widget - -template -using ProverUltraFixedBaseWidget = widget::TransitionWidget; - -template -using VerifierUltraFixedBaseWidget = - widget::GenericVerifierWidget; -} // namespace proof_system::plonk \ No newline at end of file From 61d87ec791bc999f935789d4de3b9333c24634e8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 13 Nov 2023 18:54:18 +0000 Subject: [PATCH 2/6] consolidate comput and sum linear terms --- .../benchmark/widgets_bench/widget.bench.cpp | 4 +- .../transition_widgets/arithmetic_widget.hpp | 37 +++++-------------- .../transition_widgets/elliptic_widget.hpp | 22 ++--------- .../genperm_sort_widget.hpp | 18 +++------ .../transition_widgets/logic_widget.hpp | 18 +++------ .../plookup_arithmetic_widget.hpp | 17 ++++----- .../plookup_auxiliary_widget.hpp | 17 ++++----- .../transition_widgets/transition_widget.hpp | 7 ++-- 8 files changed, 45 insertions(+), 95 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp index eb2d7ec79da..44227c1153c 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp @@ -51,8 +51,8 @@ void plookup_auxiliary_kernel(::benchmark::State& state) noexcept // NOTE: this simply calls the following 3 functions it does NOT try to replicate ProverPlookupAuxiliaryWidget // logic exactly widget::containers::coefficient_array 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); + barretenberg::fr sum_of_linear_terms = + FFTKernel::compute_linear_terms(polynomials, challenges, linear_terms, 0); FFTKernel::compute_non_linear_terms(polynomials, challenges, sum_of_linear_terms, 0); } } diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp index e21da0141eb..ef0b0cec752 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp @@ -51,10 +51,10 @@ template 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 Field compute_linear_terms(PolyContainer& polynomials, + const challenge_array& challenges, + coefficient_array& linear_terms, + const size_t i = 0) { const Field& w_1 = Getters::template get_value(polynomials, i); @@ -67,30 +67,7 @@ template class ArithmeticKe 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(polynomials, i); @@ -112,6 +89,12 @@ template class ArithmeticKe return result; } + /** + * @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 Compute the scaled values of openings * diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp index b5d36f1d81c..dc211baabee 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp @@ -93,10 +93,10 @@ template 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 Field compute_linear_terms(PolyContainer& polynomials, + const challenge_array& challenges, + coefficient_array& linear_terms, + const size_t i = 0) { const Field& x_1 = Getters::template get_value(polynomials, i); @@ -140,21 +140,7 @@ template class EllipticKern 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; - } - /** - * @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(polynomials, i); diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp index ee8afe2dc9c..52318da06f3 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp @@ -27,10 +27,10 @@ template class GenPermSortK return required_polynomial_ids; } - inline static void compute_linear_terms(PolyContainer& polynomials, - const challenge_array& challenges, - coefficient_array& linear_terms, - const size_t i = 0) + inline static Field compute_linear_terms(PolyContainer& polynomials, + const challenge_array& challenges, + coefficient_array& linear_terms, + const size_t i = 0) { constexpr barretenberg::fr minus_two(-2); constexpr barretenberg::fr minus_three(-3); @@ -95,21 +95,15 @@ template class GenPermSortK range_accumulator += T0; linear_terms[0] = range_accumulator; - } - - inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} - inline static Field sum_linear_terms(PolyContainer& polynomials, - const challenge_array&, - coefficient_array& linear_terms, - const size_t i = 0) - { const Field& q_sort = Getters::template get_value(polynomials, i); return linear_terms[0] * q_sort; } + inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} + inline static void update_kate_opening_scalars(coefficient_array& linear_terms, std::map& scalars, const challenge_array&) diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp index 6edc1c1f432..14e28c5c492 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp @@ -41,10 +41,10 @@ template class LogicKernel return !q_logic.is_zero(); } - inline static void compute_linear_terms(PolyContainer& polynomials, - const challenge_array& challenges, - coefficient_array& linear_terms, - const size_t i = 0) + inline static Field compute_linear_terms(PolyContainer& polynomials, + const challenge_array& challenges, + coefficient_array& linear_terms, + const size_t i = 0) { constexpr barretenberg::fr six(6); constexpr barretenberg::fr eighty_one(81); @@ -202,21 +202,15 @@ template class LogicKernel identity *= alpha_base; linear_terms[0] = identity; - } - - inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} - inline static Field sum_linear_terms(PolyContainer& polynomials, - const challenge_array&, - coefficient_array& linear_terms, - const size_t i = 0) - { const Field& q_logic = Getters::template get_value(polynomials, i); return linear_terms[0] * q_logic; } + inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} + inline static void update_kate_opening_scalars(coefficient_array& linear_terms, std::map& scalars, const challenge_array&) diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp index c22caccd58f..14e9dd3b607 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp @@ -78,11 +78,13 @@ template class PlookupArith * @brief Stub for computing linear terms. Not used in plookup artihmetic gate * */ - inline static void compute_linear_terms(PolyContainer&, - const challenge_array&, - coefficient_array&, - const size_t = 0) - {} + inline static Field compute_linear_terms(PolyContainer&, + const challenge_array&, + coefficient_array&, + const size_t = 0) + { + return Field(0); + } /** * @brief Computes the full identity for the arithmetic gate in plookup to be added to the quotient. All the logic * is explained in class description @@ -170,11 +172,6 @@ template class PlookupArith quotient += identity; } - inline static Field sum_linear_terms(PolyContainer&, const challenge_array&, coefficient_array&, const size_t = 0) - { - return Field(0); - } - /** * @brief Stub for updating opening scalars, since not using linear terms * diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp index 093568b58a2..046ced6bc56 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp @@ -62,11 +62,13 @@ template class PlookupAuxil return required_polynomial_ids; } - inline static void compute_linear_terms(PolyContainer&, - const challenge_array&, - coefficient_array&, - const size_t = 0) - {} + inline static Field compute_linear_terms(PolyContainer&, + const challenge_array&, + coefficient_array&, + const size_t = 0) + { + return Field(0); + } inline static void compute_non_linear_terms(PolyContainer& polynomials, const challenge_array& challenges, @@ -327,11 +329,6 @@ template class PlookupAuxil quotient += (auxiliary_identity); } - inline static Field sum_linear_terms(PolyContainer&, const challenge_array&, coefficient_array&, const size_t = 0) - { - return Field(0); - } - inline static void update_kate_opening_scalars(coefficient_array&, std::map&, const challenge_array&) diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp index 727d92e796d..22ab496cada 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp @@ -331,8 +331,7 @@ class TransitionWidget : public TransitionWidgetBase { ITERATE_OVER_DOMAIN_START(key->large_domain); coefficient_array linear_terms; - FFTKernel::compute_linear_terms(polynomials, challenges, linear_terms, i); - Field sum_of_linear_terms = FFTKernel::sum_linear_terms(polynomials, challenges, linear_terms, i); + Field sum_of_linear_terms = FFTKernel::compute_linear_terms(polynomials, challenges, linear_terms, i); // populate split quotient components Field& quotient_term = @@ -372,8 +371,8 @@ class GenericVerifierWidget { // would be the contribution with linearization, then completes that smaller sum to the full contribution // without linearization. coefficient_array linear_terms; - EvaluationKernel::compute_linear_terms(polynomial_evaluations, challenges, linear_terms); - quotient_numerator_eval += EvaluationKernel::sum_linear_terms(polynomial_evaluations, challenges, linear_terms); + quotient_numerator_eval += + EvaluationKernel::compute_linear_terms(polynomial_evaluations, challenges, linear_terms); EvaluationKernel::compute_non_linear_terms(polynomial_evaluations, challenges, quotient_numerator_eval); return EvaluationGetter::update_alpha(challenges, num_independent_relations); From 6d28906cba478923506542efc5c1f18f3165757c Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 13 Nov 2023 18:57:21 +0000 Subject: [PATCH 3/6] remove update kate scalars --- .../transition_widgets/arithmetic_widget.hpp | 19 ------------------- .../transition_widgets/elliptic_widget.hpp | 13 ------------- .../genperm_sort_widget.hpp | 7 ------- .../transition_widgets/logic_widget.hpp | 7 ------- .../plookup_arithmetic_widget.hpp | 9 --------- .../plookup_auxiliary_widget.hpp | 5 ----- 6 files changed, 60 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp index ef0b0cec752..915f42444ad 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp @@ -94,25 +94,6 @@ template class ArithmeticKe * */ inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} - - /** - * @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& 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; - } }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp index dc211baabee..585ffdb449b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp @@ -148,19 +148,6 @@ template class EllipticKern } 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& scalars, - const challenge_array&) - { - scalars["Q_ELLIPTIC"] += linear_terms[0]; - } }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp index 52318da06f3..c42a054eed9 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp @@ -103,13 +103,6 @@ template class GenPermSortK } inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} - - inline static void update_kate_opening_scalars(coefficient_array& linear_terms, - std::map& scalars, - const challenge_array&) - { - scalars["Q_SORT"] += linear_terms[0]; - } }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp index 14e28c5c492..d02b65e68e8 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp @@ -210,13 +210,6 @@ template class LogicKernel } inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} - - inline static void update_kate_opening_scalars(coefficient_array& linear_terms, - std::map& scalars, - const challenge_array&) - { - scalars["Q_LOGIC"] += linear_terms[0]; - } }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp index 14e9dd3b607..340c4378e8b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp @@ -171,15 +171,6 @@ template class PlookupArith quotient += identity; } - - /** - * @brief Stub for updating opening scalars, since not using linear terms - * - */ - inline static void update_kate_opening_scalars(coefficient_array&, - std::map&, - const challenge_array&) - {} }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp index 046ced6bc56..b94037ef235 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp @@ -328,11 +328,6 @@ template class PlookupAuxil quotient += (auxiliary_identity); } - - inline static void update_kate_opening_scalars(coefficient_array&, - std::map&, - const challenge_array&) - {} }; } // namespace widget From 97fbe9f15525c91d0a61de8f1ebd2fcf37684a99 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 13 Nov 2023 19:26:43 +0000 Subject: [PATCH 4/6] consolidate into a single accum function --- .../benchmark/widgets_bench/widget.bench.cpp | 6 ++-- .../transition_widgets/arithmetic_widget.hpp | 31 ++++++------------- .../transition_widgets/elliptic_widget.hpp | 20 +++++------- .../genperm_sort_widget.hpp | 20 +++++------- .../transition_widgets/logic_widget.hpp | 20 +++++------- .../plookup_arithmetic_widget.hpp | 21 +++---------- .../plookup_auxiliary_widget.hpp | 17 +++------- .../transition_widgets/transition_widget.hpp | 15 ++------- 8 files changed, 43 insertions(+), 107 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp index 44227c1153c..454625eafd8 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp @@ -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 linear_terms; - barretenberg::fr sum_of_linear_terms = - FFTKernel::compute_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); diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp index 915f42444ad..125b5157f2f 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/arithmetic_widget.hpp @@ -28,8 +28,6 @@ template class ArithmeticKe private: // A structure with various challenges, even though only alpha is used here. typedef containers::challenge_array challenge_array; - // Type for the linear terms of the transition - typedef containers::coefficient_array coefficient_array; public: inline static std::set const& get_required_polynomial_ids() @@ -51,10 +49,10 @@ template class ArithmeticKe * @param linear_terms Container for results of computation * @param i Index at which the wire values are sampled. */ - inline static Field 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& w_1 = Getters::template get_value(polynomials, i); @@ -63,11 +61,6 @@ template class ArithmeticKe const Field& w_3 = Getters::template get_value(polynomials, i); - linear_terms[0] = w_1 * w_2; - linear_terms[1] = w_1; - linear_terms[2] = w_2; - linear_terms[3] = w_3; - const Field& alpha = challenges.alpha_powers[0]; const Field& q_1 = Getters::template get_value(polynomials, i); @@ -80,20 +73,14 @@ template class ArithmeticKe const Field& q_c = Getters::template get_value(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; + quotient += result; } - - /** - * @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) {} }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp index 585ffdb449b..71eb808eb1c 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/elliptic_widget.hpp @@ -72,7 +72,6 @@ template class EllipticKern private: typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; public: inline static std::set const& get_required_polynomial_ids() @@ -93,10 +92,10 @@ template class EllipticKern * @param linear_terms Output array * @param i Gate index */ - inline static Field 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(polynomials, i); @@ -106,6 +105,8 @@ template class EllipticKern const Field& y_2 = Getters::template get_value(polynomials, i); const Field& x_3 = Getters::template get_value(polynomials, i); const Field& y_3 = Getters::template get_value(polynomials, i); + const Field& q_elliptic = + Getters::template get_value(polynomials, i); // sign const Field& q_sign = @@ -139,15 +140,10 @@ template 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; - - const Field& q_elliptic = - Getters::template get_value(polynomials, i); + Field identity = x_identity + y_identity; - return linear_terms[0] * q_elliptic; + quotient += identity * q_elliptic; } - - inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp index c42a054eed9..eda0f942b08 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/genperm_sort_widget.hpp @@ -15,7 +15,6 @@ template class GenPermSortK private: typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; public: inline static std::set const& get_required_polynomial_ids() @@ -27,10 +26,10 @@ template class GenPermSortK return required_polynomial_ids; } - inline static Field 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) { constexpr barretenberg::fr minus_two(-2); constexpr barretenberg::fr minus_three(-3); @@ -47,6 +46,8 @@ template class GenPermSortK Getters::template get_value(polynomials, i); const Field& w_1_omega = Getters::template get_value(polynomials, i); + const Field& q_sort = + Getters::template get_value(polynomials, i); Field alpha_a = alpha_base; Field alpha_b = alpha_a * alpha; @@ -94,15 +95,8 @@ template class GenPermSortK T0 *= alpha_d; range_accumulator += T0; - linear_terms[0] = range_accumulator; - - const Field& q_sort = - Getters::template get_value(polynomials, i); - - return linear_terms[0] * q_sort; + quotient += range_accumulator * q_sort; } - - inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp index d02b65e68e8..a5ad8549fba 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp @@ -15,7 +15,6 @@ template class LogicKernel private: typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; public: inline static std::set const& get_required_polynomial_ids() @@ -41,10 +40,10 @@ template class LogicKernel return !q_logic.is_zero(); } - inline static Field 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) { constexpr barretenberg::fr six(6); constexpr barretenberg::fr eighty_one(81); @@ -69,6 +68,8 @@ template class LogicKernel const Field& q_c = Getters::template get_value(polynomials, i); + const Field& q_logic = + Getters::template get_value(polynomials, i); Field delta_sum; Field delta_squared_sum; @@ -201,15 +202,8 @@ template class LogicKernel identity += T2; identity *= alpha_base; - linear_terms[0] = identity; - - const Field& q_logic = - Getters::template get_value(polynomials, i); - - return linear_terms[0] * q_logic; + quotient += identity * q_logic; } - - inline static void compute_non_linear_terms(PolyContainer&, const challenge_array&, Field&, const size_t = 0) {} }; } // namespace widget diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp index 340c4378e8b..61323ab4619 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_arithmetic_widget.hpp @@ -60,8 +60,6 @@ template class PlookupArith private: // A structure with various challenges, even though only alpha is used here. typedef containers::challenge_array challenge_array; - // Type for the linear terms of the transition (not actually used here) - typedef containers::coefficient_array coefficient_array; public: inline static std::set const& get_required_polynomial_ids() @@ -74,17 +72,6 @@ template class PlookupArith return required_polynomial_ids; } - /** - * @brief Stub for computing linear terms. Not used in plookup artihmetic gate - * - */ - inline static Field compute_linear_terms(PolyContainer&, - const challenge_array&, - coefficient_array&, - const size_t = 0) - { - return Field(0); - } /** * @brief Computes the full identity for the arithmetic gate in plookup to be added to the quotient. All the logic * is explained in class description @@ -94,10 +81,10 @@ template class PlookupArith * @param quotient Quotient reference to add the result to * @param i Gate index */ - inline static void compute_non_linear_terms(PolyContainer& polynomials, - const challenge_array& challenges, - Field& quotient, - const size_t i = 0) + inline static void accumulate_contribution(PolyContainer& polynomials, + const challenge_array& challenges, + Field& quotient, + const size_t i = 0) { // For subgroup element i, this term evaluates to W_4(i \omega) * 2 iff Q_ARITH(i \omega) = 2 const Field& q_arith = diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp index b94037ef235..c582d6b1a7d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/plookup_auxiliary_widget.hpp @@ -49,7 +49,6 @@ template class PlookupAuxil private: typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; public: inline static std::set const& get_required_polynomial_ids() @@ -62,18 +61,10 @@ template class PlookupAuxil return required_polynomial_ids; } - inline static Field compute_linear_terms(PolyContainer&, - const challenge_array&, - coefficient_array&, - const size_t = 0) - { - return Field(0); - } - - inline static void compute_non_linear_terms(PolyContainer& polynomials, - const challenge_array& challenges, - Field& quotient, - const size_t i = 0) + inline static void accumulate_contribution(PolyContainer& polynomials, + const challenge_array& challenges, + Field& quotient, + const size_t i = 0) { constexpr barretenberg::fr LIMB_SIZE(uint256_t(1) << 68); constexpr barretenberg::fr SUBLIMB_SHIFT(uint256_t(1) << 14); diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp index 22ab496cada..3452e4cec28 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp @@ -48,8 +48,6 @@ template struct poly_ptr_map { size_t index_shift; }; -template using coefficient_array = std::array; - } // namespace containers /** @@ -287,7 +285,6 @@ class TransitionWidget : public TransitionWidgetBase { typedef containers::poly_ptr_map poly_ptr_map; typedef containers::poly_array poly_array; typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; public: typedef getters::EvaluationGetter @@ -330,14 +327,10 @@ class TransitionWidget : public TransitionWidgetBase { FFTGetter::get_challenges(transcript, alpha_base, FFTKernel::quotient_required_challenges); ITERATE_OVER_DOMAIN_START(key->large_domain); - coefficient_array linear_terms; - Field sum_of_linear_terms = FFTKernel::compute_linear_terms(polynomials, challenges, linear_terms, i); - // populate split quotient components Field& quotient_term = key->quotient_polynomial_parts[i >> key->small_domain.log2_size][i & (key->circuit_size - 1)]; - quotient_term += sum_of_linear_terms; - FFTKernel::compute_non_linear_terms(polynomials, challenges, quotient_term, i); + FFTKernel::accumulate_contribution(polynomials, challenges, quotient_term, i); ITERATE_OVER_DOMAIN_END; return FFTGetter::update_alpha(challenges, FFTKernel::num_independent_relations); @@ -351,7 +344,6 @@ class GenericVerifierWidget { typedef containers::poly_ptr_map poly_ptr_map; typedef containers::poly_array poly_array; typedef containers::challenge_array challenge_array; - typedef containers::coefficient_array coefficient_array; public: typedef getters::EvaluationGetter EvaluationGetter; @@ -370,10 +362,7 @@ class GenericVerifierWidget { // As in the permutation widget, we have vestiges of the linearization trick: the code first computes what // would be the contribution with linearization, then completes that smaller sum to the full contribution // without linearization. - coefficient_array linear_terms; - quotient_numerator_eval += - EvaluationKernel::compute_linear_terms(polynomial_evaluations, challenges, linear_terms); - EvaluationKernel::compute_non_linear_terms(polynomial_evaluations, challenges, quotient_numerator_eval); + EvaluationKernel::accumulate_contribution(polynomial_evaluations, challenges, quotient_numerator_eval); return EvaluationGetter::update_alpha(challenges, num_independent_relations); } From 77fbf360f4e6fd04cb3e3e3473116bda7b992db1 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 13 Nov 2023 19:40:14 +0000 Subject: [PATCH 5/6] update comment --- .../widgets/transition_widgets/transition_widget.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp index 3452e4cec28..9f3cc1cb2b5 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/transition_widget.hpp @@ -359,9 +359,7 @@ class GenericVerifierWidget { challenge_array challenges = EvaluationGetter::get_challenges(transcript, alpha_base, EvaluationKernel::quotient_required_challenges); - // As in the permutation widget, we have vestiges of the linearization trick: the code first computes what - // would be the contribution with linearization, then completes that smaller sum to the full contribution - // without linearization. + // Accumulate the contribution from the widget into the quotient EvaluationKernel::accumulate_contribution(polynomial_evaluations, challenges, quotient_numerator_eval); return EvaluationGetter::update_alpha(challenges, num_independent_relations); From 9bcb80f136396bda880042c8719edfb7cd82eaf0 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 14 Nov 2023 09:56:14 +0000 Subject: [PATCH 6/6] delete logic widget which was no longer used --- .../types/polynomial_manifest.hpp | 1 - .../proof_system/types/program_settings.hpp | 4 - .../transition_widgets/logic_widget.hpp | 217 ------------------ .../recursion/verifier/program_settings.hpp | 2 - 4 files changed, 224 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp index d4148be017b..be4a634883f 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp @@ -23,7 +23,6 @@ enum PolynomialIndex { Q_FIXED_BASE, Q_RANGE, Q_SORT, - Q_LOGIC, TABLE_1, TABLE_2, TABLE_3, diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp index a9d20a7474f..1b849b49a8d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp @@ -8,7 +8,6 @@ #include "../widgets/transition_widgets/arithmetic_widget.hpp" #include "../widgets/transition_widgets/elliptic_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" @@ -63,7 +62,6 @@ class ultra_verifier_settings : public ultra_settings { typedef transcript::StandardTranscript Transcript; typedef VerifierPlookupArithmeticWidget PlookupArithmeticWidget; typedef VerifierGenPermSortWidget GenPermSortWidget; - typedef VerifierLogicWidget LogicWidget; typedef VerifierPermutationWidget PermutationWidget; typedef VerifierPlookupWidget PlookupWidget; typedef VerifierEllipticWidget EllipticWidget; @@ -119,7 +117,6 @@ class ultra_to_standard_verifier_settings : public ultra_verifier_settings { typedef VerifierPlookupArithmeticWidget PlookupArithmeticWidget; typedef VerifierGenPermSortWidget GenPermSortWidget; - typedef VerifierLogicWidget LogicWidget; typedef VerifierPermutationWidget PermutationWidget; typedef VerifierPlookupWidget PlookupWidget; typedef VerifierEllipticWidget EllipticWidget; @@ -135,7 +132,6 @@ class ultra_with_keccak_verifier_settings : public ultra_verifier_settings { typedef VerifierPlookupArithmeticWidget PlookupArithmeticWidget; typedef VerifierGenPermSortWidget GenPermSortWidget; - typedef VerifierLogicWidget LogicWidget; typedef VerifierPermutationWidget PermutationWidget; typedef VerifierPlookupWidget PlookupWidget; typedef VerifierEllipticWidget EllipticWidget; diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp deleted file mode 100644 index a5ad8549fba..00000000000 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/transition_widgets/logic_widget.hpp +++ /dev/null @@ -1,217 +0,0 @@ -#pragma once - -#include "./transition_widget.hpp" - -namespace proof_system::plonk { -namespace widget { - -template class LogicKernel { - public: - static constexpr size_t num_independent_relations = 4; - // We state the challenges required for linear/nonlinear terms computation - static constexpr uint8_t quotient_required_challenges = CHALLENGE_BIT_ALPHA; - // We state the challenges required for updating kate opening scalars - static constexpr uint8_t update_required_challenges = CHALLENGE_BIT_ALPHA; - - private: - typedef containers::challenge_array challenge_array; - - public: - inline static std::set const& get_required_polynomial_ids() - { - static const std::set required_polynomial_ids = { - PolynomialIndex::Q_C, PolynomialIndex::Q_LOGIC, PolynomialIndex::W_1, - PolynomialIndex::W_2, PolynomialIndex::W_3, PolynomialIndex::W_4 - }; - return required_polynomial_ids; - } - - /** - * @brief Quickly checks if the result of all computation will be zero because of the selector or not - * - * @param polynomials Polynomial or simulated container - * @param i Gate index - * @return q_logic[i] != 0 - */ - inline static bool gate_enabled(PolyContainer& polynomials, const size_t i = 0) - { - const Field& q_logic = - Getters::template get_value(polynomials, i); - return !q_logic.is_zero(); - } - - inline static void accumulate_contribution(PolyContainer& polynomials, - const challenge_array& challenges, - Field& quotient, - const size_t i = 0) - { - constexpr barretenberg::fr six(6); - constexpr barretenberg::fr eighty_one(81); - constexpr barretenberg::fr eighty_three(83); - - const Field& alpha_base = challenges.alpha_powers[0]; - const Field& alpha = challenges.elements[ChallengeIndex::ALPHA]; - const Field& w_1 = - Getters::template get_value(polynomials, i); - const Field& w_2 = - Getters::template get_value(polynomials, i); - const Field& w_3 = - Getters::template get_value(polynomials, i); - const Field& w_4 = - Getters::template get_value(polynomials, i); - const Field& w_1_omega = - Getters::template get_value(polynomials, i); - const Field& w_2_omega = - Getters::template get_value(polynomials, i); - const Field& w_4_omega = - Getters::template get_value(polynomials, i); - - const Field& q_c = - Getters::template get_value(polynomials, i); - const Field& q_logic = - Getters::template get_value(polynomials, i); - - Field delta_sum; - Field delta_squared_sum; - Field T0; - Field T1; - Field T2; - Field T3; - Field T4; - Field identity; - - T0 = w_1 + w_1; - T0 += T0; - T0 = w_1_omega - T0; - - // T1 = b - T1 = w_2 + w_2; - T1 += T1; - T1 = w_2_omega - T1; - - // delta_sum = a + b - delta_sum = T0 + T1; - - // T2 = a^2, T3 = b^2 - T2 = T0.sqr(); - T3 = T1.sqr(); - - delta_squared_sum = T2 + T3; - - // identity = a^2 + b^2 + 2ab - identity = delta_sum.sqr(); - // identity = 2ab - identity -= delta_squared_sum; - - // identity = 2(ab - w) - T4 = w_3 + w_3; - identity -= T4; - identity *= alpha; - - // T4 = 4w - T4 += T4; - - // T2 = a^2 - a - T2 -= T0; - - // T0 = a^2 - 5a + 6 - T0 += T0; - T0 += T0; - T0 = T2 - T0; - T0 += six; - - // identity = (identity + a(a - 1)(a - 2)(a - 3)) * alpha - T0 *= T2; - identity += T0; - identity *= alpha; - - // T3 = b^2 - b - T3 -= T1; - - // T1 = b^2 - 5b + 6 - T1 += T1; - T1 += T1; - T1 = T3 - T1; - T1 += six; - - // identity = (identity + b(b - 1)(b - 2)(b - 3)) * alpha - T1 *= T3; - identity += T1; - identity *= alpha; - - // T0 = 3(a + b) - T0 = delta_sum + delta_sum; - T0 += delta_sum; - - // T1 = 9(a + b) - T1 = T0 + T0; - T1 += T0; - - // delta_sum = 18(a + b) - delta_sum = T1 + T1; - - // T1 = 81(a + b) - T2 = delta_sum + delta_sum; - T2 += T2; - T1 += T2; - - // delta_squared_sum = 18(a^2 + b^2) - T2 = delta_squared_sum + delta_squared_sum; - T2 += delta_squared_sum; - delta_squared_sum = T2 + T2; - delta_squared_sum += T2; - delta_squared_sum += delta_squared_sum; - - // delta_sum = w(4w - 18(a + b) + 81) - delta_sum = T4 - delta_sum; - delta_sum += eighty_one; - delta_sum *= w_3; - - // T1 = 18(a^2 + b^2) - 81(a + b) + 83 - T1 = delta_squared_sum - T1; - T1 += eighty_three; - - // delta_sum = w ( w ( 4w - 18(a + b) + 81) + 18(a^2 + b^2) - 81(a + b) + 83) - delta_sum += T1; - delta_sum *= w_3; - - // T2 = 3c - T2 = w_4 + w_4; - T2 += T2; - T2 = w_4_omega - T2; - T3 = T2 + T2; - T2 += T3; - - // T3 = 9c - T3 = T2 + T2; - T3 += T2; - - // T3 = q_c * (9c - 3(a + b)) - T3 -= T0; - T3 *= q_c; - - // T2 = 3c + 3(a + b) - 2 * delta_sum - T2 += T0; - delta_sum += delta_sum; - T2 -= delta_sum; - - // T2 = T2 + T3 - T2 += T3; - - // identity = q_logic * alpha_base * (identity + T2) - identity += T2; - identity *= alpha_base; - - quotient += identity * q_logic; - } -}; - -} // namespace widget - -template -using ProverLogicWidget = widget::TransitionWidget; - -template -using VerifierLogicWidget = widget::GenericVerifierWidget; - -} // namespace proof_system::plonk \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp index f86d7963697..90d600eab22 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp @@ -20,7 +20,6 @@ template class recursive_ultra_verifier_settings : public plonk typedef proof_system::plonk::VerifierPlookupArithmeticWidget PlookupArithmeticWidget; - typedef proof_system::plonk::VerifierLogicWidget LogicWidget; typedef proof_system::plonk::VerifierGenPermSortWidget GenPermSortWidget; typedef proof_system::plonk::VerifierEllipticWidget EllipticWidget; typedef proof_system::plonk::VerifierPlookupAuxiliaryWidget @@ -98,7 +97,6 @@ class recursive_ultra_to_standard_verifier_settings : public recursive_ultra_ver typedef proof_system::plonk::VerifierPlookupArithmeticWidget PlookupArithmeticWidget; - typedef proof_system::plonk::VerifierLogicWidget LogicWidget; typedef proof_system::plonk::VerifierGenPermSortWidget GenPermSortWidget; typedef proof_system::plonk::VerifierEllipticWidget EllipticWidget; typedef proof_system::plonk::VerifierPlookupAuxiliaryWidget