diff --git a/include/nil/crypto3/zk/commitments/polynomial/kzg.hpp b/include/nil/crypto3/zk/commitments/polynomial/kzg.hpp index a2bda671c..c55d5bed1 100644 --- a/include/nil/crypto3/zk/commitments/polynomial/kzg.hpp +++ b/include/nil/crypto3/zk/commitments/polynomial/kzg.hpp @@ -121,16 +121,13 @@ namespace nil { scalar_value_type i, scalar_value_type eval, proof_type p) { - - using g1_precomp_type = typename pairing_policy::g1_precomputed_type; - using g2_precomp_type = typename pairing_policy::g2_precomputed_type; - g1_precomp_type A_1 = algebra::precompute_g1(p); - g2_precomp_type A_2 = algebra::precompute_g2(srs.verification_key - + auto A_1 = algebra::precompute_g1(p); + auto A_2 = algebra::precompute_g2(srs.verification_key - i * curve_type::template g2_type<>::value_type::one()); - g1_precomp_type B_1 = algebra::precompute_g1(eval * curve_type::template g1_type<>::value_type::one() - + auto B_1 = algebra::precompute_g1(eval * curve_type::template g1_type<>::value_type::one() - C_f); - g2_precomp_type B_2 = algebra::precompute_g2(curve_type::template g2_type<>::value_type::one()); + auto B_2 = algebra::precompute_g2(curve_type::template g2_type<>::value_type::one()); gt_value_type gt3 = algebra::double_miller_loop(A_1, A_2, B_1, B_2); gt_value_type gt_4 = algebra::final_exponentiation(gt3); diff --git a/test/commitment/kzg.cpp b/test/commitment/kzg.cpp index 412eb49ff..e36abaa16 100644 --- a/test/commitment/kzg.cpp +++ b/test/commitment/kzg.cpp @@ -79,4 +79,26 @@ BOOST_AUTO_TEST_CASE(kzg_basic_test) { BOOST_CHECK(kzg_type::verify_eval(srs, commit, i, eval, proof)); } +BOOST_AUTO_TEST_CASE(kzg_random_test) { + + typedef algebra::curves::mnt4<298> curve_type; + typedef typename curve_type::base_field_type::value_type base_value_type; + typedef typename curve_type::base_field_type base_field_type; + typedef typename curve_type::scalar_field_type scalar_field_type; + typedef typename curve_type::scalar_field_type::value_type scalar_value_type; + typedef zk::commitments::kzg_commitment kzg_type; + + scalar_value_type alpha = algebra::random_element(); + scalar_value_type i = algebra::random_element(); + std::size_t n = 298; + const polynomial f = {-1, 1, 2, 3, 5, -15}; + + auto srs = kzg_type::setup({alpha, n}); + auto commit = kzg_type::commit(srs, f); + auto eval = f.evaluate(i); + auto proof = kzg_type::proof_eval(srs, i, f); + + BOOST_CHECK(kzg_type::verify_eval(srs, commit, i, eval, proof)); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file