Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 71613cf

Browse files
committed
Synchronize with parallel-crypto3 sources
1 parent e1ac7ce commit 71613cf

30 files changed

+217
-577
lines changed

libs/containers/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTER
5757

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

60-
include(CMTest)
61-
cm_add_test_subdirectory(test)
60+
if (BUILD_TESTS)
61+
add_subdirectory(test)
62+
endif ()
6263

6364
if (BUILD_EXAMPLES)
6465
add_subdirectory(example)

libs/math/include/nil/crypto3/math/algorithms/make_evaluation_domain.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#ifndef CRYPTO3_MATH_MAKE_EVALUATION_DOMAIN_HPP
2727
#define CRYPTO3_MATH_MAKE_EVALUATION_DOMAIN_HPP
2828

29-
#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>
30-
3129
#include <nil/crypto3/math/domains/evaluation_domain.hpp>
3230
#include <nil/crypto3/math/domains/arithmetic_sequence_domain.hpp>
3331
#include <nil/crypto3/math/domains/basic_radix2_domain.hpp>

libs/math/include/nil/crypto3/math/domains/basic_radix2_domain.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
#include <vector>
3030

31-
#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>
32-
3331
#include <nil/crypto3/math/detail/field_utils.hpp>
3432

3533
#include <nil/crypto3/math/domains/evaluation_domain.hpp>

libs/math/include/nil/crypto3/math/domains/extended_radix2_domain.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
#include <vector>
3030

31-
#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>
32-
3331
#include <nil/crypto3/math/domains/evaluation_domain.hpp>
3432
#include <nil/crypto3/math/domains/basic_radix2_domain.hpp>
3533
#include <nil/crypto3/math/domains/detail/basic_radix2_domain_aux.hpp>

libs/math/include/nil/crypto3/math/polynomial/basic_operations.hpp

100755100644
-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ namespace nil {
308308
*/
309309
template<typename Range>
310310
void division(Range &q, Range &r, const Range &a, const Range &b) {
311-
312311
typedef
313312
typename std::iterator_traits<decltype(std::begin(std::declval<Range>()))>::value_type value_type;
314313

libs/math/include/nil/crypto3/math/polynomial/basis_change.hpp

100755100644
File mode changed.

libs/math/include/nil/crypto3/math/polynomial/evaluate.hpp

100755100644
File mode changed.

libs/math/include/nil/crypto3/math/polynomial/polynomial.hpp

+65-65
Large diffs are not rendered by default.

libs/math/include/nil/crypto3/math/polynomial/polynomial_dfs.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ namespace nil {
7373
polynomial_dfs() : val(1, FieldValueType::zero()), _d(0) {
7474
}
7575

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

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

@@ -340,6 +340,7 @@ namespace nil {
340340
return;
341341
}
342342
BOOST_ASSERT_MSG(_sz >= _d, "Resizing DFS polynomial to a size less than degree is prohibited: can't restore the polynomial in the future.");
343+
343344
if (this->degree() == 0) {
344345
// Here we cannot write this->val.resize(_sz, this->val[0]), it will segfault.
345346
auto value = this->val[0];
@@ -436,6 +437,7 @@ namespace nil {
436437
this->resize(other.size());
437438
}
438439
this->_d = std::max(this->_d, other._d);
440+
439441
if (this->size() > other.size()) {
440442
polynomial_dfs tmp(other);
441443
tmp.resize(this->size());
@@ -512,7 +514,6 @@ namespace nil {
512514
polynomial_dfs operator*(const polynomial_dfs& other) const {
513515
polynomial_dfs result = *this;
514516
result *= other;
515-
516517
return result;
517518
}
518519

@@ -711,7 +712,7 @@ namespace nil {
711712
polynomial_dfs<FieldValueType, Allocator> operator*(const polynomial_dfs<FieldValueType, Allocator>& A,
712713
const FieldValueType& B) {
713714
polynomial_dfs<FieldValueType> result(A);
714-
for( auto it = result.begin(); it != result.end(); it++ ){
715+
for ( auto it = result.begin(); it != result.end(); ++it) {
715716
*it *= B;
716717
}
717718
return result;
@@ -731,7 +732,7 @@ namespace nil {
731732
const FieldValueType& B) {
732733
polynomial_dfs<FieldValueType> result(A);
733734
FieldValueType B_inversed = B.inversed();
734-
for( auto it = result.begin(); it != result.end(); it++ ){
735+
for ( auto it = result.begin(); it != result.end(); ++it) {
735736
*it *= B_inversed;
736737
}
737738
return result;

libs/math/include/nil/crypto3/math/polynomial/polynomial_view.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ namespace nil {
350350
return *this;
351351
}
352352

353-
// polynomial_view operator-() const {
354353
void neg() {
355354
std::transform(this->begin(), this->end(), this->begin(), std::negate<FieldValueType>());
356355
}

libs/math/include/nil/crypto3/math/polynomial/shift.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace nil {
3939
polynomial<FieldValueType> f_shifted(f);
4040
FieldValueType x_power = x;
4141
for (std::size_t i = 1; i < f.size(); i++) {
42-
f_shifted[i] = f_shifted[i] * x_power;
42+
f_shifted[i] *= x_power;
4343
x_power *= x;
4444
}
4545

@@ -74,4 +74,4 @@ namespace nil {
7474
} // namespace crypto3
7575
} // namespace nil
7676

77-
#endif // CRYPTO3_ZK_PLONK_REDSHIFT_POLYNOMIAL_SHIFT_HPP
77+
#endif // CRYPTO3_ZK_PLONK_REDSHIFT_POLYNOMIAL_SHIFT_HPP

libs/math/include/nil/crypto3/math/polynomial/xgcd.hpp

100755100644
File mode changed.

libs/math/include/nil/crypto3/math/type_traits.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#include <nil/crypto3/math/polynomial/polynomial.hpp>
4040
#include <nil/crypto3/math/polynomial/polynomial_dfs.hpp>
4141

42-
#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>
43-
4442
namespace nil {
4543
namespace crypto3 {
4644
namespace math {

libs/math/test/polynomial_dfs.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_pow_eq_test) {
12461246
}};
12471247

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

12521252
BOOST_CHECK_EQUAL(res, a.pow(7));
@@ -1345,7 +1345,7 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_multiplication_perf_test, *boost::unit_test:
13451345
poly4[i] *= poly;
13461346
}
13471347

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

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

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

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

13711371
auto start = std::chrono::high_resolution_clock::now();
1372-
for (int i = 0; i < 10; ++i) {
1372+
for (std::size_t i = 0; i < 10; ++i) {
13731373
auto poly2 = poly;
13741374
poly2.resize(8 * size);
1375-
13761375
BOOST_CHECK(poly2.size() == 8 * size);
13771376
}
13781377

libs/zk/CMakeLists.txt

+11-8
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
3939
Boost::container
4040
Boost::log
4141

42-
${CMAKE_WORKSPACE_NAME}::algebra
43-
${CMAKE_WORKSPACE_NAME}::block
44-
${CMAKE_WORKSPACE_NAME}::math
45-
${CMAKE_WORKSPACE_NAME}::hash
46-
${CMAKE_WORKSPACE_NAME}::multiprecision
42+
# Containers and math implementation could be replaced with namespace change
4743
${CMAKE_WORKSPACE_NAME}::containers
48-
${CMAKE_WORKSPACE_NAME}::marshalling-zk
49-
${CMAKE_WORKSPACE_NAME}::benchmark_tools
50-
)
44+
${CMAKE_WORKSPACE_NAME}::math
45+
46+
crypto3::algebra
47+
crypto3::block
48+
crypto3::hash
49+
crypto3::multiprecision
50+
crypto3::marshalling-zk
51+
52+
crypto3::benchmark_tools
53+
)
5154

5255
cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
5356
INCLUDE include

libs/zk/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Zero-Knowledge Cryptography Schemes for =nil; Foundation's Cryptography Suite
22

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

77
[![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)

libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ namespace nil {
235235
}
236236

237237
// For the last round it's final_polynomial's values
238-
238+
239239
// Values for the next round.
240240
polynomial_values_type y;
241241

@@ -441,6 +441,7 @@ namespace nil {
441441
) {
442442
PROFILE_SCOPE("Basic FRI Precommit time");
443443

444+
// Resize uses low level thread pool, so we need to use the high level one here.
444445
for (std::size_t i = 0; i < poly.size(); ++i) {
445446
if (poly[i].size() != D->size()) {
446447
poly[i].resize(D->size(), nullptr, D);
@@ -743,6 +744,7 @@ namespace nil {
743744
}
744745
}
745746
}
747+
746748
return std::move(g_coeffs);
747749
}
748750

@@ -911,6 +913,7 @@ namespace nil {
911913
return std::move(round_proofs);
912914
}
913915

916+
914917
template<typename FRI, typename PolynomialType>
915918
static std::vector<typename FRI::query_proof_type>
916919
query_phase(
@@ -957,9 +960,11 @@ namespace nil {
957960
typename FRI::query_proof_type query_proof = {std::move(initial_proof), std::move(round_proofs)};
958961
query_proofs[query_id] = std::move(query_proof);
959962
}
963+
960964
return std::move(query_proofs);
961965
}
962966

967+
963968
template<typename FRI, typename PolynomialType,
964969
typename std::enable_if<
965970
std::is_base_of<
@@ -977,6 +982,7 @@ namespace nil {
977982
const typename FRI::params_type &fri_params,
978983
typename FRI::transcript_type &transcript
979984
) {
985+
PROFILE_SCOPE("Basic FRI proof_eval time");
980986
typename FRI::proof_type proof;
981987

982988
BOOST_ASSERT(check_step_list<FRI>(fri_params));

libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ namespace nil {
180180
return evaluator.evaluate();
181181
}
182182

183-
typename VariableType::assignment_type evaluate(detail::plonk_evaluation_map<VariableType> &assignments) const {
183+
typename VariableType::assignment_type
184+
evaluate(detail::plonk_evaluation_map<VariableType> &assignments) const {
185+
184186
math::expression_evaluator<VariableType> evaluator(
185187
*this,
186188
[&assignments](const VariableType &var) -> const typename VariableType::assignment_type& {

libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ namespace nil {
290290
}
291291
}
292292
for (const auto& table : _lookup_tables) {
293-
for (std::size_t i = 0; i < table.lookup_options.size(); ++i) {
293+
for( const auto &lookup_options: table.lookup_options ){
294294
// +3 because now any lookup option is lookup_column * lookup_selector * (1-q_last-q_blind) -- three polynomials degree rows_amount-1
295295
if( lookup_chunk + 3 >= max_quotient_chunks ){
296296
lookup_parts.push_back(lookup_part);

libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/lookup_table_definition.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ namespace nil {
134134
const std::vector<std::size_t> &constant_columns_ids,
135135
std::size_t usable_rows
136136
){
137+
// std::cout << "Packing lookup tables" << std::endl;
137138
// std::cout << "Usable rows before: " << usable_rows << std::endl;
138139
std::size_t usable_rows_after = usable_rows;
139140

0 commit comments

Comments
 (0)