From 8df1db95235197a393660b73d21f34f6215cc054 Mon Sep 17 00:00:00 2001 From: x-mass <36629999+x-mass@users.noreply.github.com> Date: Fri, 17 May 2024 09:39:44 +0000 Subject: [PATCH] Use polynomial_sum instead of naive sum --- .../plonk/placeholder/lookup_argument.hpp | 18 +++++++----------- .../snark/systems/plonk/placeholder/prover.hpp | 8 ++++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp index 969bf547..fbe1c104 100644 --- a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp +++ b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp @@ -278,18 +278,14 @@ namespace nil { F_dfs[3] = zero_polynomial; - for (std::size_t i = 1; i < sorted.size(); i++) { - typename FieldType::value_type alpha = transcript.template challenge(); - math::polynomial_dfs sorted_shifted = math::polynomial_shift(sorted[i-1], preprocessed_data.common_data.desc.usable_rows_amount , basic_domain->m); - F_dfs[3] += alpha * preprocessed_data.common_data.lagrange_0 * (sorted[i] - sorted_shifted); + std::vector> F_dfs_3_parts(std::next(sorted.begin(), 1), sorted.end()); + for (std::size_t i = 0; i < F_dfs_3_parts.size(); i++) { + typename FieldType::value_type alpha = transcript.template challenge(); + math::polynomial_dfs sorted_shifted = math::polynomial_shift(sorted[i], preprocessed_data.common_data.desc.usable_rows_amount , basic_domain->m); + F_dfs_3_parts[i] -= sorted_shifted; + F_dfs_3_parts[i] *= alpha * preprocessed_data.common_data.lagrange_0; } - -/* for( std::size_t i = 0; i < basic_domain->m; i++){ - BOOST_CHECK( F_dfs[0].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() ); - BOOST_CHECK( F_dfs[1].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() ); - BOOST_CHECK( F_dfs[2].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() ); - BOOST_CHECK( F_dfs[3].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() ); - }*/ + F_dfs[3] = polynomial_sum(std::move(F_dfs_3_parts)); return { std::move(F_dfs), diff --git a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp index 5b055e25..d53bc32f 100644 --- a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp +++ b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp @@ -265,14 +265,14 @@ namespace nil { transcript.template challenges(); // 7.2. Compute F_consolidated - polynomial_dfs_type F_consolidated_dfs( - 0, _F_dfs[0].size(), FieldType::value_type::zero()); - for (std::size_t i = 0; i < f_parts; i++) { + std::vector F_consolidated_dfs_parts(_F_dfs.begin(), _F_dfs.end()); + for (std::size_t i = 0; i < F_consolidated_dfs_parts.size(); ++i) { if (_F_dfs[i].is_zero()) { continue; } - F_consolidated_dfs += alphas[i] * _F_dfs[i]; + F_consolidated_dfs_parts[i] *= alphas[i]; } + polynomial_dfs_type F_consolidated_dfs = polynomial_sum(std::move(F_consolidated_dfs_parts)); polynomial_type F_consolidated_normal(F_consolidated_dfs.coefficients());