barretenberg
Loading...
Searching...
No Matches
genperm_sort_widget.hpp
1#pragma once
2
3#include "./transition_widget.hpp"
4
5namespace proof_system::plonk {
6namespace widget {
7
8template <class Field, class Getters, typename PolyContainer> class GenPermSortKernel {
9 public:
10 static constexpr size_t num_independent_relations = 4;
11 // We state the challenges required for linear/nonlinear terms computation
12 static constexpr uint8_t quotient_required_challenges = CHALLENGE_BIT_ALPHA;
13 // We state the challenges required for updating kate opening scalars
14 static constexpr uint8_t update_required_challenges = CHALLENGE_BIT_ALPHA;
15
16 private:
18
19 public:
20 inline static std::set<PolynomialIndex> const& get_required_polynomial_ids()
21 {
22 static const std::set<PolynomialIndex> required_polynomial_ids = {
23 PolynomialIndex::Q_SORT, PolynomialIndex::W_1, PolynomialIndex::W_2,
24 PolynomialIndex::W_3, PolynomialIndex::W_4, PolynomialIndex::Z
25 };
26 return required_polynomial_ids;
27 }
28
29 inline static void accumulate_contribution(PolyContainer& polynomials,
30 const challenge_array& challenges,
31 Field& quotient,
32 const size_t i = 0)
33 {
34 constexpr barretenberg::fr minus_two(-2);
35 constexpr barretenberg::fr minus_three(-3);
36
37 const Field& alpha_base = challenges.alpha_powers[0];
38 const Field& alpha = challenges.elements[ChallengeIndex::ALPHA];
39 const Field& w_1 =
40 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_1>(polynomials, i);
41 const Field& w_2 =
42 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_2>(polynomials, i);
43 const Field& w_3 =
44 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_3>(polynomials, i);
45 const Field& w_4 =
46 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_4>(polynomials, i);
47 const Field& w_1_omega =
48 Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_1>(polynomials, i);
49 const Field& q_sort =
50 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_SORT>(polynomials, i);
51
52 Field alpha_a = alpha_base;
53 Field alpha_b = alpha_a * alpha;
54 Field alpha_c = alpha_b * alpha;
55 Field alpha_d = alpha_c * alpha;
56
57 Field delta_1 = w_2 - w_1;
58 Field delta_2 = w_3 - w_2;
59 Field delta_3 = w_4 - w_3;
60 Field delta_4 = w_1_omega - w_4;
61
62 // D(D - 1)(D - 2)(D - 3).alpha
63 Field T0 = delta_1.sqr();
64 T0 -= delta_1;
65 Field T1 = delta_1 + minus_two;
66 T0 *= T1;
67 T1 = delta_1 + minus_three;
68 T0 *= T1;
69 Field range_accumulator = T0 * alpha_a;
70
71 T0 = delta_2.sqr();
72 T0 -= delta_2;
73 T1 = delta_2 + minus_two;
74 T0 *= T1;
75 T1 = delta_2 + minus_three;
76 T0 *= T1;
77 T0 *= alpha_b;
78 range_accumulator += T0;
79
80 T0 = delta_3.sqr();
81 T0 -= delta_3;
82 T1 = delta_3 + minus_two;
83 T0 *= T1;
84 T1 = delta_3 + minus_three;
85 T0 *= T1;
86 T0 *= alpha_c;
87 range_accumulator += T0;
88
89 T0 = delta_4.sqr();
90 T0 -= delta_4;
91 T1 = delta_4 + minus_two;
92 T0 *= T1;
93 T1 = delta_4 + minus_three;
94 T0 *= T1;
95 T0 *= alpha_d;
96 range_accumulator += T0;
97
98 quotient += range_accumulator * q_sort;
99 }
100};
101
102} // namespace widget
103
104template <typename Settings>
106
107template <typename Field, typename Group, typename Transcript, typename Settings>
109
110} // namespace proof_system::plonk
Definition: genperm_sort_widget.hpp:8
Definition: transition_widget.hpp:341
Definition: transition_widget.hpp:282
Definition: widget.bench.cpp:13
BBERG_INLINE constexpr field sqr() const noexcept
Definition: field_impl.hpp:61