diff --git a/include/nil/blueprint/basic_non_native_policy.hpp b/include/nil/blueprint/basic_non_native_policy.hpp index 42657a0ae..c591880da 100644 --- a/include/nil/blueprint/basic_non_native_policy.hpp +++ b/include/nil/blueprint/basic_non_native_policy.hpp @@ -74,12 +74,24 @@ namespace nil { chopped_value_type result; for (std::size_t i = 0; i < ratio; i++) { result[i] = get_i_th_chunk(input, i); - } - return result; + } + static non_native_field_type::value_type glue_non_native(chopped_value_type input) { + non_native_field_type::value_type result; + native_field_type::integral_type integral_input; + result = non_native_field_type::value_type(native_field_type::integral_type(input[0].data)); + for (std::size_t i = 1; i < ratio; i++) { + std::size_t shift = 0; + for (std::size_t j = 0; j < i; j++) { + shift += chunk_sizes[j]; + } + result += non_native_field_type::value_type(native_field_type::integral_type(input[i].data) << shift); + } + return result; } + }; /* @@ -132,12 +144,24 @@ namespace nil { chopped_value_type result; for (std::size_t i = 0; i < ratio; i++) { result[i] = get_i_th_chunk(input, i); - } - return result; + } + static non_native_field_type::value_type glue_non_native(chopped_value_type input) { + non_native_field_type::value_type result; + native_field_type::integral_type integral_input; + result = non_native_field_type::value_type(native_field_type::integral_type(input[0].data)); + for (std::size_t i = 1; i < ratio; i++) { + std::size_t shift = 0; + for (std::size_t j = 0; j < i; j++) { + shift += chunk_sizes[j]; + } + result += non_native_field_type::value_type(native_field_type::integral_type(input[i].data) << shift); + } + return result; } + }; /* diff --git a/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp b/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp index ea72918b2..c50300c04 100644 --- a/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp +++ b/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp @@ -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::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; @@ -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; @@ -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, diff --git a/test/algebra/curves/plonk/unified_addition.cpp b/test/algebra/curves/plonk/unified_addition.cpp index 4df59fd23..a6271a932 100644 --- a/test/algebra/curves/plonk/unified_addition.cpp +++ b/test/algebra/curves/plonk/unified_addition.cpp @@ -74,13 +74,14 @@ void test_unified_addition(std::vector::value_type zero_algebraic = {0, 1}; - typename CurveType::template g1_type::value_type zero_circuits = {0, 0}; + typename CurveType::template g1_type::value_type zero_circuits = {0, 1}; typename CurveType::template g1_type::value_type P = generate_random_point(); typename CurveType::template g1_type::value_type Q = -P; @@ -146,7 +146,6 @@ void test_unified_addition_random_data() { typename CurveType::template g1_type::value_type P = generate_random_point(); typename CurveType::template g1_type::value_type Q = generate_random_point(); - typename CurveType::template g1_type::value_type zero = {0, 0}; typename CurveType::template g1_type::value_type expected_res; std::vector public_input; @@ -154,6 +153,7 @@ void test_unified_addition_random_data() { 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; @@ -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(public_input, expected_res);