diff --git a/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_compile_time_size.hpp b/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_compile_time_size.hpp index dbe9a79d..7497225e 100644 --- a/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_compile_time_size.hpp +++ b/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_compile_time_size.hpp @@ -129,7 +129,13 @@ namespace nil { const std::shared_ptr > &D) { using namespace algorithms; - std::vector , detail::leaf_data_size_multiplier * list_size>> y_data; + std::vector< + ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + > + > y_data; y_data.resize(D->m); std::array , list_size> poly_dfs; for (std::size_t i = 0; i < list_size; i++) { @@ -139,9 +145,9 @@ namespace nil { } for (std::size_t i = 0; i < D->m; i++) { + auto& consumer = y_data[i]; for (std::size_t j = 0; j < list_size; j++) { - auto write_iter = y_data[i].begin() + detail::leaf_data_size_multiplier * j; - detail::write_field_element_to_iter(write_iter, poly_dfs[j][i]); + consumer.consume(poly_dfs[j][i]); } } @@ -271,6 +277,12 @@ namespace nil { V, transcript_type &transcript = transcript_type()) { + using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + >; + std::uint64_t idx = transcript.template int_challenge(); typename FieldType::value_type x = fri_params.D[0]->get_domain_element(1).pow(idx); @@ -294,12 +306,10 @@ namespace nil { for (std::size_t j = 0; j < m; j++) { - std::array < detail::leaf_data_type, detail::leaf_data_size_multiplier * leaf_size > leaf_data; + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { - auto write_iter = - leaf_data.begin() + detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, proof.round_proofs[i].y[polynom_index][j]); + leaf_data.consume(proof.round_proofs[i].y[polynom_index][j]); } if (!proof.round_proofs[i].p[j].validate(leaf_data)) { @@ -307,8 +317,7 @@ namespace nil { } } - std::array < detail::leaf_data_type, detail::leaf_data_size_multiplier * leaf_size > leaf_data; - + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { std::array y; @@ -333,12 +342,10 @@ namespace nil { math::polynomial interpolant = math::lagrange_interpolation(interpolation_points); - typename FieldType::value_type leaf = + typename FieldType::value_type& leaf = proof.round_proofs[i].colinear_value[polynom_index]; - field_element_type leaf_val(leaf); - auto write_iter = leaf_data.begin() + field_element_type::length() * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); if (interpolant.evaluate(alpha) != proof.round_proofs[i].colinear_value[polynom_index]) { @@ -378,6 +385,11 @@ namespace nil { U, const math::polynomial V, transcript_type &transcript = transcript_type()) { + using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + >; std::uint64_t idx = transcript.template int_challenge(); typename FieldType::value_type x = fri_params.D[0]->get_domain_element(1).pow(idx); @@ -401,15 +413,13 @@ namespace nil { } for (std::size_t j = 0; j < m; j++) { - std::array < detail::leaf_data_type, detail::leaf_data_size_multiplier * leaf_size > leaf_data; + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { - typename FieldType::value_type leaf = proof.round_proofs[i].y[polynom_index][j]; + typename FieldType::value_type& leaf = proof.round_proofs[i].y[polynom_index][j]; - auto write_iter = - leaf_data.begin() + detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); } if (!proof.round_proofs[i].p[j].validate(leaf_data)) { @@ -417,7 +427,7 @@ namespace nil { } } - std::array < detail::leaf_data_type, detail::leaf_data_size_multiplier * leaf_size > leaf_data; + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { @@ -443,11 +453,10 @@ namespace nil { math::polynomial interpolant = math::lagrange_interpolation(interpolation_points); - typename FieldType::value_type leaf = + typename FieldType::value_type& leaf = proof.round_proofs[i].colinear_value[polynom_index]; - auto write_iter = leaf_data.begin() + detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); if (interpolant.evaluate(alpha) != proof.round_proofs[i].colinear_value[polynom_index]) { @@ -485,6 +494,11 @@ namespace nil { const math::polynomial U, const math::polynomial V, transcript_type &transcript = transcript_type()) { + using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + >; std::size_t idx = transcript.template int_challenge(); typename FieldType::value_type x = fri_params.D[0]->get_domain_element(1).pow(idx); @@ -508,16 +522,14 @@ namespace nil { } for (std::size_t j = 0; j < m; j++) { - std::array < detail::leaf_data_type, detail::leaf_data_size_multiplier * leaf_size > leaf_data; + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { - typename FieldType::value_type leaf = proof.round_proofs[i].y[polynom_index][j]; + typename FieldType::value_type& leaf = proof.round_proofs[i].y[polynom_index][j]; - auto write_iter = leaf_data.begin() + - detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); } if (!proof.round_proofs[i].p[j].validate(leaf_data)) { @@ -525,7 +537,7 @@ namespace nil { } } - std::array < detail::leaf_data_type, detail::leaf_data_size_multiplier * leaf_size > leaf_data; + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { @@ -552,10 +564,9 @@ namespace nil { math::polynomial interpolant = math::lagrange_interpolation(interpolation_points); - typename FieldType::value_type leaf = proof.round_proofs[i].colinear_value[polynom_index]; + typename FieldType::value_type& leaf = proof.round_proofs[i].colinear_value[polynom_index]; - auto write_iter = leaf_data.begin() + detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); if (interpolant.evaluate(alpha) != proof.round_proofs[i].colinear_value[polynom_index]) { diff --git a/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_runtime_size.hpp b/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_runtime_size.hpp index c7d51fae..404875df 100644 --- a/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_runtime_size.hpp +++ b/include/nil/crypto3/zk/commitments/detail/polynomial/basic_batched_fri_runtime_size.hpp @@ -122,12 +122,19 @@ namespace nil { static precommitment_type precommit(const std::vector > &poly, const std::shared_ptr > &D) { + using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + >; using namespace algorithms; std::size_t leaf_size = poly.size(); - std::vector >> y_data; - y_data.resize(D->m); - std::vector > poly_dfs(leaf_size); + std::vector y_data( + D->m, + fri_field_element_consumer(leaf_size) + ); + std::vector> poly_dfs(leaf_size); for (std::size_t i = 0; i < leaf_size; i++) { poly_dfs[i].resize(poly[i].size()); std::copy(poly[i].begin(), poly[i].end(), poly_dfs[i].begin()); @@ -136,10 +143,7 @@ namespace nil { for (std::size_t i = 0; i < D->m; i++) { for (std::size_t j = 0; j < leaf_size; j++) { - y_data[i].resize(detail::leaf_data_size_multiplier * leaf_size); - - auto write_iter = y_data[i].begin() + detail::leaf_data_size_multiplier * j; - detail::write_field_element_to_iter(write_iter, poly_dfs[j][i]); + y_data[i].consume(poly_dfs[j][i]); } } @@ -274,6 +278,11 @@ namespace nil { const std::vector < math::polynomial> V, transcript_type &transcript = transcript_type()) { + using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + >; assert(U.size() == V.size()); std::size_t leaf_size = U.size(); @@ -300,16 +309,14 @@ namespace nil { } for (std::size_t j = 0; j < m; j++) { - std::vector > leaf_data(detail::leaf_data_size_multiplier * leaf_size); + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { - typename FieldType::value_type leaf = proof.round_proofs[i].y[polynom_index][j]; + typename FieldType::value_type& leaf = proof.round_proofs[i].y[polynom_index][j]; - auto write_iter = leaf_data.begin() + - detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); } if (!proof.round_proofs[i].p[j].validate(leaf_data)) { @@ -317,7 +324,7 @@ namespace nil { } } - std::vector > leaf_data(detail::leaf_data_size_multiplier * leaf_size); + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { @@ -344,10 +351,9 @@ namespace nil { math::polynomial interpolant = math::lagrange_interpolation(interpolation_points); - typename FieldType::value_type leaf = proof.round_proofs[i].colinear_value[polynom_index]; + typename FieldType::value_type& leaf = proof.round_proofs[i].colinear_value[polynom_index]; - auto write_iter = leaf_data.begin() + detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); if (interpolant.evaluate(alpha) != proof.round_proofs[i].colinear_value[polynom_index]) { @@ -387,6 +393,11 @@ namespace nil { math::polynomial> U, const math::polynomial V, transcript_type &transcript = transcript_type()) { + using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer< + FieldType, + MerkleTreeHashType, + field_element_type + >; std::size_t leaf_size = U.size(); @@ -412,16 +423,14 @@ namespace nil { } for (std::size_t j = 0; j < m; j++) { - std::vector > leaf_data(detail::leaf_data_size_multiplier * leaf_size); + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { - typename FieldType::value_type leaf = proof.round_proofs[i].y[polynom_index][j]; + typename FieldType::value_type& leaf = proof.round_proofs[i].y[polynom_index][j]; - auto write_iter = leaf_data.begin() + - detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); } if (!proof.round_proofs[i].p[j].validate(leaf_data)) { @@ -429,7 +438,7 @@ namespace nil { } } - std::vector > leaf_data(detail::leaf_data_size_multiplier * leaf_size); + fri_field_element_consumer leaf_data(leaf_size); for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) { @@ -456,10 +465,9 @@ namespace nil { math::polynomial interpolant = math::lagrange_interpolation(interpolation_points); - typename FieldType::value_type leaf = proof.round_proofs[i].colinear_value[polynom_index]; + typename FieldType::value_type& leaf = proof.round_proofs[i].colinear_value[polynom_index]; - auto write_iter = leaf_data.begin() + detail::leaf_data_size_multiplier * polynom_index; - detail::write_field_element_to_iter(write_iter, leaf); + leaf_data.consume(leaf); if (interpolant.evaluate(alpha) != proof.round_proofs[i].colinear_value[polynom_index]) {