Skip to content

Commit

Permalink
Merge pull request #101 from NilFoundation/multiprecision_changes
Browse files Browse the repository at this point in the history
Changes related to creation of a modular backend in multiprecision [SyncWith: crypto3-multiprecision#70]
  • Loading branch information
martun authored May 15, 2024
2 parents 4daed96 + 5566ba1 commit 3304952
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,22 @@ namespace nil {
fill_field_element_vector_from_columns_with_padding<value_type, Endianness>(
assignments.witnesses(),
assignments.rows_amount(),
0
0u
),
fill_field_element_vector_from_columns_with_padding<value_type, Endianness>(
assignments.public_inputs(),
assignments.rows_amount(),
0
0u
),
fill_field_element_vector_from_columns_with_padding<value_type, Endianness>(
assignments.constants(),
assignments.rows_amount(),
0
0u
),
fill_field_element_vector_from_columns_with_padding<value_type, Endianness>(
assignments.selectors(),
assignments.rows_amount(),
0
0u
)
)));
}
Expand Down
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ macro(define_marshalling_test test)

endif()
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-steps=2147483647")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

endmacro()

set(TESTS_NAMES
Expand Down
4 changes: 2 additions & 2 deletions test/accumulation_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down
218 changes: 112 additions & 106 deletions test/detail/circuits.hpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/eddsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down
8 changes: 4 additions & 4 deletions test/fri_commitment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down Expand Up @@ -331,7 +331,7 @@ BOOST_FIXTURE_TEST_SUITE(marshalling_fri_proof_elements, zk::test_tools::random_

BOOST_AUTO_TEST_CASE(polynomial_test) {
using polynomial_type = math::polynomial<typename field_type::value_type>;
polynomial_type f = {1, 3, 4, 1, 5, 6, 7, 2, 8, 7, 5, 6, 1, 2, 1, 1};
polynomial_type f = {{1u, 3u, 4u, 1u, 5u, 6u, 7u, 2u, 8u, 7u, 5u, 6u, 1u, 2u, 1u, 1u}};
auto filled_polynomial = nil::crypto3::marshalling::types::fill_fri_math_polynomial<Endianness, polynomial_type>(f);

auto _f = nil::crypto3::marshalling::types::make_fri_math_polynomial<Endianness, polynomial_type>(filled_polynomial);
Expand Down Expand Up @@ -460,7 +460,7 @@ BOOST_AUTO_TEST_CASE(marshalling_fri_basic_test) {
BOOST_CHECK(D[1]->get_domain_element(1) == D[0]->get_domain_element(1).squared());

// commit
math::polynomial<typename field_type::value_type> f = {1, 3, 4, 1, 5, 6, 7, 2, 8, 7, 5, 6, 1, 2, 1, 1};
math::polynomial<typename field_type::value_type> f = {{1u, 3u, 4u, 1u, 5u, 6u, 7u, 2u, 8u, 7u, 5u, 6u, 1u, 2u, 1u, 1u}};
std::array<std::vector<math::polynomial<typename field_type::value_type>>, 1> fs;
fs[0].resize(1);
fs[0][0] = f;
Expand Down
25 changes: 12 additions & 13 deletions test/kzg_commitment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>
Expand All @@ -53,7 +53,7 @@
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt6.hpp>

#include <nil/crypto3/algebra/curves/bls12.hpp>
#include <nil/crypto3/algebra/pairing/bls12.hpp>
#include <nil/crypto3/algebra/pairing/bls12.hpp>

/*
#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
Expand Down Expand Up @@ -98,16 +98,16 @@ struct placeholder_class_test_initializer {
using kzg_scheme_type = typename zk::commitments::kzg_commitment_scheme_v2<kzg_type>;
using endianness = nil::marshalling::option::big_endian;

scalar_value_type alpha = 7;
scalar_value_type alpha = 7u;
auto params = kzg_scheme_type::create_params(8, alpha);
kzg_scheme_type kzg(params);

typename kzg_type::batch_of_polynomials_type polys(4);

polys[0].template from_coefficients<std::vector<scalar_value_type>>({{ 1, 2, 3, 4, 5, 6, 7, 8}});
polys[1].template from_coefficients<std::vector<scalar_value_type>>({{11, 12, 13, 14, 15, 16, 17, 18}});
polys[2].template from_coefficients<std::vector<scalar_value_type>>({{21, 22, 23, 24, 25, 26, 27, 28}});
polys[3].template from_coefficients<std::vector<scalar_value_type>>({{31, 32, 33, 34, 35, 36, 37, 38}});
polys[0].template from_coefficients<std::vector<scalar_value_type>>({{ 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u}});
polys[1].template from_coefficients<std::vector<scalar_value_type>>({{11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u}});
polys[2].template from_coefficients<std::vector<scalar_value_type>>({{21u, 22u, 23u, 24u, 25u, 26u, 27u, 28u}});
polys[3].template from_coefficients<std::vector<scalar_value_type>>({{31u, 32u, 33u, 34u, 35u, 36u, 37u, 38u}});


std::size_t batch_id = 0;
Expand All @@ -116,10 +116,10 @@ struct placeholder_class_test_initializer {
std::map<std::size_t, typename kzg_scheme_type::commitment_type> commitments;
commitments[batch_id] = kzg.commit(batch_id);

std::set<scalar_value_type> points_0 = {101, 2, 3};
std::set<scalar_value_type> points_1 = {102, 2, 3};
std::set<scalar_value_type> points_2 = { 1, 2, 3};
std::set<scalar_value_type> points_3 = {104, 2, 3};
std::set<scalar_value_type> points_0 = {101u, 2u, 3u};
std::set<scalar_value_type> points_1 = {102u, 2u, 3u};
std::set<scalar_value_type> points_2 = { 1u, 2u, 3u};
std::set<scalar_value_type> points_3 = {104u, 2u, 3u};
kzg.append_eval_points(batch_id, 0, points_0);
kzg.append_eval_points(batch_id, 1, points_1);
kzg.append_eval_points(batch_id, 2, points_2);
Expand Down Expand Up @@ -154,7 +154,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(placeholder_class_test, F, TestFixtures) {
BOOST_CHECK(fixture.run_test());
}


BOOST_AUTO_TEST_SUITE_END()

/*
Expand Down
14 changes: 7 additions & 7 deletions test/lpc_commitment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down Expand Up @@ -483,11 +483,11 @@ BOOST_FIXTURE_TEST_CASE(batches_num_3_test, zk::test_tools::random_test_initiali
lpc_scheme_type lpc_scheme_verifier(fri_params);

// Generate polynomials
lpc_scheme_prover.append_to_batch(0, {1, 13, 4, 1, 5, 6, 7, 2, 8, 7, 5, 6, 1, 2, 1, 1});
lpc_scheme_prover.append_to_batch(2, {0, 1});
lpc_scheme_prover.append_to_batch(2, {0, 1, 2});
lpc_scheme_prover.append_to_batch(2, {0, 1, 3});
lpc_scheme_prover.append_to_batch(3, {0});
lpc_scheme_prover.append_to_batch(0, {1u, 13u, 4u, 1u, 5u, 6u, 7u, 2u, 8u, 7u, 5u, 6u, 1u, 2u, 1u, 1u});
lpc_scheme_prover.append_to_batch(2, {0u, 1u});
lpc_scheme_prover.append_to_batch(2, {0u, 1u, 2u});
lpc_scheme_prover.append_to_batch(2, {0u, 1u, 3u});
lpc_scheme_prover.append_to_batch(3, {0u});

// Commit
std::map<std::size_t, typename lpc_type::commitment_type> commitments;
Expand Down
4 changes: 2 additions & 2 deletions test/merkle_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/algebra/type_traits.hpp>
#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/hash/block_to_field_elements_wrapper.hpp>
#include <nil/crypto3/hash/sha2.hpp>
Expand Down
4 changes: 2 additions & 2 deletions test/placeholder_common_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/pallas.hpp>
Expand Down
8 changes: 4 additions & 4 deletions test/placeholder_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>

Expand Down Expand Up @@ -250,7 +250,7 @@ template<typename ColumnType>
void print_public_input(ColumnType &public_input, std::string filename){
std::size_t max_non_zero = 0;
for(std::size_t i = 0; i < public_input.size(); i++){
if( public_input[i] != 0 ){
if( public_input[i] != 0u ){
max_non_zero = i + 1;
}
}
Expand Down Expand Up @@ -1162,7 +1162,7 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali
typename policy_type::variable_assignment_type assignments = circuit.table;

// KZG commitment scheme
typename kzg_type::field_type::value_type alpha (7);
typename kzg_type::field_type::value_type alpha(7u);
auto kzg_params = kzg_scheme_type::create_params(1 << table_rows_log, alpha);
kzg_scheme_type kzg_scheme(kzg_params);

Expand Down
4 changes: 2 additions & 2 deletions test/r1cs_gg_ppzksnark_primary_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down
4 changes: 2 additions & 2 deletions test/r1cs_gg_ppzksnark_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down
4 changes: 2 additions & 2 deletions test/r1cs_gg_ppzksnark_verification_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down
4 changes: 2 additions & 2 deletions test/sparse_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down

0 comments on commit 3304952

Please sign in to comment.