diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/alt_bn128.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/alt_bn128.hpp index 251dd39d9c..2719c896a1 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/alt_bn128.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/alt_bn128.hpp @@ -65,6 +65,10 @@ namespace nil { // pairing::detail::alt_bn128_pairing_functions> pairing_policy; typedef typename policy_type::gt_field_type gt_type; + + /// Returns name of this curve. + static std::string name() + { return "alt_bn128_" + std::to_string(Version); } }; typedef alt_bn128<254> alt_bn128_254; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp index 97dbd69f80..07db4c69a5 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp @@ -61,6 +61,10 @@ namespace nil { // pairing; // constexpr static const bool has_affine_pairing = false; + + /// Returns name of this curve. + static std::string name() + { return "babyjubjub"; } }; } // namespace curves diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp index 11a10e3106..bd92201ae1 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp @@ -71,6 +71,10 @@ namespace nil { #endif typedef typename policy_type::gt_field_type gt_type; + + /// Returns name of this curve. + static std::string name() + { return "bls12_" + std::to_string(Version); } }; typedef bls12<381> bls12_381; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/curve25519.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/curve25519.hpp index 38395ffd37..b843d37d79 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/curve25519.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/curve25519.hpp @@ -48,6 +48,10 @@ namespace nil { template using g1_type = typename detail::curve25519_g1; + + /// Returns name of this curve. + static std::string name() + { return "curve25519"; } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/ed25519.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/ed25519.hpp index 9c33bf16e9..2c962e52c1 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/ed25519.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/ed25519.hpp @@ -48,6 +48,10 @@ namespace nil { template using g1_type = typename detail::curve25519_g1; + + /// Returns name of this curve. + static std::string name() + { return "ed25519"; } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/edwards.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/edwards.hpp index 78e6ff2e33..97bcc78d43 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/edwards.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/edwards.hpp @@ -69,6 +69,10 @@ namespace nil { typedef typename policy_type::gt_field_type gt_type; constexpr static const bool has_affine_pairing = false; + + /// Returns name of this curve. + static std::string name() + { return "edwards_" + std::to_string(Version); } }; typedef edwards<183> edwards_183; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/frp_v1.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/frp_v1.hpp index b0e036bd85..6b0f705802 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/frp_v1.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/frp_v1.hpp @@ -61,6 +61,10 @@ namespace nil { 0xB6B3D4C356C139EB31183D4749D423958C27D2DCAF98B70164C97A2DD98F5CFF_cppui_modular256; constexpr static const integral_type y = 0x6142E0F7C8B204911F9271F0F3ECEF8C2701C307E8E4C9E183115A1554062CFB_cppui_modular256; + + /// Returns name of this curve. + static std::string name() + { return "frp_v1_" + std::to_string(base_field_bits); } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/gost_A.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/gost_A.hpp index 50ba72822b..751a64f736 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/gost_A.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/gost_A.hpp @@ -64,6 +64,10 @@ namespace nil { constexpr static const integral_type x = 0x1_cppui_modular256; constexpr static const integral_type y = 0x8D91E471E0989CDA27DF505A453F2B7635294F2DDF23E3B122ACC99C9E9F1E14_cppui_modular256; + + /// Returns name of this curve. + static std::string name() + { return "gost_A_" + std::to_string(base_field_bits); } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp index 612659aac0..99dc5ef8ec 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp @@ -64,6 +64,10 @@ namespace nil { // pairing; // constexpr static const bool has_affine_pairing = false; + + /// Returns name of this curve. + static std::string name() + { return "jubjub"; } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/mnt4.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/mnt4.hpp index e317fb9be3..f1c71c3621 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/mnt4.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/mnt4.hpp @@ -66,6 +66,10 @@ namespace nil { typedef typename policy_type::gt_field_type gt_type; constexpr static const bool has_affine_pairing = true; + + /// Returns name of this curve. + static std::string name() + { return "mnt4_" + std::to_string(Version); } }; typedef mnt4<298> mnt4_298; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/mnt6.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/mnt6.hpp index 91d65acc0b..437426d603 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/mnt6.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/mnt6.hpp @@ -66,6 +66,10 @@ namespace nil { typedef typename policy_type::gt_field_type gt_type; constexpr static const bool has_affine_pairing = true; + + /// Returns name of this curve. + static std::string name() + { return "mnt6_" + std::to_string(Version); } }; typedef mnt6<298> mnt6_298; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/p192.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/p192.hpp index c4292008bd..21e86c572d 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/p192.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/p192.hpp @@ -46,6 +46,10 @@ namespace nil { constexpr static const integral_type p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF_cppui_modular192; + + /// Returns name of this curve. + static std::string name() + { return "p192_" + std::to_string(WordBits); } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/p224.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/p224.hpp index 325f898879..dfb4c6f90a 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/p224.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/p224.hpp @@ -44,6 +44,10 @@ namespace nil { constexpr static const integral_type p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001_cppui_modular224; + + /// Returns name of this curve. + static std::string name() + { return "p224_" + std::to_string(WordBits); } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/p384.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/p384.hpp index 488a69a954..8a323b2034 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/p384.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/p384.hpp @@ -45,6 +45,10 @@ namespace nil { constexpr static const integral_type p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF_cppui_modular384; + + /// Returns name of this curve. + static std::string name() + { return "p384_" + std::to_string(WordBits); } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/p521.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/p521.hpp index cf1b1d6ca5..f64725d3a7 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/p521.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/p521.hpp @@ -45,6 +45,10 @@ namespace nil { constexpr static const integral_type p = 0x1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_cppui_modular521; + + /// Returns name of this curve. + static std::string name() + { return "p521_" + std::to_string(WordBits); } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/pallas.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/pallas.hpp index 3301d6a3d5..e59961d0d7 100755 --- a/libs/algebra/include/nil/crypto3/algebra/curves/pallas.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/pallas.hpp @@ -48,6 +48,10 @@ namespace nil { template using g1_type = typename detail::pallas_g1; + + /// Returns name of this curve. + static std::string name() + { return "pallas"; } }; } // namespace curves } // namespace algebra diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/secp_k1.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/secp_k1.hpp index 046335ee68..350d28dc74 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/secp_k1.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/secp_k1.hpp @@ -45,6 +45,10 @@ namespace nil { template using g1_type = typename detail::secp_k1_g1; + + /// Returns name of this curve. + static std::string name() + { return "secp_k1_" + std::to_string(Version); } }; typedef secp_k1<160> secp160k1; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/secp_r1.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/secp_r1.hpp index 598db11a4f..af724dc367 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/secp_r1.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/secp_r1.hpp @@ -44,6 +44,10 @@ namespace nil { template using g1_type = typename detail::secp_r1_g1; + + /// Returns name of this curve. + static std::string name() + { return "secp_r1_" + std::to_string(Version); } }; typedef secp_r1<160> secp160r1; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/sm2p_v1.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/sm2p_v1.hpp index 31d113c40d..39525469aa 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/sm2p_v1.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/sm2p_v1.hpp @@ -61,6 +61,10 @@ namespace nil { 0x32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7_cppui_modular256; constexpr static const integral_type y = 0xBC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0_cppui_modular256; + + /// Returns name of this curve. + static std::string name() + { return "sm2p_v1_" + std::to_string(base_field_bits); } }; typedef sm2p_v1<256> sm2p256v1; diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/vesta.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/vesta.hpp index 0c7fa3276b..e7f7ac77a4 100755 --- a/libs/algebra/include/nil/crypto3/algebra/curves/vesta.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/vesta.hpp @@ -48,6 +48,10 @@ namespace nil { template using g1_type = typename detail::vesta_g1; + + /// Returns name of this curve. + static std::string name() + { return "vesta"; } }; } // namespace curves } // namespace algebra diff --git a/libs/marshalling/zk/test/placeholder_proof.cpp b/libs/marshalling/zk/test/placeholder_proof.cpp index 19bd0d9394..fa6576ced5 100644 --- a/libs/marshalling/zk/test/placeholder_proof.cpp +++ b/libs/marshalling/zk/test/placeholder_proof.cpp @@ -58,10 +58,13 @@ #include #include #include -/* + +/**/ #include +#include #include -*/ +/**/ + #include #include #include @@ -100,6 +103,9 @@ using namespace nil::crypto3; using namespace nil::crypto3::zk; using namespace nil::crypto3::zk::snark; +/// Generates random steps in range [1..max_step], until their sum will become +/// equal to 'r'. +/// Returns the sequence of generated steps. inline std::vector generate_random_step_list(const std::size_t r, const std::size_t max_step) { using dist_type = std::uniform_int_distribution; static std::random_device random_engine; @@ -122,6 +128,9 @@ inline std::vector generate_random_step_list(const std::size_t r, c return step_list; } +/// Prints bytes from range [iter_begin, iter_end) in hexadecimal format, into +/// output stream 'os'. +/// Appends end-line in case if 'endl' is true. template void print_hex_byteblob(std::ostream &os, TIter iter_begin, TIter iter_end, bool endl) { os << std::hex; @@ -134,6 +143,8 @@ void print_hex_byteblob(std::ostream &os, TIter iter_begin, TIter iter_end, bool } } +/// Prints bytes from range [proof_begin, proof_end) in hexadecimal format, +/// into file with name 'name'. template void print_placeholder_proof(ProofIterator proof_begin, ProofIterator proof_end, bool endl, const char *name) { std::ofstream out; @@ -190,6 +201,9 @@ print_curve_point(std::ostream &os, os << "] )" << std::endl; } +/// Runs placeholder proof 'proof' on specified params 'params', +/// checks that it is correct, then reads it back, and checks that the results +/// are the same. template void test_placeholder_proof(const ProofType &proof, const CommitmentParamsType& params, std::string output_file = "") { @@ -220,6 +234,7 @@ void test_placeholder_proof(const ProofType &proof, const CommitmentParamsType& BOOST_CHECK(proof == constructed_val_read); } +/// Checks if the Boost master test suite has "--print" argument specified. bool has_argv(std::string name){ bool result = false; for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc); i++) { @@ -230,6 +245,8 @@ bool has_argv(std::string name){ return result; } +/// Prints placeholder proof and its params into files "proof.bin" / "params.json", +/// which will be created in folder 'folder_name'. template void print_placeholder_proof_with_params( const typename placeholder_public_preprocessor::preprocessed_data_type &preprocessed_data, @@ -246,6 +263,7 @@ void print_placeholder_proof_with_params( ); } +/// Prints specified public input into file 'filename', until the first zero value. template void print_public_input(ColumnType &public_input, std::string filename){ std::size_t max_non_zero = 0; @@ -1190,7 +1208,7 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali print_placeholder_proof_with_params< Endianness, kzg_placeholder_params_type> (kzg_preprocessed_public_data, kzg_proof, kzg_scheme, desc, - std::string("circuit_") + typeid(curve_type).name()); + std::string("circuit_") + curve_type::name()); } else { test_placeholder_proof< Endianness, placeholder_proof> @@ -1209,48 +1227,59 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2) using TestFixtures = boost::mpl::list< - placeholder_kzg_test_fixture_v2< - algebra::curves::bls12_381, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - /* - , placeholder_kzg_test_fixture< - algebra::curves::alt_bn128_254, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - 4, true> - */ - , placeholder_kzg_test_fixture_v2< - algebra::curves::mnt4_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - , placeholder_kzg_test_fixture_v2< - algebra::curves::mnt6_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> + placeholder_kzg_test_fixture_v2< + algebra::curves::bls12_381, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> + + , placeholder_kzg_test_fixture_v2< + algebra::curves::alt_bn128_254, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> + + /*, placeholder_kzg_test_fixture< + algebra::curves::alt_bn128_254, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + 4, true>*/ + + , placeholder_kzg_test_fixture_v2< + algebra::curves::mnt4_298, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> + , placeholder_kzg_test_fixture_v2< + algebra::curves::mnt6_298, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> /*, -- Not yet implemented placeholder_kzg_test_fixture< algebra::curves::mnt6_298,