Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit c904644

Browse files
committed
zero representation in unified addition component changed from (0,0) to (0,1)
1 parent 95645c9 commit c904644

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace nil {
163163
assignment.witness(component.W(2), j) = Q.X;
164164
assignment.witness(component.W(3), j) = Q.Y;
165165
typename CurveType::template g1_type<crypto3::algebra::curves::coordinates::affine>::value_type zero = {
166-
0, 0};
166+
0, 1};
167167
if (P.X == zero.X && P.Y == zero.Y) {
168168
assignment.witness(component.W(4), j) = Q.X;
169169
assignment.witness(component.W(5), j) = Q.Y;
@@ -174,7 +174,7 @@ namespace nil {
174174
} else {
175175
if (Q.X == P.X && Q.Y == -P.Y) {
176176
assignment.witness(component.W(4), j) = 0;
177-
assignment.witness(component.W(5), j) = 0;
177+
assignment.witness(component.W(5), j) = 1;
178178
} else {
179179
assignment.witness(component.W(4), j) = (P + Q).X;
180180
assignment.witness(component.W(5), j) = (P + Q).Y;
@@ -275,7 +275,7 @@ namespace nil {
275275
auto constraint_12 = bp.add_constraint(
276276
(1 - (var(component.W(2), 0) - var(component.W(0), 0)) * var(component.W(8), 0) -
277277
(var(component.W(3), 0) + var(component.W(1), 0)) * var(component.W(9), 0)) *
278-
var(component.W(5), 0));
278+
(1 - var(component.W(5), 0)));
279279

280280
bp.add_gate(first_selector_index,
281281
{constraint_1, constraint_2, constraint_3, constraint_4, constraint_5, constraint_6,

test/algebra/curves/plonk/unified_addition.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ void test_unified_addition(std::vector<typename CurveType::base_field_type::valu
7474

7575
auto result_check = [&expected_res, public_input](AssignmentType &assignment,
7676
typename component_type::result_type &real_res) {
77-
#ifdef BLUEPRINT_PLONK_PROFILING_ENABLED
78-
std::cout << "unified_addition test: " << "\n";
79-
std::cout << "input : " << public_input[0].data << " " << public_input[1].data << "\n";
80-
std::cout << "input : " << public_input[2].data << " " << public_input[3].data << "\n";
81-
std::cout << "expected: " << expected_res.X.data << " " << expected_res.Y.data << "\n";
82-
std::cout << "real : " << var_value(assignment, real_res.X).data << " " << var_value(assignment, real_res.Y).data << "\n\n";
83-
#endif
77+
78+
if((expected_res.X != var_value(assignment, real_res.X)) || (expected_res.Y != var_value(assignment, real_res.Y))) {
79+
std::cout << "unified_addition failed, expected result differs form circuit output: " << "\n";
80+
std::cout << "input : " << public_input[0].data << " " << public_input[1].data << "\n";
81+
std::cout << "input : " << public_input[2].data << " " << public_input[3].data << "\n";
82+
std::cout << "expected: " << expected_res.X.data << " " << expected_res.Y.data << "\n";
83+
std::cout << "real : " << var_value(assignment, real_res.X).data << " " << var_value(assignment, real_res.Y).data << "\n\n";
84+
}
8485
assert(expected_res.X == var_value(assignment, real_res.X));
8586
assert(expected_res.Y == var_value(assignment, real_res.Y));
8687
};
@@ -97,8 +98,7 @@ void test_unified_addition_with_zeroes() {
9798
boost::random::mt19937 seed_seq;
9899
generate_random_point.seed(seed_seq);
99100

100-
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type zero_algebraic = {0, 1};
101-
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type zero_circuits = {0, 0};
101+
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type zero_circuits = {0, 1};
102102
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type P = generate_random_point();
103103
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type Q = -P;
104104

@@ -146,14 +146,14 @@ void test_unified_addition_random_data() {
146146

147147
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type P = generate_random_point();
148148
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type Q = generate_random_point();
149-
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type zero = {0, 0};
150149
typename CurveType::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type expected_res;
151150

152151
std::vector<typename CurveType::base_field_type::value_type> public_input;
153152

154153
for (std::size_t i = 0; i < RandomTestsAmount; i++){
155154
P = generate_random_point();
156155
Q = generate_random_point();
156+
<<<<<<< HEAD
157157

158158
if (Q.X == zero.X && Q.Y == zero.Y) {
159159
expected_res = P;
@@ -168,6 +168,9 @@ void test_unified_addition_random_data() {
168168
}
169169
}
170170
}
171+
=======
172+
expected_res = P + Q;
173+
>>>>>>> 1c5f11c9 (zero representation in unified addition component changed from (0,0) to (0,1))
171174

172175
public_input = {P.X, P.Y, Q.X, Q.Y};
173176
test_unified_addition<CurveType>(public_input, expected_res);

0 commit comments

Comments
 (0)