Skip to content

Commit

Permalink
minor updates #113
Browse files Browse the repository at this point in the history
  • Loading branch information
tshchelovek authored and martun committed Aug 10, 2023
1 parent d7ea612 commit fed92c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions include/nil/crypto3/zk/commitments/polynomial/kzg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
#include <nil/crypto3/algebra/multiexp/policies.hpp>
#include <nil/crypto3/algebra/pairing/pairing_policy.hpp>

using namespace nil::crypto3::math;

#include <nil/crypto3/math/polynomial/polynomial.hpp>

using namespace nil::crypto3;
using namespace nil::crypto3::math;

namespace nil {
namespace crypto3 {
namespace zk {
Expand All @@ -73,7 +74,7 @@ namespace nil {
scalar_value_type alpha; //secret key
kzg_params_type(std::size_t _n, scalar_value_type _alpha) : n(_n), alpha(_alpha) {}
kzg_params_type(std::size_t _n) {
alpha = scalar_value_type::random_element();
alpha = algebra::random_element<typename curve_type::scalar_field_type>();
n = _n;
}
};
Expand Down Expand Up @@ -101,7 +102,7 @@ namespace nil {

static commitment_type commit(const srs_type &srs,
const polynomial<scalar_value_type> &f) {
// assert(f.size() <= srs.commitment_key.size());
assert(f.size() <= srs.commitment_key.size());
return algebra::multiexp<multiexp_method>(srs.commitment_key.begin(),
srs.commitment_key.begin() + f.size(), f.begin(), f.end(), 1);
}
Expand Down
9 changes: 5 additions & 4 deletions test/commitment/kzg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ BOOST_AUTO_TEST_CASE(kzg_random_test) {
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({n, alpha});
auto kzg_params = kzg_type::kzg_params_type(n);
auto srs = kzg_type::setup(kzg_params);
auto commit = kzg_type::commit(srs, f);
auto eval = f.evaluate(i);
auto proof = kzg_type::proof_eval(srs, f, i, eval);
Expand Down Expand Up @@ -232,7 +232,6 @@ BOOST_AUTO_TEST_CASE(kzg_batched_random_test) {
typedef typename curve_type::scalar_field_type::value_type scalar_value_type;
typedef zk::commitments::kzg_batched_commitment<curve_type> kzg_type;

scalar_value_type alpha = algebra::random_element<scalar_field_type>();
std::size_t n = 298;
const std::vector<polynomial<scalar_value_type>> f0{{
{{1, 2, 3, 4, 5, 6, 7, 8}},
Expand All @@ -259,7 +258,9 @@ BOOST_AUTO_TEST_CASE(kzg_batched_random_test) {
}
auto evals = kzg_type::evaluate_polynomials(polys, zs);

auto srs = kzg_type::setup({n, alpha});
auto kzg_params = kzg_type::kzg_params_type(n);
auto alpha = kzg_params.alpha;
auto srs = kzg_type::setup(kzg_params);

std::vector<scalar_value_type> gammas;
for (std::size_t i = 0; i < num_polys; ++i) {
Expand Down

0 comments on commit fed92c4

Please sign in to comment.