barretenberg
Loading...
Searching...
No Matches
elliptic_widget.hpp
1#pragma once
2
3#include "./transition_widget.hpp"
4
5namespace proof_system::plonk {
6namespace widget {
7
65template <class Field, class Getters, typename PolyContainer> class EllipticKernel {
66 public:
67 static constexpr size_t num_independent_relations = 4;
68 // We state the challenges required for linear/nonlinear terms computation
69 static constexpr uint8_t quotient_required_challenges = CHALLENGE_BIT_ALPHA;
70 // We state the challenges required for updating kate opening scalars
71 static constexpr uint8_t update_required_challenges = CHALLENGE_BIT_ALPHA;
72
73 private:
75
76 public:
77 inline static std::set<PolynomialIndex> const& get_required_polynomial_ids()
78 {
79 static const std::set<PolynomialIndex> required_polynomial_ids = {
80 PolynomialIndex::Q_1, PolynomialIndex::Q_3, PolynomialIndex::Q_4,
81 PolynomialIndex::Q_M, PolynomialIndex::Q_ELLIPTIC, PolynomialIndex::W_1,
82 PolynomialIndex::W_2, PolynomialIndex::W_3, PolynomialIndex::W_4
83 };
84 return required_polynomial_ids;
85 }
86
95 inline static void accumulate_contribution(PolyContainer& polynomials,
96 const challenge_array& challenges,
97 Field& quotient,
98 const size_t i = 0)
99 {
100 const Field& x_1 =
101 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_2>(polynomials, i);
102 const Field& y_1 =
103 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::W_3>(polynomials, i);
104 const Field& x_2 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_1>(polynomials, i);
105 const Field& y_2 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_4>(polynomials, i);
106 const Field& x_3 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_2>(polynomials, i);
107 const Field& y_3 = Getters::template get_value<EvaluationType::SHIFTED, PolynomialIndex::W_3>(polynomials, i);
108 const Field& q_elliptic =
109 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_ELLIPTIC>(polynomials, i);
110
111 // sign
112 const Field& q_sign =
113 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_1>(polynomials, i);
114
115 // ecc add gate is active when q_elliptic = 1 and q_m = 0
116 // ecc double gate is active when q_elliptic = 1 and q_m = 1
117 const Field& q_is_double =
118 Getters::template get_value<EvaluationType::NON_SHIFTED, PolynomialIndex::Q_M>(polynomials, i);
119
120 Field x_diff = x_2 - x_1;
121 Field y1_sqr = y_1.sqr();
122 Field y2_sqr = y_2.sqr();
123 Field y1y2 = y_1 * y_2 * q_sign;
124 Field x_identity_add = (x_3 + x_2 + x_1) * x_diff.sqr() - y1_sqr - y2_sqr + y1y2 + y1y2;
125 Field y_identity_add = (y_3 + y_1) * x_diff + (x_3 - x_1) * (y_2 * q_sign - y_1);
126
127 // x-coordinate identity
128 // (x3 + 2x1)(4y^2) - (9x^4) = 0
129 // This is degree 4...but
130 // we can use x^3 = y^2 - b
131 // (x3 + 2x1)(4y ^ 2) - (9x(y ^ 2 - b)) is degree 3
132 const Field x_pow_4 = (y_1 * y_1 - grumpkin::g1::curve_b) * x_1;
133 Field x_identity_double = (x_3 + x_1 + x_1) * (y_1 + y_1) * (y_1 + y_1) - x_pow_4 * Field(9);
134
135 // Y identity: (x1 - x3)(3x^2) - (2y1)(y1 + y3) = 0
136 const Field x_pow_2 = (x_1 * x_1);
137 Field y_identity_double = x_pow_2 * (x_1 - x_3) * 3 - (y_1 + y_1) * (y_1 + y_3);
138
139 auto x_identity =
140 (q_is_double * (x_identity_double - x_identity_add) + x_identity_add) * challenges.alpha_powers[0];
141 auto y_identity =
142 (q_is_double * (y_identity_double - y_identity_add) + y_identity_add) * challenges.alpha_powers[1];
143 Field identity = x_identity + y_identity;
144
145 quotient += identity * q_elliptic;
146 }
147};
148
149} // namespace widget
150
151template <typename Settings>
152using ProverEllipticWidget = widget::TransitionWidget<barretenberg::fr, Settings, widget::EllipticKernel>;
153
154template <typename Field, typename Group, typename Transcript, typename Settings>
155using VerifierEllipticWidget = widget::GenericVerifierWidget<Field, Transcript, Settings, widget::EllipticKernel>;
156
157} // namespace proof_system::plonk
Core class implementing elliptic curve point addition. It is enhanced to handle the case where one of...
Definition: elliptic_widget.hpp:65
static void accumulate_contribution(PolyContainer &polynomials, const challenge_array &challenges, Field &quotient, const size_t i=0)
Computes the single linear term for elliptic point addition.
Definition: elliptic_widget.hpp:95
Definition: widget.bench.cpp:13