Skip to content

Commit

Permalink
zero representation in unified addition component changed from (0,0) …
Browse files Browse the repository at this point in the history
…to (0,1)
  • Loading branch information
CblPOK-git committed Sep 26, 2023
1 parent 95645c9 commit c904644
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace nil {
assignment.witness(component.W(2), j) = Q.X;
assignment.witness(component.W(3), j) = Q.Y;
typename CurveType::template g1_type<crypto3::algebra::curves::coordinates::affine>::value_type zero = {
0, 0};
0, 1};
if (P.X == zero.X && P.Y == zero.Y) {
assignment.witness(component.W(4), j) = Q.X;
assignment.witness(component.W(5), j) = Q.Y;
Expand All @@ -174,7 +174,7 @@ namespace nil {
} else {
if (Q.X == P.X && Q.Y == -P.Y) {
assignment.witness(component.W(4), j) = 0;
assignment.witness(component.W(5), j) = 0;
assignment.witness(component.W(5), j) = 1;
} else {
assignment.witness(component.W(4), j) = (P + Q).X;
assignment.witness(component.W(5), j) = (P + Q).Y;
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace nil {
auto constraint_12 = bp.add_constraint(
(1 - (var(component.W(2), 0) - var(component.W(0), 0)) * var(component.W(8), 0) -
(var(component.W(3), 0) + var(component.W(1), 0)) * var(component.W(9), 0)) *
var(component.W(5), 0));
(1 - var(component.W(5), 0)));

bp.add_gate(first_selector_index,
{constraint_1, constraint_2, constraint_3, constraint_4, constraint_5, constraint_6,
Expand Down
23 changes: 13 additions & 10 deletions test/algebra/curves/plonk/unified_addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ void test_unified_addition(std::vector<typename CurveType::base_field_type::valu

auto result_check = [&expected_res, public_input](AssignmentType &assignment,
typename component_type::result_type &real_res) {
#ifdef BLUEPRINT_PLONK_PROFILING_ENABLED
std::cout << "unified_addition test: " << "\n";
std::cout << "input : " << public_input[0].data << " " << public_input[1].data << "\n";
std::cout << "input : " << public_input[2].data << " " << public_input[3].data << "\n";
std::cout << "expected: " << expected_res.X.data << " " << expected_res.Y.data << "\n";
std::cout << "real : " << var_value(assignment, real_res.X).data << " " << var_value(assignment, real_res.Y).data << "\n\n";
#endif

if((expected_res.X != var_value(assignment, real_res.X)) || (expected_res.Y != var_value(assignment, real_res.Y))) {
std::cout << "unified_addition failed, expected result differs form circuit output: " << "\n";
std::cout << "input : " << public_input[0].data << " " << public_input[1].data << "\n";
std::cout << "input : " << public_input[2].data << " " << public_input[3].data << "\n";
std::cout << "expected: " << expected_res.X.data << " " << expected_res.Y.data << "\n";
std::cout << "real : " << var_value(assignment, real_res.X).data << " " << var_value(assignment, real_res.Y).data << "\n\n";
}
assert(expected_res.X == var_value(assignment, real_res.X));
assert(expected_res.Y == var_value(assignment, real_res.Y));
};
Expand All @@ -97,8 +98,7 @@ void test_unified_addition_with_zeroes() {
boost::random::mt19937 seed_seq;
generate_random_point.seed(seed_seq);

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

Expand Down Expand Up @@ -146,14 +146,14 @@ void test_unified_addition_random_data() {

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

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

for (std::size_t i = 0; i < RandomTestsAmount; i++){
P = generate_random_point();
Q = generate_random_point();
<<<<<<< HEAD

if (Q.X == zero.X && Q.Y == zero.Y) {
expected_res = P;
Expand All @@ -168,6 +168,9 @@ void test_unified_addition_random_data() {
}
}
}
=======
expected_res = P + Q;
>>>>>>> 1c5f11c9 (zero representation in unified addition component changed from (0,0) to (0,1))

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

0 comments on commit c904644

Please sign in to comment.