Skip to content

Commit

Permalink
Now polynomials are resized before they are sent to precommit.
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed Sep 13, 2024
1 parent c01e646 commit 9ed3962
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,13 @@ namespace nil {
FRI>::value,
bool>::type = true>
static typename FRI::precommitment_type
precommit_inner(const math::polynomial_dfs<typename FRI::field_type::value_type> &f,
precommit(const math::polynomial_dfs<typename FRI::field_type::value_type> &f,
std::shared_ptr<math::evaluation_domain<typename FRI::field_type>> D,
const std::size_t fri_step) {

if (f.size() != D->size()) {
throw std::runtime_error("Polynomial size does not match the domain size in FRI precommit.");
}

std::size_t domain_size = D->size();
std::size_t coset_size = 1 << fri_step;
std::size_t leafs_number = domain_size / coset_size;
Expand Down Expand Up @@ -452,30 +455,6 @@ namespace nil {
y_data.end());
}

template<typename FRI,
typename std::enable_if<
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type,
typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type,
FRI::m, typename FRI::grinding_type
>,
FRI>::value,
bool>::type = true>
static typename FRI::precommitment_type
precommit(const math::polynomial_dfs<typename FRI::field_type::value_type> &f,
std::shared_ptr<math::evaluation_domain<typename FRI::field_type>> D,
const std::size_t fri_step) {

if (f.size() == D->size())
return precommit_inner<FRI>(f, D, fri_step);

math::polynomial_dfs<typename FRI::field_type::value_type> f_copy = f;
f_copy.resize(D->size(), nullptr, D);
return precommit_inner<FRI>(f_copy, D, fri_step);
}

template<typename FRI,
typename std::enable_if<
std::is_base_of<
Expand All @@ -495,6 +474,10 @@ namespace nil {
math::polynomial_dfs<typename FRI::field_type::value_type> f_dfs;
f_dfs.from_coefficients(f);

if (f_dfs.size() != D->size()) {
f_dfs.resize(D->size(), nullptr, D);
}

return precommit<FRI>(f_dfs, D, fri_step);
}

Expand Down Expand Up @@ -767,8 +750,13 @@ namespace nil {
f = commitments::detail::fold_polynomial<typename FRI::field_type>(f, alpha);
}
}
if (i != fri_params.step_list.size() - 1)
precommitment = precommit<FRI>(f, fri_params.D[t], fri_params.step_list[i + 1]);
if (i != fri_params.step_list.size() - 1) {
const auto& D = fri_params.D[t];
if (f.size() != D->size()) {
f.resize(D->size(), nullptr, D);
}
precommitment = precommit<FRI>(f, D, fri_params.step_list[i + 1]);
}
}
fs.push_back(f);
if constexpr (std::is_same<math::polynomial_dfs<typename FRI::field_type::value_type>, PolynomialType>::value) {
Expand Down
9 changes: 9 additions & 0 deletions libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace nil {

commitment_type commit(std::size_t index) {
this->state_commited(index);

_trees[index] = nil::crypto3::zk::algorithms::precommit<fri_type>(
this->_polys[index], _fri_params.D[0], _fri_params.step_list.front());
return _trees[index].root();
Expand Down Expand Up @@ -204,6 +205,9 @@ namespace nil {
round_proof_type proof_eval_round_proof(const polynomial_type& sum_poly, transcript_type &transcript) {
// TODO(martun): this function belongs to FRI, not here, will move later.
// Precommit to sum_poly.
if (sum_poly.size() != _fri_params.D[0]->size()) {
sum_poly.resize(_fri_params.D[0]->size(), nullptr, _fri_params.D[0]);
}
precommitment_type sum_poly_precommitment = nil::crypto3::zk::algorithms::precommit<fri_type>(
sum_poly,
_fri_params.D[0],
Expand Down Expand Up @@ -246,6 +250,7 @@ namespace nil {
typename fri_type::proof_type commit_and_fri_proof(
const polynomial_type& combined_Q, transcript_type &transcript) {


precommitment_type combined_Q_precommitment = nil::crypto3::zk::algorithms::precommit<fri_type>(
combined_Q,
_fri_params.D[0],
Expand Down Expand Up @@ -334,6 +339,10 @@ namespace nil {
} else {
combined_Q = std::move(combined_Q_normal);
}

if (combined_Q.size() != _fri_params.D[0]->size()) {
combined_Q.resize(_fri_params.D[0]->size(), nullptr, _fri_params.D[0]);
}
return combined_Q;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ namespace nil {
_proof.eval_proof.challenge = transcript.template challenge<FieldType>();
generate_evaluation_points();

{
PROFILE_SCOPE("commitment scheme proof eval time");
_proof.eval_proof.eval_proof = _commitment_scheme.proof_eval(transcript);
}
_proof.eval_proof.eval_proof = _commitment_scheme.proof_eval(transcript);
}

return _proof;
Expand Down

0 comments on commit 9ed3962

Please sign in to comment.