Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move random_test_initializer to separate file [SyncWith: crypto3-zk#328] #328

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 0 additions & 95 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,100 +52,6 @@ include(FindPkgConfig)

option(BUILD_TESTS "Build unit tests" FALSE)

list(APPEND ${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS
include/nil/crypto3/zk/snark/accumulators/snark.hpp

include/nil/crypto3/zk/snark/detail/accumulation_vector.hpp
include/nil/crypto3/zk/snark/detail/set_commitment.hpp
include/nil/crypto3/zk/snark/detail/sparse_vector.hpp

include/nil/crypto3/zk/snark/commitments/knowledge_commitment_multiexp.hpp
include/nil/crypto3/zk/snark/commitments/knowledge_commitment.hpp

include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/compliance_predicate/compliance_predicate.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/compliance_predicate/cp_handler.hpp

include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_mp_ppzkpcd/mp_pcd_circuits.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_mp_ppzkpcd/r1cs_mp_ppzkpcd.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_mp_ppzkpcd/r1cs_mp_ppzkpcd_params.hpp

include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_sp_ppzkpcd/r1cs_sp_ppzkpcd.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_sp_ppzkpcd/r1cs_sp_ppzkpcd_params.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_sp_ppzkpcd/sp_pcd_circuits.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/ppzkpcd_compliance_predicate.hpp
include/nil/crypto3/zk/snark/systems/pcd/r1cs_pcd/r1cs_pcd_params.hpp

include/nil/crypto3/zk/snark/systems/ppzkadsnark/r1cs_ppzkadsnark/r1cs_ppzkadsnark.hpp
include/nil/crypto3/zk/snark/systems/ppzkadsnark/r1cs_ppzkadsnark/prf.hpp
include/nil/crypto3/zk/snark/systems/ppzkadsnark/r1cs_ppzkadsnark/signature.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzkadsnark/r1cs_ppzkadsnark/basic_policy.hpp

include/nil/crypto3/zk/snark/systems/ppzksnark/bacs_ppzksnark.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzksnark/bacs_ppzksnark/basic_policy.hpp

include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_gg_ppzksnark.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzksnark/r1cs_gg_ppzksnark/basic_policy.hpp

include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_ppzksnark.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzksnark/r1cs_ppzksnark/basic_policy.hpp

include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_se_ppzksnark.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzksnark/r1cs_se_ppzksnark/basic_policy.hpp

include/nil/crypto3/zk/snark/systems/ppzksnark/tbcs_ppzksnark.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzksnark/tbcs_ppzksnark/basic_policy.hpp

include/nil/crypto3/zk/snark/systems/ppzksnark/uscs_ppzksnark.hpp
include/nil/crypto3/zk/snark/systems/detail/ppzksnark/uscs_ppzksnark/basic_policy.hpp

include/nil/crypto3/zk/snark/reductions/bacs_to_r1cs.hpp

include/nil/crypto3/zk/snark/reductions/r1cs_to_qap.hpp

include/nil/crypto3/zk/snark/reductions/r1cs_to_sap.hpp

include/nil/crypto3/zk/snark/reductions/tbcs_to_uscs.hpp

include/nil/crypto3/zk/snark/reductions/uscs_to_ssp.hpp

include/nil/crypto3/zk/snark/arithmetization/arithmetic_programs/qap.hpp

include/nil/crypto3/zk/snark/arithmetization/arithmetic_programs/sap.hpp

include/nil/crypto3/zk/snark/arithmetization/arithmetic_programs/ssp.hpp

include/nil/crypto3/zk/snark/arithmetization/circuit_satisfaction_problems/bacs.hpp

include/nil/crypto3/zk/snark/arithmetization/circuit_satisfaction_problems/tbcs.hpp

include/nil/crypto3/zk/snark/arithmetization/constraint_satisfaction_problems/r1cs.hpp

include/nil/crypto3/zk/snark/arithmetization/constraint_satisfaction_problems/uscs.hpp

include/nil/crypto3/zk/snark/arithmetization/ram_computations/memory/delegated_ra_memory.hpp
include/nil/crypto3/zk/snark/arithmetization/ram_computations/memory/memory_interface.hpp
include/nil/crypto3/zk/snark/arithmetization/ram_computations/memory/memory_store_trace.hpp
include/nil/crypto3/zk/snark/arithmetization/ram_computations/memory/ra_memory.hpp

include/nil/crypto3/zk/snark/arithmetization/ram_computations/rams/fooram/fooram_aux.hpp
include/nil/crypto3/zk/snark/arithmetization/ram_computations/rams/fooram/fooram_params.hpp

include/nil/crypto3/zk/snark/arithmetization/ram_computations/rams/tinyram/tinyram_aux.hpp
include/nil/crypto3/zk/snark/arithmetization/ram_computations/rams/tinyram/tinyram_params.hpp
include/nil/crypto3/zk/snark/arithmetization/ram_computations/rams/ram_params.hpp
include/nil/crypto3/zk/snark/arithmetization/variable.hpp
include/nil/crypto3/zk/snark/routing/as_waksman.hpp
include/nil/crypto3/zk/snark/routing/benes.hpp
include/nil/crypto3/zk/snark/constraint_profiling.hpp
include/nil/crypto3/zk/snark/integer_permutation.hpp
include/nil/crypto3/zk/snark/merkle_tree.hpp)

list(APPEND ${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES)

list(APPEND ${CURRENT_PROJECT_NAME}_HEADERS ${${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS})

list(APPEND ${CURRENT_PROJECT_NAME}_SOURCES ${${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES})

cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})

add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE)
Expand All @@ -169,7 +75,6 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::hash
${CMAKE_WORKSPACE_NAME}::multiprecision
${CMAKE_WORKSPACE_NAME}::containers)
# marshalling::crypto3_zk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably have this dependency, but we choose not to list it here, that's why we had this comment. But it's ok to delete it.


cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
INCLUDE include
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ include(CMTest)

cm_find_package(Boost REQUIRED COMPONENTS unit_test_framework)

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>")

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

${CMAKE_WORKSPACE_NAME}::algebra
Expand Down
95 changes: 95 additions & 0 deletions test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2022 Mikhail Komarov <[email protected]>
// Copyright (c) 2022 Nikita Kaskov <[email protected]>
// Copyright (c) 2022 Ilia Shirobokov <[email protected]>
// Copyright (c) 2022 Alisa Cherniaeva <[email protected]>
// Copyright (c) 2023 Elena Tatuzova <[email protected]>
//
// 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 <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/random/algebraic_random_device.hpp>
#include <nil/crypto3/random/algebraic_engine.hpp>


namespace nil {
namespace crypto3 {
namespace zk {
namespace test_tools {

// *******************************************************************************
// * Randomness setup
// *******************************************************************************/
// Template structure to include algebraic random engines for multiple field types
template<typename... FieldTypes>
struct random_engine_container {
std::size_t seed;
std::tuple<nil::crypto3::random::algebraic_engine<FieldTypes>...> alg_rnd_engines;

explicit random_engine_container(std::size_t init_seed = 0)
: alg_rnd_engines(nil::crypto3::random::algebraic_engine<FieldTypes>(init_seed)...) {
}

// Template method to access a specific engine by type
template<typename FieldType>
nil::crypto3::random::algebraic_engine<FieldType>& get_alg_engine() {
return std::get<nil::crypto3::random::algebraic_engine<FieldType>>(alg_rnd_engines);
}
};

template<typename... FieldType>
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<FieldType...>(seed);
generic_random_engine = boost::random::mt11213b(seed);
}

std::size_t seed = 0;
random_engine_container<FieldType...> 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
Loading
Loading