From bc2b5d54910823a016db01f1a6516a40a0ad4163 Mon Sep 17 00:00:00 2001 From: Martun Karapetyan Date: Sat, 14 Sep 2024 17:43:31 +0400 Subject: [PATCH] Use points map for faster search over the LPC points. --- .../nil/crypto3/zk/commitments/polynomial/lpc.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp b/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp index f93adac478..95e0d99733 100644 --- a/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp +++ b/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp @@ -278,6 +278,8 @@ namespace nil { polynomial_type prepare_combined_Q( const typename field_type::value_type& theta, std::size_t starting_power = 0) { + this->build_points_map(); + typename field_type::value_type theta_acc = theta.pow(starting_power); polynomial_type combined_Q; math::polynomial V; @@ -290,8 +292,10 @@ namespace nil { math::polynomial Q_normal; for (std::size_t i: this->_z.get_batches()) { for (std::size_t j = 0; j < this->_z.get_batch_size(i); j++) { - auto it = std::find(this->_points[i][j].begin(), this->_points[i][j].end(), point); - if( it == this->_points[i][j].end()) continue; + auto iter = this->_points_map[i][j].find(point); + if (iter == this->_points_map[i][j].end()) + continue; + math::polynomial g_normal; if constexpr(std::is_same, PolynomialType>::value ) { g_normal = math::polynomial(this->_polys[i][j].coefficients()); @@ -300,7 +304,7 @@ namespace nil { } g_normal *= theta_acc; Q_normal += g_normal; - Q_normal -= this->_z.get(i, j, it - this->_points[i][j].begin()) * theta_acc; + Q_normal -= this->_z.get(i, j, iter->second) * theta_acc; theta_acc *= theta; } }