Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 0f6ec02

Browse files
tshchelovekmartun
authored andcommitted
minor updates kzg commitment #113
1 parent 3480371 commit 0f6ec02

File tree

2 files changed

+26
-7
lines changed
  • include/nil/crypto3/zk/commitments/polynomial
  • test/commitment

2 files changed

+26
-7
lines changed

include/nil/crypto3/zk/commitments/polynomial/kzg.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,13 @@ namespace nil {
121121
scalar_value_type i,
122122
scalar_value_type eval,
123123
proof_type p) {
124-
125-
using g1_precomp_type = typename pairing_policy::g1_precomputed_type;
126-
using g2_precomp_type = typename pairing_policy::g2_precomputed_type;
127124

128-
g1_precomp_type A_1 = algebra::precompute_g1<curve_type>(p);
129-
g2_precomp_type A_2 = algebra::precompute_g2<curve_type>(srs.verification_key -
125+
auto A_1 = algebra::precompute_g1<curve_type>(p);
126+
auto A_2 = algebra::precompute_g2<curve_type>(srs.verification_key -
130127
i * curve_type::template g2_type<>::value_type::one());
131-
g1_precomp_type B_1 = algebra::precompute_g1<curve_type>(eval * curve_type::template g1_type<>::value_type::one() -
128+
auto B_1 = algebra::precompute_g1<curve_type>(eval * curve_type::template g1_type<>::value_type::one() -
132129
C_f);
133-
g2_precomp_type B_2 = algebra::precompute_g2<curve_type>(curve_type::template g2_type<>::value_type::one());
130+
auto B_2 = algebra::precompute_g2<curve_type>(curve_type::template g2_type<>::value_type::one());
134131

135132
gt_value_type gt3 = algebra::double_miller_loop<curve_type>(A_1, A_2, B_1, B_2);
136133
gt_value_type gt_4 = algebra::final_exponentiation<curve_type>(gt3);

test/commitment/kzg.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,26 @@ BOOST_AUTO_TEST_CASE(kzg_basic_test) {
7979
BOOST_CHECK(kzg_type::verify_eval(srs, commit, i, eval, proof));
8080
}
8181

82+
BOOST_AUTO_TEST_CASE(kzg_random_test) {
83+
84+
typedef algebra::curves::mnt4<298> curve_type;
85+
typedef typename curve_type::base_field_type::value_type base_value_type;
86+
typedef typename curve_type::base_field_type base_field_type;
87+
typedef typename curve_type::scalar_field_type scalar_field_type;
88+
typedef typename curve_type::scalar_field_type::value_type scalar_value_type;
89+
typedef zk::commitments::kzg_commitment<curve_type> kzg_type;
90+
91+
scalar_value_type alpha = algebra::random_element<scalar_field_type>();
92+
scalar_value_type i = algebra::random_element<scalar_field_type>();
93+
std::size_t n = 298;
94+
const polynomial<scalar_value_type> f = {-1, 1, 2, 3, 5, -15};
95+
96+
auto srs = kzg_type::setup({alpha, n});
97+
auto commit = kzg_type::commit(srs, f);
98+
auto eval = f.evaluate(i);
99+
auto proof = kzg_type::proof_eval(srs, i, f);
100+
101+
BOOST_CHECK(kzg_type::verify_eval(srs, commit, i, eval, proof));
102+
}
103+
82104
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)