diff --git a/include/nil/blueprint/components/algebra/curves/detail/plonk/mnt4_g2_point_addition.hpp b/include/nil/blueprint/components/algebra/curves/detail/plonk/mnt4_g2_point_addition.hpp index 5e91e1a9a..be48d1c52 100644 --- a/include/nil/blueprint/components/algebra/curves/detail/plonk/mnt4_g2_point_addition.hpp +++ b/include/nil/blueprint/components/algebra/curves/detail/plonk/mnt4_g2_point_addition.hpp @@ -47,6 +47,10 @@ namespace nil { namespace blueprint { namespace components { + + using mnt4_g2_params = crypto3::algebra::curves::detail:: + mnt4_g2_params<298,crypto3::algebra::curves::forms::short_weierstrass>; + // E'(F_p^2) : y^2 = x^3 + a*x + b point addition gate. // Expects point at infinity encoded by (0,0) in input and output // Input: (xP, yP) = P[4], (xQ, yQ) = Q[4] @@ -70,7 +74,6 @@ namespace nil { public: using component_type = plonk_component; - using var = typename component_type::var; using manifest_type = plonk_component_manifest; @@ -187,7 +190,7 @@ namespace nil { zQ = yQ.inversed(), zPQ = (xP - xQ).inversed(), wPQ = (yP + yQ).inversed(), - lambda = (xP == xQ)? ((3*xP.pow(2) + mnt4_298::g2_type::params_type::a ) / (2*yP)) : ((yP-yQ)/(xP-xQ)), + lambda = (xP == xQ)? ((3*xP.pow(2) + mnt4_g2_params::a ) / (2*yP)) : ((yP-yQ)/(xP-xQ)), nu = yP - lambda*xP, xR, yR; if (yP == fp2zero) { @@ -243,12 +246,20 @@ namespace nil { using constraint_type = crypto3::zk::snark::plonk_constraint; // Fp2 field over constraints: - using fp2_constraint = detail::abstract_fp2_element; + using fp2_constraint = detail::abstract_fp2_element< + constraint_type, + typename mnt4_g2_params::field_type::value_type >; constraint_type cnstr_zero = constraint_type(), cnstr_one = cnstr_zero + 1; + constraint_type + constr_a0 = constraint_type()+mnt4_g2_params::a.data[0], + constr_a1 = constraint_type()+mnt4_g2_params::a.data[1]; + + fp2_constraint one = {cnstr_one,cnstr_zero}, + a = {constr_a0, constr_a1}, xP = {var(component.W(0), 0, true),var(component.W(1), 0, true)}, yP = {var(component.W(2), 0, true),var(component.W(3), 0, true)}, xQ = {var(component.W(4), 0, true),var(component.W(5), 0, true)}, @@ -323,7 +334,7 @@ namespace nil { // yQ ( 2yP zPQ ( (xP - xQ)la - (yP - yQ) ) + (1 - (xP - xQ)zPQ) wPQ (2yP la - 3xP^2)) = 0 (15) C = yQ * ( 2*yP * zPQ * ((xP - xQ)*la - (yP - yQ)) + - (one - (xP - xQ)*zPQ) * wPQ *(2*yP*la - 3*xP*xP - mnt4_298::g2_type::params_type::a) + (one - (xP - xQ)*zPQ) * wPQ *(2*yP*la - 3*xP*xP - a) ); Cs.push_back(C[0]); Cs.push_back(C[1]); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/abstract_fp2.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/abstract_fp2.hpp index 7f635a77e..c797a7a6a 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/abstract_fp2.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/abstract_fp2.hpp @@ -35,7 +35,6 @@ namespace nil { namespace detail { template class abstract_fp2_element { - using non_residue = UnderlyingFieldType::non_residue; public: std::array data; @@ -48,7 +47,7 @@ namespace nil { constexpr abstract_fp2_element operator*(const abstract_fp2_element& other) { - return { data[0] * other.data[0] + non_residue * data[1] * other.data[1], + return { data[0] * other.data[0] + UnderlyingFieldType::non_residue * data[1] * other.data[1], data[0] * other.data[1] + data[1] * other.data[0]}; } constexpr abstract_fp2_element operator*(const int x) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e24e14030..ec9a1f474 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -86,6 +86,7 @@ set(PLONK_TESTS_FILES "algebra/curves/plonk/unified_addition" "algebra/curves/plonk/variable_base_endo_scalar_mul" "algebra/curves/plonk/endo_scalar" + "algebra/curves/plonk/mnt4_g2" "hashes/plonk/poseidon" "hashes/plonk/sha256" "hashes/plonk/sha512" diff --git a/test/algebra/curves/plonk/mnt4_g2.cpp b/test/algebra/curves/plonk/mnt4_g2.cpp index bc00c238c..5bfd9aa60 100644 --- a/test/algebra/curves/plonk/mnt4_g2.cpp +++ b/test/algebra/curves/plonk/mnt4_g2.cpp @@ -104,7 +104,7 @@ void test_mnt4_g2_adding(std::vector::value_type expected_res){ using curve_type = CurveType; - using BlueprintFieldType = typename curve_type::g2_type<>::field_type::base_field_type; + using BlueprintFieldType = typename curve_type::template g2_type<>::field_type::base_field_type; constexpr std::size_t WitnessColumns = 12; constexpr std::size_t PublicInputColumns = 1; @@ -129,7 +129,7 @@ void test_mnt4_g2_adding(std::vector::field_type::value_type expected_x = expected_res.X / expected_res.Z.pow(2), + typename curve_type::template g2_type<>::field_type::value_type expected_x = expected_res.X / expected_res.Z.pow(2), expected_y = expected_res.Y / expected_res.Z.pow(3); #ifdef BLUEPRINT_PLONK_PROFILING_ENABLED std::cout << "G2 addition test: " << "\n"; diff --git a/test/test_plonk_component.hpp b/test/test_plonk_component.hpp index 3711108c8..a7e0c4dfd 100644 --- a/test/test_plonk_component.hpp +++ b/test/test_plonk_component.hpp @@ -50,14 +50,14 @@ #include #include #include -//#include +#include #include #include #include #include -// #include "profiling_plonk_circuit.hpp" +#include "profiling_plonk_circuit.hpp" #include #include @@ -605,4 +605,4 @@ namespace nil { } // namespace crypto3 } // namespace nil -#endif // CRYPTO3_TEST_PLONK_COMPONENT_HPP \ No newline at end of file +#endif // CRYPTO3_TEST_PLONK_COMPONENT_HPP