Skip to content

Commit

Permalink
minor updates kzg commitment #113
Browse files Browse the repository at this point in the history
  • Loading branch information
tshchelovek committed Feb 3, 2023
1 parent b5fc894 commit a8df83b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 4 additions & 7 deletions include/nil/crypto3/zk/commitments/polynomial/kzg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<curve_type>(p);
g2_precomp_type A_2 = algebra::precompute_g2<curve_type>(srs.verification_key -
auto A_1 = algebra::precompute_g1<curve_type>(p);
auto A_2 = algebra::precompute_g2<curve_type>(srs.verification_key -
i * curve_type::template g2_type<>::value_type::one());
g1_precomp_type B_1 = algebra::precompute_g1<curve_type>(eval * curve_type::template g1_type<>::value_type::one() -
auto B_1 = algebra::precompute_g1<curve_type>(eval * curve_type::template g1_type<>::value_type::one() -
C_f);
g2_precomp_type B_2 = algebra::precompute_g2<curve_type>(curve_type::template g2_type<>::value_type::one());
auto B_2 = algebra::precompute_g2<curve_type>(curve_type::template g2_type<>::value_type::one());

gt_value_type gt3 = algebra::double_miller_loop<curve_type>(A_1, A_2, B_1, B_2);
gt_value_type gt_4 = algebra::final_exponentiation<curve_type>(gt3);
Expand Down
22 changes: 22 additions & 0 deletions test/commitment/kzg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<curve_type> kzg_type;

scalar_value_type alpha = algebra::random_element<scalar_field_type>();
scalar_value_type i = algebra::random_element<scalar_field_type>();
std::size_t n = 298;
const polynomial<scalar_value_type> 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()

0 comments on commit a8df83b

Please sign in to comment.