Skip to content

Commit

Permalink
Synchronize with parallel-crypto3 sources
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Sep 11, 2024
1 parent e1ac7ce commit 71613cf
Show file tree
Hide file tree
Showing 30 changed files with 217 additions and 577 deletions.
5 changes: 3 additions & 2 deletions libs/containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTER

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INCLUDE include NAMESPACE ${CMAKE_WORKSPACE_NAME}::)

include(CMTest)
cm_add_test_subdirectory(test)
if (BUILD_TESTS)
add_subdirectory(test)
endif ()

if (BUILD_EXAMPLES)
add_subdirectory(example)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#ifndef CRYPTO3_MATH_MAKE_EVALUATION_DOMAIN_HPP
#define CRYPTO3_MATH_MAKE_EVALUATION_DOMAIN_HPP

#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>

#include <nil/crypto3/math/domains/evaluation_domain.hpp>
#include <nil/crypto3/math/domains/arithmetic_sequence_domain.hpp>
#include <nil/crypto3/math/domains/basic_radix2_domain.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <vector>

#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>

#include <nil/crypto3/math/detail/field_utils.hpp>

#include <nil/crypto3/math/domains/evaluation_domain.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <vector>

#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>

#include <nil/crypto3/math/domains/evaluation_domain.hpp>
#include <nil/crypto3/math/domains/basic_radix2_domain.hpp>
#include <nil/crypto3/math/domains/detail/basic_radix2_domain_aux.hpp>
Expand Down
1 change: 0 additions & 1 deletion libs/math/include/nil/crypto3/math/polynomial/basic_operations.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ namespace nil {
*/
template<typename Range>
void division(Range &q, Range &r, const Range &a, const Range &b) {

typedef
typename std::iterator_traits<decltype(std::begin(std::declval<Range>()))>::value_type value_type;

Expand Down
Empty file modified libs/math/include/nil/crypto3/math/polynomial/basis_change.hpp
100755 → 100644
Empty file.
Empty file modified libs/math/include/nil/crypto3/math/polynomial/evaluate.hpp
100755 → 100644
Empty file.
130 changes: 65 additions & 65 deletions libs/math/include/nil/crypto3/math/polynomial/polynomial.hpp

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions libs/math/include/nil/crypto3/math/polynomial/polynomial_dfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ namespace nil {
polynomial_dfs() : val(1, FieldValueType::zero()), _d(0) {
}

explicit polynomial_dfs(size_t d, size_type n) : val(n), _d(d) {
explicit polynomial_dfs(size_t d, size_type n) : val(n, FieldValueType::zero()), _d(d) {
BOOST_ASSERT_MSG(n == detail::power_of_two(n), "DFS optimal polynomial size must be a power of two");
}

explicit polynomial_dfs(size_t d, size_type n, const allocator_type& a) : val(n, a), _d(d) {
explicit polynomial_dfs(size_t d, size_type n, const allocator_type& a) : val(n, FieldValueType::zero(), a), _d(d) {
BOOST_ASSERT_MSG(n == detail::power_of_two(n), "DFS optimal polynomial size must be a power of two");
}

Expand Down Expand Up @@ -340,6 +340,7 @@ namespace nil {
return;
}
BOOST_ASSERT_MSG(_sz >= _d, "Resizing DFS polynomial to a size less than degree is prohibited: can't restore the polynomial in the future.");

if (this->degree() == 0) {
// Here we cannot write this->val.resize(_sz, this->val[0]), it will segfault.
auto value = this->val[0];
Expand Down Expand Up @@ -436,6 +437,7 @@ namespace nil {
this->resize(other.size());
}
this->_d = std::max(this->_d, other._d);

if (this->size() > other.size()) {
polynomial_dfs tmp(other);
tmp.resize(this->size());
Expand Down Expand Up @@ -512,7 +514,6 @@ namespace nil {
polynomial_dfs operator*(const polynomial_dfs& other) const {
polynomial_dfs result = *this;
result *= other;

return result;
}

Expand Down Expand Up @@ -711,7 +712,7 @@ namespace nil {
polynomial_dfs<FieldValueType, Allocator> operator*(const polynomial_dfs<FieldValueType, Allocator>& A,
const FieldValueType& B) {
polynomial_dfs<FieldValueType> result(A);
for( auto it = result.begin(); it != result.end(); it++ ){
for ( auto it = result.begin(); it != result.end(); ++it) {
*it *= B;
}
return result;
Expand All @@ -731,7 +732,7 @@ namespace nil {
const FieldValueType& B) {
polynomial_dfs<FieldValueType> result(A);
FieldValueType B_inversed = B.inversed();
for( auto it = result.begin(); it != result.end(); it++ ){
for ( auto it = result.begin(); it != result.end(); ++it) {
*it *= B_inversed;
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ namespace nil {
return *this;
}

// polynomial_view operator-() const {
void neg() {
std::transform(this->begin(), this->end(), this->begin(), std::negate<FieldValueType>());
}
Expand Down
4 changes: 2 additions & 2 deletions libs/math/include/nil/crypto3/math/polynomial/shift.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace nil {
polynomial<FieldValueType> f_shifted(f);
FieldValueType x_power = x;
for (std::size_t i = 1; i < f.size(); i++) {
f_shifted[i] = f_shifted[i] * x_power;
f_shifted[i] *= x_power;
x_power *= x;
}

Expand Down Expand Up @@ -74,4 +74,4 @@ namespace nil {
} // namespace crypto3
} // namespace nil

#endif // CRYPTO3_ZK_PLONK_REDSHIFT_POLYNOMIAL_SHIFT_HPP
#endif // CRYPTO3_ZK_PLONK_REDSHIFT_POLYNOMIAL_SHIFT_HPP
Empty file modified libs/math/include/nil/crypto3/math/polynomial/xgcd.hpp
100755 → 100644
Empty file.
2 changes: 0 additions & 2 deletions libs/math/include/nil/crypto3/math/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#include <nil/crypto3/math/polynomial/polynomial.hpp>
#include <nil/crypto3/math/polynomial/polynomial_dfs.hpp>

#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>

namespace nil {
namespace crypto3 {
namespace math {
Expand Down
11 changes: 5 additions & 6 deletions libs/math/test/polynomial_dfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_pow_eq_test) {
}};

polynomial_dfs<typename FieldType::value_type> res = a;
for (int i = 1; i < 7; ++i)
for (std::size_t i = 1; i < 7; ++i)
res *= a;

BOOST_CHECK_EQUAL(res, a.pow(7));
Expand Down Expand Up @@ -1345,7 +1345,7 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_multiplication_perf_test, *boost::unit_test:
poly4[i] *= poly;
}

for (int i = 1; i < poly4.size(); ++i) {
for (std::size_t i = 1; i < poly4.size(); ++i) {
BOOST_CHECK(poly4[i] == poly4[0]);
}

Expand All @@ -1360,19 +1360,18 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_multiplication_perf_test, *boost::unit_test:

BOOST_AUTO_TEST_CASE(polynomial_dfs_resize_perf_test, *boost::unit_test::disabled()) {
std::vector<typename FieldType::value_type> values;
size_t size = 131072 * 16;
for (int i = 0; i < size; i++) {
std::size_t size = 131072 * 16;
for (std::size_t i = 0; i < size; i++) {
values.push_back(nil::crypto3::algebra::random_element<FieldType>());
}

polynomial_dfs<typename FieldType::value_type> poly = {
size - 1, values};

auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 10; ++i) {
for (std::size_t i = 0; i < 10; ++i) {
auto poly2 = poly;
poly2.resize(8 * size);

BOOST_CHECK(poly2.size() == 8 * size);
}

Expand Down
19 changes: 11 additions & 8 deletions libs/zk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
Boost::container
Boost::log

${CMAKE_WORKSPACE_NAME}::algebra
${CMAKE_WORKSPACE_NAME}::block
${CMAKE_WORKSPACE_NAME}::math
${CMAKE_WORKSPACE_NAME}::hash
${CMAKE_WORKSPACE_NAME}::multiprecision
# Containers and math implementation could be replaced with namespace change
${CMAKE_WORKSPACE_NAME}::containers
${CMAKE_WORKSPACE_NAME}::marshalling-zk
${CMAKE_WORKSPACE_NAME}::benchmark_tools
)
${CMAKE_WORKSPACE_NAME}::math

crypto3::algebra
crypto3::block
crypto3::hash
crypto3::multiprecision
crypto3::marshalling-zk

crypto3::benchmark_tools
)

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
INCLUDE include
Expand Down
4 changes: 2 additions & 2 deletions libs/zk/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Zero-Knowledge Cryptography Schemes for =nil; Foundation's Cryptography Suite

Zero-Knowledge cryptography schemes for =nil; Foundation's cryptography suite.
SNARK-alike schemes for now. More trivial Pedersen commitment schemes, STARKs,
Zero-Knowledge cryptography schemes for =nil; Foundation's cryptography suite.
SNARK-alike schemes for now. More trivial Pedersen commitment schemes, STARKs,
IOP-based SNARKs, Bulletproofs etc in future.

[![Run tests](https://github.com/NilFoundation/crypto3-zk/actions/workflows/run_tests.yml/badge.svg)](https://github.com/NilFoundation/crypto3-zk/actions/workflows/run_tests.yml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace nil {
}

// For the last round it's final_polynomial's values

// Values for the next round.
polynomial_values_type y;

Expand Down Expand Up @@ -441,6 +441,7 @@ namespace nil {
) {
PROFILE_SCOPE("Basic FRI Precommit time");

// Resize uses low level thread pool, so we need to use the high level one here.
for (std::size_t i = 0; i < poly.size(); ++i) {
if (poly[i].size() != D->size()) {
poly[i].resize(D->size(), nullptr, D);
Expand Down Expand Up @@ -743,6 +744,7 @@ namespace nil {
}
}
}

return std::move(g_coeffs);
}

Expand Down Expand Up @@ -911,6 +913,7 @@ namespace nil {
return std::move(round_proofs);
}


template<typename FRI, typename PolynomialType>
static std::vector<typename FRI::query_proof_type>
query_phase(
Expand Down Expand Up @@ -957,9 +960,11 @@ namespace nil {
typename FRI::query_proof_type query_proof = {std::move(initial_proof), std::move(round_proofs)};
query_proofs[query_id] = std::move(query_proof);
}

return std::move(query_proofs);
}


template<typename FRI, typename PolynomialType,
typename std::enable_if<
std::is_base_of<
Expand All @@ -977,6 +982,7 @@ namespace nil {
const typename FRI::params_type &fri_params,
typename FRI::transcript_type &transcript
) {
PROFILE_SCOPE("Basic FRI proof_eval time");
typename FRI::proof_type proof;

BOOST_ASSERT(check_step_list<FRI>(fri_params));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ namespace nil {
return evaluator.evaluate();
}

typename VariableType::assignment_type evaluate(detail::plonk_evaluation_map<VariableType> &assignments) const {
typename VariableType::assignment_type
evaluate(detail::plonk_evaluation_map<VariableType> &assignments) const {

math::expression_evaluator<VariableType> evaluator(
*this,
[&assignments](const VariableType &var) -> const typename VariableType::assignment_type& {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ namespace nil {
}
}
for (const auto& table : _lookup_tables) {
for (std::size_t i = 0; i < table.lookup_options.size(); ++i) {
for( const auto &lookup_options: table.lookup_options ){
// +3 because now any lookup option is lookup_column * lookup_selector * (1-q_last-q_blind) -- three polynomials degree rows_amount-1
if( lookup_chunk + 3 >= max_quotient_chunks ){
lookup_parts.push_back(lookup_part);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace nil {
const std::vector<std::size_t> &constant_columns_ids,
std::size_t usable_rows
){
// std::cout << "Packing lookup tables" << std::endl;
// std::cout << "Usable rows before: " << usable_rows << std::endl;
std::size_t usable_rows_after = usable_rows;

Expand Down
Loading

0 comments on commit 71613cf

Please sign in to comment.