diff --git a/libs/hash/test/hash_to_curve.cpp b/libs/hash/test/hash_to_curve.cpp index 6a6ab08e96..65221b352e 100644 --- a/libs/hash/test/hash_to_curve.cpp +++ b/libs/hash/test/hash_to_curve.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include diff --git a/libs/marshalling/algebra/test/curve_element.cpp b/libs/marshalling/algebra/test/curve_element.cpp index 2dd4292e5d..865e4c08da 100644 --- a/libs/marshalling/algebra/test/curve_element.cpp +++ b/libs/marshalling/algebra/test/curve_element.cpp @@ -25,7 +25,7 @@ #define BOOST_TEST_MODULE crypto3_marshalling_curve_element_test -#include +#include #include #include diff --git a/libs/marshalling/zk/test/kzg_commitment.cpp b/libs/marshalling/zk/test/kzg_commitment.cpp index c9fe149959..5c3a127ab3 100644 --- a/libs/marshalling/zk/test/kzg_commitment.cpp +++ b/libs/marshalling/zk/test/kzg_commitment.cpp @@ -28,7 +28,7 @@ #include "nil/crypto3/zk/commitments/batched_commitment.hpp" #define BOOST_TEST_MODULE crypto3_marshalling_kzg_commitment_test -#include +#include #include #include #include diff --git a/libs/marshalling/zk/test/lpc_commitment.cpp b/libs/marshalling/zk/test/lpc_commitment.cpp index 75ca64ceaf..26e433fa74 100644 --- a/libs/marshalling/zk/test/lpc_commitment.cpp +++ b/libs/marshalling/zk/test/lpc_commitment.cpp @@ -27,7 +27,7 @@ #define BOOST_TEST_MODULE crypto3_marshalling_lpc_commitment_test -#include +#include #include #include diff --git a/libs/marshalling/zk/test/placeholder_common_data.cpp b/libs/marshalling/zk/test/placeholder_common_data.cpp index 7cf32bf6d7..5615616f39 100644 --- a/libs/marshalling/zk/test/placeholder_common_data.cpp +++ b/libs/marshalling/zk/test/placeholder_common_data.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE crypto3_marshalling_placeholder_common_data_test -#include +#include #include #include #include diff --git a/libs/marshalling/zk/test/placeholder_proof.cpp b/libs/marshalling/zk/test/placeholder_proof.cpp index 2eb1440536..19bd0d9394 100644 --- a/libs/marshalling/zk/test/placeholder_proof.cpp +++ b/libs/marshalling/zk/test/placeholder_proof.cpp @@ -27,7 +27,7 @@ #define BOOST_TEST_MODULE crypto3_marshalling_placeholder_proof_test -#include +#include #include #include #include diff --git a/libs/zk/test/CMakeLists.txt b/libs/zk/test/CMakeLists.txt index 068f71c937..9e1ea90960 100644 --- a/libs/zk/test/CMakeLists.txt +++ b/libs/zk/test/CMakeLists.txt @@ -50,7 +50,6 @@ set(TESTS_NAMES "commitment/fri" "commitment/kzg" "commitment/fold_polynomial" - "commitment/lpc_performance" "commitment/pedersen" "commitment/proof_of_knowledge" # "commitment/powers_of_tau" @@ -110,3 +109,7 @@ endforeach() # string(CONCAT TEST_DATA ${CMAKE_CURRENT_SOURCE_DIR} "/systems/plonk/pickles/data/kimchi") # target_compile_definitions(crypto3_zk_systems_plonk_pickles_kimchi_test PRIVATE TEST_DATA="${TEST_DATA}") +if(BUILD_BENCH_TESTS) + cm_add_test_subdirectory(bench_test) +endif() + diff --git a/libs/zk/test/bench_test/CMakeLists.txt b/libs/zk/test/bench_test/CMakeLists.txt new file mode 100644 index 0000000000..72e11a016f --- /dev/null +++ b/libs/zk/test/bench_test/CMakeLists.txt @@ -0,0 +1,45 @@ +#---------------------------------------------------------------------------# +# Copyright (c) 2018-2021 Mikhail Komarov +# +# Distributed under the Boost Software License, Version 1.0 +# See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt +#---------------------------------------------------------------------------# + +include(CMTest) + +add_custom_target(zk_runtime_bench_tests) + +macro(define_runtime_zk_test name) + set(test_name "zk_${name}_bench_test") + add_dependencies(zk_runtime_bench_tests ${test_name}) + + cm_test(NAME ${test_name} SOURCES ${name}.cpp) + + target_include_directories(${test_name} PRIVATE + "$" + "$" + + ${Boost_INCLUDE_DIRS}) + + set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17 + CXX_STANDARD_REQUIRED TRUE) + + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${test_name} PRIVATE "-fconstexpr-ops-limit=4294967295") + endif() + + target_compile_definitions(${test_name} PRIVATE TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/") +endmacro() + +set(RUNTIME_TESTS_NAMES + "bench_pedersen" + "bench_lpc" + ) + +foreach(TEST_NAME ${RUNTIME_TESTS_NAMES}) + define_runtime_zk_test(${TEST_NAME}) +endforeach() + diff --git a/libs/zk/test/bench_test/lpc.cpp b/libs/zk/test/bench_test/lpc.cpp new file mode 100644 index 0000000000..fbee5d86ee --- /dev/null +++ b/libs/zk/test/bench_test/lpc.cpp @@ -0,0 +1,400 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2021 Mikhail Komarov +// Copyright (c) 2021 Nikita Kaskov +// Copyright (c) 2022 Ilia Shirobokov +// +// 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. +//---------------------------------------------------------------------------// + +#define BOOST_TEST_MODULE lpc_test + +// Do it manually for all performance tests +#define ZK_PLACEHOLDER_PROFILING_ENABLED + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace nil::crypto3; +using namespace nil::crypto3::zk::snark; + +namespace boost { + namespace test_tools { + namespace tt_detail { + template<> + struct print_log_value>>>> { + void operator()(std::ostream &, + const nil::crypto3::math::polynomial> + + >> &) { + } + }; +} // namespace tt_detail +} // namespace test_tools +} // namespace boost + +template +std::vector> generate(NumberType degree) { + typedef boost::random::independent_bits_engine + random_polynomial_generator_type; + + std::vector> res; + + boost::random::random_device rd; // Will be used to obtain a seed for the random number engine + boost::random::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() + boost::random::uniform_int_distribution<> distrib(std::numeric_limits::min(), std::numeric_limits::max()); + + random_polynomial_generator_type polynomial_element_gen; + std::size_t height = 1; + res.reserve(height); + + for (int i = 0; i < height; i++) { + math::polynomial poly; + for (int j = 0; j < degree; j++) { + poly.push_back(typename FieldType::value_type(polynomial_element_gen())); + } + res.push_back(poly); + } + + return res; +} + +inline std::vector generate_random_step_list(const std::size_t r, const int max_step) { + using dist_type = std::uniform_int_distribution; + static std::random_device random_engine; + + std::vector step_list; + std::size_t steps_sum = 0; + while (steps_sum != r) { + if (r - steps_sum <= max_step) { + while (r - steps_sum != 1) { + step_list.emplace_back(r - steps_sum - 1); + steps_sum += step_list.back(); + } + step_list.emplace_back(1); + steps_sum += step_list.back(); + } else { + step_list.emplace_back(dist_type(1, max_step)(random_engine)); + steps_sum += step_list.back(); + } + } + return step_list; +} + +BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) + + BOOST_AUTO_TEST_CASE(step_list_1) { + PROFILE_PLACEHOLDER_SCOPE("LPC step list 1 test"); + typedef algebra::curves::bls12<381> curve_type; + typedef typename curve_type::scalar_field_type FieldType; + + typedef hashes::keccak_1600<256> merkle_hash_type; + typedef hashes::keccak_1600<256> transcript_hash_type; + + constexpr static const std::size_t lambda = 40; + constexpr static const std::size_t k = 1; + + // It's important parameter + constexpr static const std::size_t d = 1 << 24; + constexpr static const std::size_t r = boost::static_log2<(d - k)>::value; + + constexpr static const std::size_t m = 2; + + typedef zk::commitments::fri fri_type; + typedef zk::commitments::list_polynomial_commitment_params lpc_params_type; + typedef zk::commitments::list_polynomial_commitment lpc_type; + + constexpr static const std::size_t d_extended = d; + std::size_t extended_log = boost::static_log2::value; + std::vector>> D = + math::calculate_domain_set(extended_log, r); + + typename fri_type::params_type fri_params( + d - 1, + D, + generate_random_step_list(r, 1), + r, + lambda + ); + + using lpc_scheme_type = nil::crypto3::zk::commitments::lpc_commitment_scheme>; + lpc_scheme_type lpc_scheme_prover(fri_params); + lpc_scheme_type lpc_scheme_verifier(fri_params); + + typedef boost::random::independent_bits_engine< + boost::random::mt19937, FieldType::modulus_bits, + typename FieldType::value_type::integral_type + > random_polynomial_generator_type; + + std::vector> res; + + // Generate polys + boost::random::random_device rd; // Will be used to obtain a seed for the random number engine + boost::random::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() + boost::random::uniform_int_distribution<> distrib(std::numeric_limits::min(), + std::numeric_limits::max()); + + random_polynomial_generator_type polynomial_element_gen; + std::size_t height = 1; + res.reserve(height); + + for (int i = 0; i < height; i++) { + math::polynomial poly(fri_params.max_degree + 1); + for (int j = 0; j < fri_params.max_degree + 1; j++) { + poly[i] = typename FieldType::value_type(polynomial_element_gen()); + } + + std::map commitments; + { + PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + lpc_scheme_prover.append_to_batch(0, poly); + commitments[0] = lpc_scheme_prover.commit(0); + } + + + typename lpc_scheme_type::proof_type proof; + std::array x_data{}; + { + PROFILE_PLACEHOLDER_SCOPE("proof generation"); + lpc_scheme_prover.append_eval_point(0, + algebra::fields::arithmetic_params::multiplicative_generator); + zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); + proof = lpc_scheme_prover.proof_eval(transcript); + } + + { + PROFILE_PLACEHOLDER_SCOPE("verification"); + zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); + lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); + + lpc_scheme_verifier.append_eval_point(0, + algebra::fields::arithmetic_params::multiplicative_generator); + BOOST_CHECK(lpc_scheme_verifier.verify_eval(proof, commitments, transcript_verifier)); + } + } + } + + BOOST_AUTO_TEST_CASE(step_list_3) { + PROFILE_PLACEHOLDER_SCOPE("LPC step list 3 test"); + typedef algebra::curves::bls12<381> curve_type; + typedef typename curve_type::scalar_field_type FieldType; + + typedef hashes::keccak_1600<256> merkle_hash_type; + typedef hashes::keccak_1600<256> transcript_hash_type; + + constexpr static const std::size_t lambda = 40; + constexpr static const std::size_t k = 1; + + // It's important parameter + constexpr static const std::size_t d = 1 << 24; + + constexpr static const std::size_t r = boost::static_log2<(d - k)>::value; + constexpr static const std::size_t m = 2; + + typedef zk::commitments::fri fri_type; + typedef zk::commitments::list_polynomial_commitment_params lpc_params_type; + typedef zk::commitments::list_polynomial_commitment lpc_type; + + constexpr static const std::size_t d_extended = d; + std::size_t extended_log = boost::static_log2::value; + std::vector>> D = + math::calculate_domain_set(extended_log, r); + + typename fri_type::params_type fri_params( + d - 1, + D, + generate_random_step_list(r, 3), + r, + lambda + ); + + using lpc_scheme_type = nil::crypto3::zk::commitments::lpc_commitment_scheme>; + lpc_scheme_type lpc_scheme_prover(fri_params); + lpc_scheme_type lpc_scheme_verifier(fri_params); + + typedef boost::random::independent_bits_engine< + boost::random::mt19937, FieldType::modulus_bits, + typename FieldType::value_type::integral_type + > random_polynomial_generator_type; + + std::vector> res; + + // Generate polys + boost::random::random_device rd; // Will be used to obtain a seed for the random number engine + boost::random::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() + boost::random::uniform_int_distribution<> distrib(std::numeric_limits::min(), + std::numeric_limits::max()); + + random_polynomial_generator_type polynomial_element_gen; + std::size_t height = 1; + res.reserve(height); + + for (int i = 0; i < height; i++) { + math::polynomial poly(fri_params.max_degree + 1); + for (int j = 0; j < fri_params.max_degree + 1; j++) { + poly[i] = typename FieldType::value_type(polynomial_element_gen()); + } + + std::map commitments; + { + PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + lpc_scheme_prover.append_to_batch(0, poly); + commitments[0] = lpc_scheme_prover.commit(0); + } + + + typename lpc_scheme_type::proof_type proof; + std::array x_data{}; + { + PROFILE_PLACEHOLDER_SCOPE("proof generation"); + lpc_scheme_prover.append_eval_point(0, + algebra::fields::arithmetic_params::multiplicative_generator); + zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); + proof = lpc_scheme_prover.proof_eval(transcript); + } + + { + PROFILE_PLACEHOLDER_SCOPE("verification"); + zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); + lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); + + lpc_scheme_verifier.append_eval_point(0, + algebra::fields::arithmetic_params::multiplicative_generator); + BOOST_CHECK(lpc_scheme_verifier.verify_eval(proof, commitments, transcript_verifier)); + } + } + } + + BOOST_AUTO_TEST_CASE(step_list_5) { + PROFILE_PLACEHOLDER_SCOPE("LPC step list 5 test"); + typedef algebra::curves::bls12<381> curve_type; + typedef typename curve_type::scalar_field_type FieldType; + + typedef hashes::keccak_1600<256> merkle_hash_type; + typedef hashes::keccak_1600<256> transcript_hash_type; + + constexpr static const std::size_t lambda = 40; + constexpr static const std::size_t k = 1; + + // It's important parameter + constexpr static const std::size_t d = 1 << 24; + constexpr static const std::size_t m = 2; + constexpr static const std::size_t r = boost::static_log2<(d - k)>::value; + + typedef zk::commitments::fri fri_type; + typedef zk::commitments::list_polynomial_commitment_params lpc_params_type; + typedef zk::commitments::list_polynomial_commitment lpc_type; + + constexpr static const std::size_t d_extended = d; + std::size_t extended_log = boost::static_log2::value; + std::vector>> D = + math::calculate_domain_set(extended_log, r); + + typename fri_type::params_type fri_params( + d - 1, + D, + generate_random_step_list(r, 5), + r, + lambda + ); + + using lpc_scheme_type = nil::crypto3::zk::commitments::lpc_commitment_scheme>; + lpc_scheme_type lpc_scheme_prover(fri_params); + lpc_scheme_type lpc_scheme_verifier(fri_params); + + typedef boost::random::independent_bits_engine< + boost::random::mt19937, FieldType::modulus_bits, + typename FieldType::value_type::integral_type + > random_polynomial_generator_type; + + std::vector> res; + + // Generate polys + boost::random::random_device rd; // Will be used to obtain a seed for the random number engine + boost::random::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() + boost::random::uniform_int_distribution<> distrib(std::numeric_limits::min(), + std::numeric_limits::max()); + + random_polynomial_generator_type polynomial_element_gen; + std::size_t height = 1; + res.reserve(height); + + for (int i = 0; i < height; i++) { + math::polynomial poly(fri_params.max_degree + 1); + for (int j = 0; j < fri_params.max_degree + 1; j++) { + poly[i] = typename FieldType::value_type(polynomial_element_gen()); + } + + std::map commitments; + { + PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + lpc_scheme_prover.append_to_batch(0, poly); + commitments[0] = lpc_scheme_prover.commit(0); + } + + + typename lpc_scheme_type::proof_type proof; + std::array x_data{}; + { + PROFILE_PLACEHOLDER_SCOPE("proof generation"); + lpc_scheme_prover.append_eval_point(0, + algebra::fields::arithmetic_params::multiplicative_generator); + zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); + proof = lpc_scheme_prover.proof_eval(transcript); + } + + { + PROFILE_PLACEHOLDER_SCOPE("verification"); + zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); + lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); + + lpc_scheme_verifier.append_eval_point(0, + algebra::fields::arithmetic_params::multiplicative_generator); + BOOST_CHECK(lpc_scheme_verifier.verify_eval(proof, commitments, transcript_verifier)); + } + } + } + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/libs/zk/test/bench_test/pedersen.cpp b/libs/zk/test/bench_test/pedersen.cpp new file mode 100644 index 0000000000..d066c97c57 --- /dev/null +++ b/libs/zk/test/bench_test/pedersen.cpp @@ -0,0 +1,109 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2021 Mikhail Komarov +// Copyright (c) 2021 Nikita Kaskov +// Copyright (c) 2022 Ilia Shirobokov +// Copyright (c) 2024 Martun Karapetyan +// +// 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. +//---------------------------------------------------------------------------// + +#define BOOST_TEST_MODULE pedersen_test + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +using namespace nil::crypto3; + +BOOST_AUTO_TEST_SUITE(pedersen_test_suite) + +BOOST_AUTO_TEST_CASE(pedersen_long_test) { + + // setup + using curve_type = algebra::curves::bls12<381>; + using curve_group_type = curve_type::template g1_type<>; + using field_type = typename curve_type::scalar_field_type; + + constexpr static const int n = 2000000000; + constexpr static const int k = 1999999999; + static curve_group_type::value_type g = algebra::random_element(); + static curve_group_type::value_type h = algebra::random_element(); + while (g == h) { + h = algebra::random_element(); + } + + typedef typename zk::commitments::pedersen pedersen_type; + + typedef typename pedersen_type::proof_type proof_type; + typedef typename pedersen_type::params_type params_type; + + params_type params; + + params.n = n; + params.k = k; + params.g = g; + params.h = h; + + BOOST_CHECK(g != h); + BOOST_CHECK(n >= k); + BOOST_CHECK(k > 0); + + // commit + constexpr static const field_type::value_type w = field_type::value_type(300000000); + + // eval + proof_type proof = pedersen_type::proof_eval(params, w); + + // verify + BOOST_CHECK(pedersen_type::verify_eval(params, proof)); + + std::vector idx; + std::vector idx_base; + for (int i = 1; i <= n; ++i) { + idx_base.push_back(i); + } + std::random_device rd; + std::mt19937 gen(rd()); + std::shuffle(idx_base.begin(), idx_base.end(), gen); + for (int i = 0; i < k; ++i) { + idx.push_back(idx_base[i]); + } + + BOOST_CHECK(idx.size() >= k); + field_type::value_type secret = pedersen_type::message_eval(params, proof, idx); + BOOST_CHECK(w == secret); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/zk/test/commitment/kzg.cpp b/libs/zk/test/commitment/kzg.cpp index a37cb08ad8..edcaa34ffa 100644 --- a/libs/zk/test/commitment/kzg.cpp +++ b/libs/zk/test/commitment/kzg.cpp @@ -30,7 +30,7 @@ #include -#include +#include #include #include diff --git a/libs/zk/test/commitment/pedersen.cpp b/libs/zk/test/commitment/pedersen.cpp index 93a845b87e..c7de3d9a8b 100644 --- a/libs/zk/test/commitment/pedersen.cpp +++ b/libs/zk/test/commitment/pedersen.cpp @@ -48,175 +48,118 @@ using namespace nil::crypto3; BOOST_AUTO_TEST_SUITE(pedersen_test_suite) - BOOST_AUTO_TEST_CASE(pedersen_basic_test) { - - // setup - using curve_type = algebra::curves::bls12<381>; - using curve_group_type = curve_type::template g1_type<>; - using field_type = typename curve_type::scalar_field_type; - - constexpr static const int n = 50; - constexpr static const int k = 26; - curve_group_type::value_type g = algebra::random_element(); - curve_group_type::value_type h = algebra::random_element(); - while (g == h) { - h = algebra::random_element(); - } - - typedef typename zk::commitments::pedersen pedersen_type; - - typedef typename pedersen_type::proof_type proof_type; - typedef typename pedersen_type::params_type params_type; - - params_type params; - - params.n = n; - params.k = k; - params.g = g; - params.h = h; - - BOOST_CHECK(g != h); - BOOST_CHECK(n >= k); - BOOST_CHECK(k > 0); - - // commit - constexpr static const field_type::value_type w = field_type::value_type(37684); - - // eval - proof_type proof = pedersen_type::proof_eval(params, w); - - // verify - BOOST_CHECK(pedersen_type::verify_eval(params, proof)); - - std::vector idx; - std::vector idx_base; - for (int i = 1; i <= n; ++i) { - idx_base.push_back(i); - } - std::random_device rd; - std::mt19937 gen(rd()); - std::shuffle(idx_base.begin(), idx_base.end(), gen); - for (int i = 0; i < k; ++i) { - idx.push_back(idx_base[i]); - } - - BOOST_CHECK(idx.size() >= k); - field_type::value_type secret = pedersen_type::message_eval(params, proof, idx); - BOOST_CHECK(w == secret); +BOOST_AUTO_TEST_CASE(pedersen_basic_test) { + + // setup + using curve_type = algebra::curves::bls12<381>; + using curve_group_type = curve_type::template g1_type<>; + using field_type = typename curve_type::scalar_field_type; + + constexpr static const int n = 50; + constexpr static const int k = 26; + curve_group_type::value_type g = algebra::random_element(); + curve_group_type::value_type h = algebra::random_element(); + while (g == h) { + h = algebra::random_element(); } - BOOST_AUTO_TEST_CASE(pedersen_short_test) { - - // setup - using curve_type = algebra::curves::bls12<381>; - using curve_group_type = curve_type::template g1_type<>; - using field_type = typename curve_type::scalar_field_type; - - constexpr static const int n = 2; - constexpr static const int k = 1; - static curve_group_type::value_type g = algebra::random_element(); - static curve_group_type::value_type h = algebra::random_element(); - while (g == h) { - h = algebra::random_element(); - } - - typedef typename zk::commitments::pedersen pedersen_type; - - typedef typename pedersen_type::proof_type proof_type; - typedef typename pedersen_type::params_type params_type; - - params_type params; - - params.n = n; - params.k = k; - params.g = g; - params.h = h; - - BOOST_CHECK(g != h); - BOOST_CHECK(n >= k); - BOOST_CHECK(k > 0); - - // commit - constexpr static const field_type::value_type w = field_type::value_type(3); - - // eval - proof_type proof = pedersen_type::proof_eval(params, w); - - // verify - BOOST_CHECK(pedersen_type::verify_eval(params, proof)); - - std::vector idx; - std::vector idx_base; - for (int i = 1; i <= n; ++i) { - idx_base.push_back(i); - } - std::random_device rd; - std::mt19937 gen(rd()); - std::shuffle(idx_base.begin(), idx_base.end(), gen); - for (int i = 0; i < k; ++i) { - idx.push_back(idx_base[i]); - } - - BOOST_CHECK(idx.size() >= k); - field_type::value_type secret = pedersen_type::message_eval(params, proof, idx); - BOOST_CHECK(w == secret); + typedef typename zk::commitments::pedersen pedersen_type; + + typedef typename pedersen_type::proof_type proof_type; + typedef typename pedersen_type::params_type params_type; + + params_type params; + + params.n = n; + params.k = k; + params.g = g; + params.h = h; + + BOOST_CHECK(g != h); + BOOST_CHECK(n >= k); + BOOST_CHECK(k > 0); + + // commit + constexpr static const field_type::value_type w = field_type::value_type(37684); + + // eval + proof_type proof = pedersen_type::proof_eval(params, w); + + // verify + BOOST_CHECK(pedersen_type::verify_eval(params, proof)); + + std::vector idx; + std::vector idx_base; + for (int i = 1; i <= n; ++i) { + idx_base.push_back(i); + } + std::random_device rd; + std::mt19937 gen(rd()); + std::shuffle(idx_base.begin(), idx_base.end(), gen); + for (int i = 0; i < k; ++i) { + idx.push_back(idx_base[i]); + } + + BOOST_CHECK(idx.size() >= k); + field_type::value_type secret = pedersen_type::message_eval(params, proof, idx); + BOOST_CHECK(w == secret); +} + +BOOST_AUTO_TEST_CASE(pedersen_short_test) { + + // setup + using curve_type = algebra::curves::bls12<381>; + using curve_group_type = curve_type::template g1_type<>; + using field_type = typename curve_type::scalar_field_type; + + constexpr static const int n = 2; + constexpr static const int k = 1; + static curve_group_type::value_type g = algebra::random_element(); + static curve_group_type::value_type h = algebra::random_element(); + while (g == h) { + h = algebra::random_element(); } - BOOST_AUTO_TEST_CASE(pedersen_long_test) { - - // setup - using curve_type = algebra::curves::bls12<381>; - using curve_group_type = curve_type::template g1_type<>; - using field_type = typename curve_type::scalar_field_type; - - constexpr static const int n = 2000000000; - constexpr static const int k = 1999999999; - static curve_group_type::value_type g = algebra::random_element(); - static curve_group_type::value_type h = algebra::random_element(); - while (g == h) { - h = algebra::random_element(); - } - - typedef typename zk::commitments::pedersen pedersen_type; - - typedef typename pedersen_type::proof_type proof_type; - typedef typename pedersen_type::params_type params_type; - - params_type params; - - params.n = n; - params.k = k; - params.g = g; - params.h = h; - - BOOST_CHECK(g != h); - BOOST_CHECK(n >= k); - BOOST_CHECK(k > 0); - - // commit - constexpr static const field_type::value_type w = field_type::value_type(300000000); - - // eval - proof_type proof = pedersen_type::proof_eval(params, w); - - // verify - BOOST_CHECK(pedersen_type::verify_eval(params, proof)); - - std::vector idx; - std::vector idx_base; - for (int i = 1; i <= n; ++i) { - idx_base.push_back(i); - } - std::random_device rd; - std::mt19937 gen(rd()); - std::shuffle(idx_base.begin(), idx_base.end(), gen); - for (int i = 0; i < k; ++i) { - idx.push_back(idx_base[i]); - } - - BOOST_CHECK(idx.size() >= k); - field_type::value_type secret = pedersen_type::message_eval(params, proof, idx); - BOOST_CHECK(w == secret); + typedef typename zk::commitments::pedersen pedersen_type; + + typedef typename pedersen_type::proof_type proof_type; + typedef typename pedersen_type::params_type params_type; + + params_type params; + + params.n = n; + params.k = k; + params.g = g; + params.h = h; + + BOOST_CHECK(g != h); + BOOST_CHECK(n >= k); + BOOST_CHECK(k > 0); + + // commit + constexpr static const field_type::value_type w = field_type::value_type(3); + + // eval + proof_type proof = pedersen_type::proof_eval(params, w); + + // verify + BOOST_CHECK(pedersen_type::verify_eval(params, proof)); + + std::vector idx; + std::vector idx_base; + for (int i = 1; i <= n; ++i) { + idx_base.push_back(i); + } + std::random_device rd; + std::mt19937 gen(rd()); + std::shuffle(idx_base.begin(), idx_base.end(), gen); + for (int i = 0; i < k; ++i) { + idx.push_back(idx_base[i]); } + BOOST_CHECK(idx.size() >= k); + field_type::value_type secret = pedersen_type::message_eval(params, proof, idx); + BOOST_CHECK(w == secret); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp index a7671f07cf..fa36662651 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_circuits.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_circuits_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp index 182b0591a6..494bd5e871 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_curves.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_curves_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp index 213a1274ac..f7eb1a23db 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_gate_argument.cpp @@ -31,7 +31,7 @@ #define BOOST_TEST_MODULE placeholder_gate_argument_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp index 2a37ed7fc7..5aba05528c 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_goldilocks.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_goldilocks_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp index 4153797554..45d17d2d3f 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_hashes.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_hashes_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp index d9d3c5ce4a..66ef6c6f73 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_kzg_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp index 26a59e9336..dcf7e2427f 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp @@ -31,7 +31,7 @@ #define BOOST_TEST_MODULE placeholder_lookup_argument_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp index 2190e08da4..7a5afba270 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_permutation_test -#include +#include #include #include diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp index 0cb797116d..2e7b5354a2 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_quotient_polynomial_chunks.cpp @@ -32,7 +32,7 @@ #define BOOST_TEST_MODULE placeholder_quotient_polynomial_chunks_test -#include +#include #include #include