From 8c205ff4d60740eb31a1f625ae1d40599c5183ac Mon Sep 17 00:00:00 2001 From: "e.tatuzova" Date: Thu, 3 Oct 2024 15:25:12 +0400 Subject: [PATCH 1/2] random_test_initializer moved to crypto3/test_tools #52 --- .../libs/marshalling/zk/test/CMakeLists.txt | 1 + .../marshalling/zk/test/fri_commitment.cpp | 6 +- .../marshalling/zk/test/lpc_commitment.cpp | 6 +- .../zk/test/placeholder_common_data.cpp | 2 +- .../placeholder_preprocessed_public_data.cpp | 2 +- .../marshalling/zk/test/placeholder_proof.cpp | 2 +- .../zk/test/plonk_assignment_table.cpp | 12 +-- .../zk/test/plonk_constraint_system.cpp | 2 +- .../marshalling/zk/test/polys_evaluator.cpp | 2 +- .../zk/test/random_test_data_generation.hpp | 2 +- crypto3/libs/zk/test/CMakeLists.txt | 1 + .../zk/test_tools/random_test_initializer.hpp | 98 ------------------- .../placeholder/placeholder_circuits.cpp | 2 +- .../plonk/placeholder/placeholder_curves.cpp | 2 +- .../placeholder/placeholder_gate_argument.cpp | 2 +- .../placeholder/placeholder_goldilocks.cpp | 2 +- .../plonk/placeholder/placeholder_hashes.cpp | 2 +- .../plonk/placeholder/placeholder_kzg.cpp | 2 +- .../placeholder_lookup_argument.cpp | 2 +- .../placeholder_permutation_argument.cpp | 2 +- ...placeholder_quotient_polynomial_chunks.cpp | 2 +- .../test_tools/random_test_initializer.hpp | 96 ++++++++++++++++++ 22 files changed, 125 insertions(+), 125 deletions(-) delete mode 100644 crypto3/libs/zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp create mode 100644 crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp diff --git a/crypto3/libs/marshalling/zk/test/CMakeLists.txt b/crypto3/libs/marshalling/zk/test/CMakeLists.txt index fba9aa60d3..f5fa15e7b2 100644 --- a/crypto3/libs/marshalling/zk/test/CMakeLists.txt +++ b/crypto3/libs/marshalling/zk/test/CMakeLists.txt @@ -32,6 +32,7 @@ macro(define_marshalling_test test) cm_test(NAME ${full_test_name} SOURCES ${test}.cpp) target_include_directories(marshalling_zk_${name}_test PRIVATE + "$" "$" "$" diff --git a/crypto3/libs/marshalling/zk/test/fri_commitment.cpp b/crypto3/libs/marshalling/zk/test/fri_commitment.cpp index 027f3100b8..bbc62cf0c9 100644 --- a/crypto3/libs/marshalling/zk/test/fri_commitment.cpp +++ b/crypto3/libs/marshalling/zk/test/fri_commitment.cpp @@ -67,7 +67,7 @@ #include #include -#include +#include #include #include "random_test_data_generation.hpp" @@ -112,7 +112,7 @@ void test_fri_proof(typename FRI::proof_type &proof, typename nil::crypto3::mars BOOST_CHECK(proof == constructed_val_read); } -BOOST_FIXTURE_TEST_SUITE(marshalling_fri_proof_elements, zk::test_tools::random_test_initializer::scalar_field_type>) +BOOST_FIXTURE_TEST_SUITE(marshalling_fri_proof_elements, test_tools::random_test_initializer::scalar_field_type>) static constexpr std::size_t lambda = 40; static constexpr std::size_t m = 2; @@ -218,7 +218,7 @@ BOOST_FIXTURE_TEST_SUITE(marshalling_fri_proof_elements, zk::test_tools::random_ BOOST_AUTO_TEST_SUITE_END() -BOOST_FIXTURE_TEST_SUITE(marshalling_real_fri_proofs, zk::test_tools::random_test_initializer) +BOOST_FIXTURE_TEST_SUITE(marshalling_real_fri_proofs, test_tools::random_test_initializer) using Endianness = nil::marshalling::option::big_endian; BOOST_AUTO_TEST_CASE(marshalling_fri_basic_test) { diff --git a/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp b/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp index 01fe347716..a951089cc2 100644 --- a/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp +++ b/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp @@ -170,7 +170,7 @@ BOOST_AUTO_TEST_SUITE(marshalling_random) using LPC = typename nil::crypto3::zk::commitments::batched_list_polynomial_commitment; using lpc_scheme_type = nil::crypto3::zk::commitments::lpc_commitment_scheme>; -BOOST_FIXTURE_TEST_CASE(lpc_proof_test, zk::test_tools::random_test_initializer) { +BOOST_FIXTURE_TEST_CASE(lpc_proof_test, test_tools::random_test_initializer) { typename FRI::params_type fri_params(1, r + 1, lambda, 4); @@ -185,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE(lpc_proof_test, zk::test_tools::random_test_initializer< test_lpc_proof(proof, fri_params); } -BOOST_FIXTURE_TEST_CASE(lpc_aggregated_proof_test, zk::test_tools::random_test_initializer) { +BOOST_FIXTURE_TEST_CASE(lpc_aggregated_proof_test, test_tools::random_test_initializer) { typename FRI::params_type fri_params(1, r + 1, lambda, 4); auto proof = generate_random_lpc_aggregated_proof( @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_SUITE(marshalling_real) using transcript_hash_type = nil::crypto3::hashes::keccak_1600<256>; using merkle_tree_type = typename containers::merkle_tree; -BOOST_FIXTURE_TEST_CASE(batches_num_3_test, zk::test_tools::random_test_initializer){ +BOOST_FIXTURE_TEST_CASE(batches_num_3_test, test_tools::random_test_initializer){ // Setup types. constexpr static const std::size_t lambda = 40; constexpr static const std::size_t k = 1; diff --git a/crypto3/libs/marshalling/zk/test/placeholder_common_data.cpp b/crypto3/libs/marshalling/zk/test/placeholder_common_data.cpp index 5615616f39..f972641a5a 100644 --- a/crypto3/libs/marshalling/zk/test/placeholder_common_data.cpp +++ b/crypto3/libs/marshalling/zk/test/placeholder_common_data.cpp @@ -53,7 +53,7 @@ #include #include #include -#include +#include #include #include diff --git a/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp b/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp index 11ea97d8c8..c6d685525a 100644 --- a/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp +++ b/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include diff --git a/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp b/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp index cafb311f26..eb4657c625 100644 --- a/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp +++ b/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp @@ -82,7 +82,7 @@ #include #include #include -#include +#include #include #include diff --git a/crypto3/libs/marshalling/zk/test/plonk_assignment_table.cpp b/crypto3/libs/marshalling/zk/test/plonk_assignment_table.cpp index 353d779b8f..a3e5948803 100644 --- a/crypto3/libs/marshalling/zk/test/plonk_assignment_table.cpp +++ b/crypto3/libs/marshalling/zk/test/plonk_assignment_table.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -236,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE(assignment_table_marshalling_test, test_tools::random_te test_assignment_table(desc.usable_rows_amount, assignments, "circuit2"); else test_assignment_table(desc.usable_rows_amount, assignments); - + test_assignment_table_description>(desc); } BOOST_AUTO_TEST_SUITE_END() @@ -295,7 +295,7 @@ BOOST_FIXTURE_TEST_CASE(assignment_table_marshalling_test, test_tools::random_te test_assignment_table(desc.usable_rows_amount, assignments, "circuit3"); else test_assignment_table(desc.usable_rows_amount, assignments); - + test_assignment_table_description>(desc); } BOOST_AUTO_TEST_SUITE_END() @@ -356,7 +356,7 @@ BOOST_FIXTURE_TEST_CASE(assignment_table_marshalling_test, test_tools::random_te test_assignment_table(desc.usable_rows_amount, assignments, "circuit4"); else test_assignment_table(desc.usable_rows_amount, assignments); - + test_assignment_table_description>(desc); } BOOST_AUTO_TEST_SUITE_END() @@ -477,7 +477,7 @@ BOOST_FIXTURE_TEST_CASE(assignment_table_marshalling_test, test_tools::random_te test_assignment_table(desc.usable_rows_amount, assignments, "circuit6"); else test_assignment_table(desc.usable_rows_amount, assignments); - + test_assignment_table_description>(desc); } BOOST_AUTO_TEST_SUITE_END() @@ -535,7 +535,7 @@ BOOST_FIXTURE_TEST_CASE(assignment_table_marshalling_test, test_tools::random_te test_assignment_table(desc.usable_rows_amount, assignments, "circuit7"); else test_assignment_table(desc.usable_rows_amount, assignments); - + test_assignment_table_description>(desc); } BOOST_AUTO_TEST_SUITE_END() diff --git a/crypto3/libs/marshalling/zk/test/plonk_constraint_system.cpp b/crypto3/libs/marshalling/zk/test/plonk_constraint_system.cpp index 3d36ceadc1..30a4a26d4d 100644 --- a/crypto3/libs/marshalling/zk/test/plonk_constraint_system.cpp +++ b/crypto3/libs/marshalling/zk/test/plonk_constraint_system.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include diff --git a/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp b/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp index 52d61f795e..5c5c0727d1 100644 --- a/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp +++ b/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_SUITE(marshalling_real) using transcript_hash_type = nil::crypto3::hashes::keccak_1600<256>; using merkle_tree_type = typename containers::merkle_tree; -BOOST_FIXTURE_TEST_CASE(batches_num_3_test, zk::test_tools::random_test_initializer){ +BOOST_FIXTURE_TEST_CASE(batches_num_3_test, test_tools::random_test_initializer){ // Setup types. constexpr static const std::size_t lambda = 40; constexpr static const std::size_t k = 1; diff --git a/crypto3/libs/marshalling/zk/test/random_test_data_generation.hpp b/crypto3/libs/marshalling/zk/test/random_test_data_generation.hpp index 5301742098..76ae35998d 100644 --- a/crypto3/libs/marshalling/zk/test/random_test_data_generation.hpp +++ b/crypto3/libs/marshalling/zk/test/random_test_data_generation.hpp @@ -67,7 +67,7 @@ #include #include -#include +#include using namespace nil::crypto3; diff --git a/crypto3/libs/zk/test/CMakeLists.txt b/crypto3/libs/zk/test/CMakeLists.txt index 4173028d7f..2b9469a6b3 100644 --- a/crypto3/libs/zk/test/CMakeLists.txt +++ b/crypto3/libs/zk/test/CMakeLists.txt @@ -9,6 +9,7 @@ include(CMTest) target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE + "$" "$" "$") diff --git a/crypto3/libs/zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp b/crypto3/libs/zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp deleted file mode 100644 index 2740db924c..0000000000 --- a/crypto3/libs/zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp +++ /dev/null @@ -1,98 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2022 Mikhail Komarov -// Copyright (c) 2022 Nikita Kaskov -// Copyright (c) 2022 Ilia Shirobokov -// Copyright (c) 2022 Alisa Cherniaeva -// Copyright (c) 2023 Elena Tatuzova -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP -#define CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP - -#include -#include - -#include -#include -#include - - -namespace nil { - namespace crypto3 { - namespace zk { - namespace test_tools { - - // ******************************************************************************* - // * Randomness setup - // *******************************************************************************/ - // Template structure to include algebraic random engines for multiple field types - template - struct random_engine_container { - std::size_t seed; - std::tuple...> alg_rnd_engines; - - explicit random_engine_container(std::size_t init_seed = 0) - : alg_rnd_engines(nil::crypto3::random::algebraic_engine(init_seed)...) { - } - - // Template method to access a specific engine by type - template - nil::crypto3::random::algebraic_engine& get_alg_engine() { - return std::get>(alg_rnd_engines); - } - }; - - template - struct random_test_initializer { - random_test_initializer() { - for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc - 1); i++) { - if (std::string(boost::unit_test::framework::master_test_suite().argv[i]) == "--seed") { - if (std::string(boost::unit_test::framework::master_test_suite().argv[i + 1]) == "random") { - std::random_device rd; - seed = rd(); - break; - } - if (std::regex_match(boost::unit_test::framework::master_test_suite().argv[i + 1], - std::regex(("((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?")))) { - seed = atoi(boost::unit_test::framework::master_test_suite().argv[i + 1]); - break; - } - } - } - - BOOST_TEST_MESSAGE("seed = " << seed); - alg_random_engines = random_engine_container(seed); - generic_random_engine = boost::random::mt11213b(seed); - } - - std::size_t seed = 0; - random_engine_container alg_random_engines; - boost::random::mt11213b generic_random_engine; - }; - - } // namespace test_tools - } // namespace zk - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp index fa36662651..0e0c02f817 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp @@ -38,7 +38,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp index 494bd5e871..f4c358a131 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp @@ -53,7 +53,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp index e6d00985ef..6448147d94 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include "circuits.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp index 5aba05528c..32d3d2e45e 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp index 45d17d2d3f..09aa37808b 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp @@ -44,7 +44,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp index 66ef6c6f73..acfb535c6d 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp index dcf7e2427f..6a37bbe055 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp @@ -62,7 +62,7 @@ #include #include -#include +#include #include "circuits.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp index 7a5afba270..ea5133e9c6 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include "circuits.hpp" diff --git a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp index 2e7b5354a2..aeb5db7ffc 100644 --- a/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp +++ b/crypto3/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp b/crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp new file mode 100644 index 0000000000..64b42c7ab5 --- /dev/null +++ b/crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp @@ -0,0 +1,96 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2022 Mikhail Komarov +// Copyright (c) 2022 Nikita Kaskov +// Copyright (c) 2022 Ilia Shirobokov +// Copyright (c) 2022 Alisa Cherniaeva +// Copyright (c) 2023 Elena Tatuzova +// +// MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +//---------------------------------------------------------------------------// + +#ifndef CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP +#define CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP + +#include +#include + +#include +#include +#include + + +namespace nil { + namespace crypto3 { + namespace test_tools { + + // ******************************************************************************* + // * Randomness setup + // *******************************************************************************/ + // Template structure to include algebraic random engines for multiple field types + template + struct random_engine_container { + std::size_t seed; + std::tuple...> alg_rnd_engines; + + explicit random_engine_container(std::size_t init_seed = 0) + : alg_rnd_engines(nil::crypto3::random::algebraic_engine(init_seed)...) { + } + + // Template method to access a specific engine by type + template + nil::crypto3::random::algebraic_engine& get_alg_engine() { + return std::get>(alg_rnd_engines); + } + }; + + template + struct random_test_initializer { + random_test_initializer() { + for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc - 1); i++) { + if (std::string(boost::unit_test::framework::master_test_suite().argv[i]) == "--seed") { + if (std::string(boost::unit_test::framework::master_test_suite().argv[i + 1]) == "random") { + std::random_device rd; + seed = rd(); + break; + } + if (std::regex_match(boost::unit_test::framework::master_test_suite().argv[i + 1], + std::regex(("((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?")))) { + seed = atoi(boost::unit_test::framework::master_test_suite().argv[i + 1]); + break; + } + } + } + + BOOST_TEST_MESSAGE("seed = " << seed); + alg_random_engines = random_engine_container(seed); + generic_random_engine = boost::random::mt11213b(seed); + } + + std::size_t seed = 0; + random_engine_container alg_random_engines; + boost::random::mt11213b generic_random_engine; + }; + + } // namespace test_tools + } // namespace crypto3 +} // namespace nil + +#endif // CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP From b527c2fd99a0857cfe0cf8258d2fab0e190672bd Mon Sep 17 00:00:00 2001 From: "e.tatuzova" Date: Thu, 3 Oct 2024 19:15:03 +0400 Subject: [PATCH 2/2] Update parallel version and transpiler #52 --- .../zk/detail/random_test_data_generation.hpp | 1 - .../marshalling/zk/test/fri_commitment.cpp | 1 + .../marshalling/zk/test/lpc_commitment.cpp | 2 + .../placeholder_preprocessed_public_data.cpp | 1 + .../marshalling/zk/test/placeholder_proof.cpp | 2 +- .../marshalling/zk/test/polys_evaluator.cpp | 2 + .../libs/parallel-zk/test/CMakeLists.txt | 5 +- .../zk/test_tools/random_test_initializer.hpp | 98 ------------------- .../placeholder/placeholder_circuits.cpp | 2 +- .../plonk/placeholder/placeholder_curves.cpp | 2 +- .../placeholder/placeholder_gate_argument.cpp | 2 +- .../placeholder/placeholder_goldilocks.cpp | 2 +- .../plonk/placeholder/placeholder_hashes.cpp | 2 +- .../plonk/placeholder/placeholder_kzg.cpp | 2 +- .../placeholder_lookup_argument.cpp | 2 +- .../placeholder_permutation_argument.cpp | 2 +- ...placeholder_quotient_polynomial_chunks.cpp | 2 +- .../test_tools/random_test_initializer.hpp | 96 ++++++++++++++++++ 18 files changed, 115 insertions(+), 111 deletions(-) delete mode 100644 parallel-crypto3/libs/parallel-zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp create mode 100644 parallel-crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp diff --git a/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/detail/random_test_data_generation.hpp b/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/detail/random_test_data_generation.hpp index bc0abc191a..bc3e6452b6 100644 --- a/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/detail/random_test_data_generation.hpp +++ b/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/detail/random_test_data_generation.hpp @@ -67,7 +67,6 @@ #include #include -#include using namespace nil::crypto3; diff --git a/crypto3/libs/marshalling/zk/test/fri_commitment.cpp b/crypto3/libs/marshalling/zk/test/fri_commitment.cpp index 0c7038ecde..086448fa83 100644 --- a/crypto3/libs/marshalling/zk/test/fri_commitment.cpp +++ b/crypto3/libs/marshalling/zk/test/fri_commitment.cpp @@ -70,6 +70,7 @@ #include #include +#include #include using namespace nil::crypto3; diff --git a/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp b/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp index 8cb8df3046..94d75ae836 100644 --- a/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp +++ b/crypto3/libs/marshalling/zk/test/lpc_commitment.cpp @@ -65,6 +65,8 @@ #include #include + +#include #include using namespace nil::crypto3; diff --git a/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp b/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp index af7a8f4576..3d8006ac2d 100644 --- a/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp +++ b/crypto3/libs/marshalling/zk/test/placeholder_preprocessed_public_data.cpp @@ -59,6 +59,7 @@ #include #include #include + #include #include "./detail/circuits.hpp" diff --git a/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp b/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp index 8368294e2d..2a09fb1d9b 100644 --- a/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp +++ b/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp @@ -82,7 +82,6 @@ #include #include #include -#include #include #include @@ -94,6 +93,7 @@ #include #include "./detail/circuits.hpp" +#include #include using namespace nil; diff --git a/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp b/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp index aa99e58559..afc94e19ad 100644 --- a/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp +++ b/crypto3/libs/marshalling/zk/test/polys_evaluator.cpp @@ -70,6 +70,8 @@ #include #include #include // contains class polys_evaluator + +#include #include using namespace nil::crypto3; diff --git a/parallel-crypto3/libs/parallel-zk/test/CMakeLists.txt b/parallel-crypto3/libs/parallel-zk/test/CMakeLists.txt index a17031e301..f9eea44abe 100644 --- a/parallel-crypto3/libs/parallel-zk/test/CMakeLists.txt +++ b/parallel-crypto3/libs/parallel-zk/test/CMakeLists.txt @@ -30,8 +30,9 @@ macro(define_zk_test test) cm_test(NAME ${full_test_name} SOURCES ${test}.cpp) target_include_directories(${full_test_name} PRIVATE - "$" - "$" + "$" + "$" + "$" ${Boost_INCLUDE_DIRS}) diff --git a/parallel-crypto3/libs/parallel-zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp b/parallel-crypto3/libs/parallel-zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp deleted file mode 100644 index 2740db924c..0000000000 --- a/parallel-crypto3/libs/parallel-zk/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp +++ /dev/null @@ -1,98 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2022 Mikhail Komarov -// Copyright (c) 2022 Nikita Kaskov -// Copyright (c) 2022 Ilia Shirobokov -// Copyright (c) 2022 Alisa Cherniaeva -// Copyright (c) 2023 Elena Tatuzova -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP -#define CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP - -#include -#include - -#include -#include -#include - - -namespace nil { - namespace crypto3 { - namespace zk { - namespace test_tools { - - // ******************************************************************************* - // * Randomness setup - // *******************************************************************************/ - // Template structure to include algebraic random engines for multiple field types - template - struct random_engine_container { - std::size_t seed; - std::tuple...> alg_rnd_engines; - - explicit random_engine_container(std::size_t init_seed = 0) - : alg_rnd_engines(nil::crypto3::random::algebraic_engine(init_seed)...) { - } - - // Template method to access a specific engine by type - template - nil::crypto3::random::algebraic_engine& get_alg_engine() { - return std::get>(alg_rnd_engines); - } - }; - - template - struct random_test_initializer { - random_test_initializer() { - for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc - 1); i++) { - if (std::string(boost::unit_test::framework::master_test_suite().argv[i]) == "--seed") { - if (std::string(boost::unit_test::framework::master_test_suite().argv[i + 1]) == "random") { - std::random_device rd; - seed = rd(); - break; - } - if (std::regex_match(boost::unit_test::framework::master_test_suite().argv[i + 1], - std::regex(("((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?")))) { - seed = atoi(boost::unit_test::framework::master_test_suite().argv[i + 1]); - break; - } - } - } - - BOOST_TEST_MESSAGE("seed = " << seed); - alg_random_engines = random_engine_container(seed); - generic_random_engine = boost::random::mt11213b(seed); - } - - std::size_t seed = 0; - random_engine_container alg_random_engines; - boost::random::mt11213b generic_random_engine; - }; - - } // namespace test_tools - } // namespace zk - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_circuits.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_circuits.cpp index fdffd550bd..0e0c02f817 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_circuits.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_circuits.cpp @@ -38,7 +38,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_curves.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_curves.cpp index 744d08ef38..f4c358a131 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_curves.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_curves.cpp @@ -53,7 +53,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp index 5578c3f0d6..6448147d94 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include "circuits.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp index a2ad6fbf58..32d3d2e45e 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_hashes.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_hashes.cpp index 2c34838e17..09aa37808b 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_hashes.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_hashes.cpp @@ -44,7 +44,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_kzg.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_kzg.cpp index 52e87b38c5..acfb535c6d 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_kzg.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_kzg.cpp @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp index 059dd61b82..6a37bbe055 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp @@ -62,7 +62,7 @@ #include #include -#include +#include #include "circuits.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp index e8b1e88a09..ea5133e9c6 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include "circuits.hpp" diff --git a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp index ae12452758..aeb5db7ffc 100644 --- a/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp +++ b/parallel-crypto3/libs/parallel-zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include "circuits.hpp" #include "placeholder_test_runner.hpp" diff --git a/parallel-crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp b/parallel-crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp new file mode 100644 index 0000000000..64b42c7ab5 --- /dev/null +++ b/parallel-crypto3/test_tools/include/nil/crypto3/test_tools/random_test_initializer.hpp @@ -0,0 +1,96 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2022 Mikhail Komarov +// Copyright (c) 2022 Nikita Kaskov +// Copyright (c) 2022 Ilia Shirobokov +// Copyright (c) 2022 Alisa Cherniaeva +// Copyright (c) 2023 Elena Tatuzova +// +// MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +//---------------------------------------------------------------------------// + +#ifndef CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP +#define CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP + +#include +#include + +#include +#include +#include + + +namespace nil { + namespace crypto3 { + namespace test_tools { + + // ******************************************************************************* + // * Randomness setup + // *******************************************************************************/ + // Template structure to include algebraic random engines for multiple field types + template + struct random_engine_container { + std::size_t seed; + std::tuple...> alg_rnd_engines; + + explicit random_engine_container(std::size_t init_seed = 0) + : alg_rnd_engines(nil::crypto3::random::algebraic_engine(init_seed)...) { + } + + // Template method to access a specific engine by type + template + nil::crypto3::random::algebraic_engine& get_alg_engine() { + return std::get>(alg_rnd_engines); + } + }; + + template + struct random_test_initializer { + random_test_initializer() { + for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc - 1); i++) { + if (std::string(boost::unit_test::framework::master_test_suite().argv[i]) == "--seed") { + if (std::string(boost::unit_test::framework::master_test_suite().argv[i + 1]) == "random") { + std::random_device rd; + seed = rd(); + break; + } + if (std::regex_match(boost::unit_test::framework::master_test_suite().argv[i + 1], + std::regex(("((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?")))) { + seed = atoi(boost::unit_test::framework::master_test_suite().argv[i + 1]); + break; + } + } + } + + BOOST_TEST_MESSAGE("seed = " << seed); + alg_random_engines = random_engine_container(seed); + generic_random_engine = boost::random::mt11213b(seed); + } + + std::size_t seed = 0; + random_engine_container alg_random_engines; + boost::random::mt11213b generic_random_engine; + }; + + } // namespace test_tools + } // namespace crypto3 +} // namespace nil + +#endif // CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP