diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bb0109f5..ac349ec8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -103,8 +103,9 @@ set(TESTS_NAMES "systems/plonk/pickles/to_field" "systems/plonk/pickles/to_group" - "systems/plonk/placeholder/placeholder" +# "systems/plonk/placeholder/placeholder" "systems/plonk/placeholder/placeholder_circuits" + "systems/plonk/placeholder/placeholder_goldilocks" "systems/plonk/placeholder/placeholder_lookup_argument" "systems/plonk/placeholder/placeholder_gate_argument" "systems/plonk/placeholder/placeholder_permutation_argument" diff --git a/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp b/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp index 6256dce1..99c1e77d 100644 --- a/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp +++ b/test/include/nil/crypto3/zk/test_tools/random_test_initializer.hpp @@ -29,6 +29,9 @@ #ifndef CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP #define CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP +#include +#include + #include #include #include diff --git a/test/systems/plonk/placeholder/circuits.hpp b/test/systems/plonk/placeholder/circuits.hpp index b4fd8610..3f97de80 100644 --- a/test/systems/plonk/placeholder/circuits.hpp +++ b/test/systems/plonk/placeholder/circuits.hpp @@ -228,7 +228,7 @@ namespace nil { constexpr static const std::size_t usable_rows_t = 5; template - circuit_description, usable_rows_t> + circuit_description> circuit_test_t( typename FieldType::value_type pi0 = 0u, typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), @@ -236,7 +236,6 @@ namespace nil { ) { using assignment_type = typename FieldType::value_type; - constexpr static const std::size_t usable_rows = usable_rows_t; constexpr static const std::size_t witness_columns = witness_columns_t; constexpr static const std::size_t public_columns = public_columns_t; constexpr static const std::size_t constant_columns = constant_columns_t; @@ -246,8 +245,9 @@ namespace nil { typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; test_circuit.public_input_sizes = {3}; + test_circuit.usable_rows = usable_rows_t; std::vector> table(table_columns); @@ -361,7 +361,7 @@ namespace nil { constexpr static const std::size_t usable_rows_3 = 4; template - circuit_description, usable_rows_3> circuit_test_3( + circuit_description> circuit_test_3( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), boost::random::mt11213b rnd = boost::random::mt11213b() ) { @@ -373,11 +373,11 @@ namespace nil { constexpr static const std::size_t selector_columns = selector_columns_3; constexpr static const std::size_t table_columns = witness_columns + public_columns + constant_columns; - constexpr static const std::size_t usable_rows = usable_rows_3; typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; + test_circuit.usable_rows = usable_rows_3; std::vector> table(table_columns); for (std::size_t j = 0; j < table_columns; j++) { @@ -466,7 +466,7 @@ namespace nil { constexpr static const std::size_t selector_columns_4 = 3; template - circuit_description, 5> circuit_test_4( + circuit_description> circuit_test_4( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), boost::random::mt11213b rnd = boost::random::mt11213b() ) { @@ -483,8 +483,9 @@ namespace nil { typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; test_circuit.table_rows = 1 << rows_log; + test_circuit.usable_rows = 5; std::vector> table(table_columns); for (std::size_t j = 0; j < table_columns; j++) { @@ -578,25 +579,23 @@ namespace nil { constexpr static const std::size_t usable_rows_5 = 30; template - circuit_description, usable_rows_5> + circuit_description> circuit_test_5( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), boost::random::mt11213b rnd = boost::random::mt11213b() ) { using assignment_type = typename FieldType::value_type; - constexpr static const std::size_t usable_rows = usable_rows_5; constexpr static const std::size_t witness_columns = witness_columns_5; constexpr static const std::size_t public_input_columns = public_columns_5; constexpr static const std::size_t constant_columns = constant_columns_5; constexpr static const std::size_t selector_columns = selector_columns_5; - constexpr static const std::size_t table_columns = - witness_columns + public_input_columns + constant_columns; typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; test_circuit.public_input_sizes = {witness_columns}; + test_circuit.usable_rows = usable_rows_5; std::vector> private_assignment(witness_columns); std::vector> public_input_assignment(public_input_columns); @@ -656,7 +655,7 @@ namespace nil { constexpr static const std::size_t selector_columns_fib = 1; template - circuit_description, usable_rows> + circuit_description > circuit_test_fib( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine() ) { @@ -671,7 +670,8 @@ namespace nil { typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; + test_circuit.usable_rows = usable_rows; std::vector> table(table_columns); std::vector q_add(test_circuit.usable_rows); @@ -773,7 +773,7 @@ namespace nil { constexpr static const std::size_t usable_rows_6 = 6; template - circuit_description, usable_rows_6> circuit_test_6( + circuit_description> circuit_test_6( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), boost::random::mt11213b rnd = boost::random::mt11213b() ) { @@ -788,7 +788,8 @@ namespace nil { typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; + test_circuit.usable_rows = usable_rows_6; std::vector> table(table_columns); for (std::size_t j = 0; j < table_columns; j++) { @@ -913,7 +914,7 @@ namespace nil { constexpr static const std::size_t usable_rows_7 = 14; template - circuit_description, usable_rows_7> circuit_test_7( + circuit_description> circuit_test_7( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), boost::random::mt11213b rnd = boost::random::mt11213b() ) { @@ -928,7 +929,8 @@ namespace nil { typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; + test_circuit.usable_rows = usable_rows_7; std::vector> table(table_columns); for (std::size_t j = 0; j < table_columns; j++) { diff --git a/test/systems/plonk/placeholder/placeholder_circuits.cpp b/test/systems/plonk/placeholder/placeholder_circuits.cpp index ded2750e..c5bb3f1f 100644 --- a/test/systems/plonk/placeholder/placeholder_circuits.cpp +++ b/test/systems/plonk/placeholder/placeholder_circuits.cpp @@ -30,10 +30,6 @@ #define BOOST_TEST_MODULE placeholder_circuits_test -#include -#include -#include - #include #include #include @@ -89,81 +85,7 @@ #include #include "circuits.hpp" - -using namespace nil::crypto3; -using namespace nil::crypto3::zk; -using namespace nil::crypto3::zk::snark; - -template -struct placeholder_test_runner { - using field_type = FieldType; - - struct placeholder_test_params { - constexpr static const std::size_t lambda = 40; - constexpr static const std::size_t m = 2; - }; - - typedef placeholder_circuit_params circuit_params; - using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; - - using lpc_params_type = commitments::list_polynomial_commitment_params< - merkle_hash_type, - transcript_hash_type, - placeholder_test_params::m - >; - - using lpc_type = commitments::list_polynomial_commitment; - using lpc_scheme_type = typename commitments::lpc_commitment_scheme; - using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; - using policy_type = zk::snark::detail::placeholder_policy; - using circuit_type = circuit_description, usable_rows_amount>; - - placeholder_test_runner(const circuit_type& circuit_in, std::size_t usable_rows, std::size_t table_rows) - : circuit(circuit_in) - , desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) - , constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables) - , assignments(circuit.table) - , table_rows_log(std::log2(table_rows)) - , fri_params(1,table_rows_log, placeholder_test_params::lambda, 4) - { - desc.rows_amount = table_rows; - desc.usable_rows_amount = usable_rows; - } - - bool run_test() { - lpc_scheme_type lpc_scheme(fri_params); - - typename placeholder_public_preprocessor::preprocessed_data_type - lpc_preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.move_public_table(), desc, lpc_scheme, max_quotient_poly_chunks - ); - - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.move_private_table(), desc - ); - - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, std::move(lpc_preprocessed_private_data), desc, constraint_system, lpc_scheme - ); - - bool verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, lpc_proof, desc, constraint_system, lpc_scheme - ); - return verifier_res; - } - - circuit_type circuit; - plonk_table_description desc; - typename policy_type::constraint_system_type constraint_system; - typename policy_type::variable_assignment_type assignments; - std::size_t table_rows_log; - typename lpc_type::fri_type::params_type fri_params; -}; - - +#include "placeholder_test_runner.hpp" BOOST_AUTO_TEST_SUITE(placeholder_circuit1) @@ -184,8 +106,8 @@ using TestRunners = boost::mpl::list< >, placeholder_test_runner< algebra::curves::pallas::base_field_type, - hashes::keccak_1600<512>, - hashes::keccak_1600<512>, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, witness_columns_1, public_columns_1, constant_columns_1, @@ -226,8 +148,8 @@ using TestRunners = boost::mpl::list< >, placeholder_test_runner< algebra::curves::pallas::base_field_type, - hashes::keccak_1600<512>, - hashes::keccak_1600<512>, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, witness_columns_3, public_columns_3, constant_columns_3, @@ -255,7 +177,7 @@ const size_t usable_rows_4 = 5; using TestRunners = boost::mpl::list< placeholder_test_runner, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_4, public_columns_4, constant_columns_4, selector_columns_4, usable_rows_4> + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_4, public_columns_4, constant_columns_4, selector_columns_4, usable_rows_4> >; BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { test_tools::random_test_initializer random_test_initializer; @@ -275,7 +197,7 @@ using poseidon_type = hashes::poseidon, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_5, public_columns_5, constant_columns_5, selector_columns_5, usable_rows_5, false, 10> + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_5, public_columns_5, constant_columns_5, selector_columns_5, usable_rows_5, false, 10> >; BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { test_tools::random_test_initializer random_test_initializer; @@ -296,7 +218,7 @@ using poseidon_type = hashes::poseidon, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_6, public_columns_6, constant_columns_6, selector_columns_6, usable_rows_6, true> + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_6, public_columns_6, constant_columns_6, selector_columns_6, usable_rows_6, true> >; BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { test_tools::random_test_initializer random_test_initializer; @@ -317,10 +239,10 @@ using poseidon_type = hashes::poseidon, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 8>, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 10>, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 30>, - placeholder_test_runner, hashes::keccak_1600<512>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 50> + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 8>, + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 10>, + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 30>, + placeholder_test_runner, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 50> >; BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { test_tools::random_test_initializer random_test_initializer; diff --git a/test/systems/plonk/placeholder/placeholder_gate_argument.cpp b/test/systems/plonk/placeholder/placeholder_gate_argument.cpp index 3cb95a17..4d10f533 100644 --- a/test/systems/plonk/placeholder/placeholder_gate_argument.cpp +++ b/test/systems/plonk/placeholder/placeholder_gate_argument.cpp @@ -99,8 +99,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_gate_argument) using field_type = typename curve_type::scalar_field_type; struct placeholder_test_params { - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; + using merkle_hash_type = hashes::keccak_1600<256>; + using transcript_hash_type = hashes::keccak_1600<256>; constexpr static const std::size_t witness_columns = 3; constexpr static const std::size_t public_input_columns = 1; diff --git a/test/systems/plonk/placeholder/placeholder_goldilocks.cpp b/test/systems/plonk/placeholder/placeholder_goldilocks.cpp index 99c9d227..d17de1a7 100644 --- a/test/systems/plonk/placeholder/placeholder_goldilocks.cpp +++ b/test/systems/plonk/placeholder/placeholder_goldilocks.cpp @@ -89,6 +89,7 @@ #include #include "circuits.hpp" +#include "placeholder_test_runner.hpp" using namespace nil::crypto3; using namespace nil::crypto3::zk; @@ -102,8 +103,8 @@ using poseidon_type = hashes::poseidon, - hashes::keccak_1600<512>, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, witness_columns_1, public_columns_1, constant_columns_1, diff --git a/test/systems/plonk/placeholder/placeholder_hashes.cpp b/test/systems/plonk/placeholder/placeholder_hashes.cpp index 2f1197ca..b40c51b9 100644 --- a/test/systems/plonk/placeholder/placeholder_hashes.cpp +++ b/test/systems/plonk/placeholder/placeholder_hashes.cpp @@ -30,10 +30,6 @@ #define BOOST_TEST_MODULE placeholder_hashes_test -#include -#include -#include - #include #include #include @@ -89,87 +85,12 @@ #include #include "circuits.hpp" +#include "placeholder_test_runner.hpp" using namespace nil::crypto3; using namespace nil::crypto3::zk; using namespace nil::crypto3::zk::snark; -template -struct placeholder_test_runner { - using field_type = FieldType; - - struct placeholder_test_params { - constexpr static const std::size_t usable_rows = 13; - - constexpr static const std::size_t witness_columns = WitnessColumns; - constexpr static const std::size_t public_input_columns = PublicInputColumns; - constexpr static const std::size_t constant_columns = ConstantColumns; - constexpr static const std::size_t selector_columns = SelectorColumns; - - constexpr static const std::size_t lambda = 40; - constexpr static const std::size_t m = 2; - }; - - typedef placeholder_circuit_params circuit_params; - using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; - - using lpc_params_type = commitments::list_polynomial_commitment_params< - merkle_hash_type, - transcript_hash_type, - placeholder_test_params::m - >; - - using lpc_type = commitments::list_polynomial_commitment; - using lpc_scheme_type = typename commitments::lpc_commitment_scheme; - using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; - using policy_type = zk::snark::detail::placeholder_policy; - using circuit_type = circuit_description, usable_rows_amount>; - - placeholder_test_runner(const circuit_type& circuit_in, std::size_t usable_rows, std::size_t table_rows) - : circuit(circuit_in) - , desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) - , constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables) - , assignments(circuit.table) - , table_rows_log(std::log2(table_rows)) - , fri_params(1,table_rows_log, placeholder_test_params::lambda, 4) - { - desc.rows_amount = table_rows; - desc.usable_rows_amount = usable_rows; - } - - bool run_test() { - lpc_scheme_type lpc_scheme(fri_params); - - typename placeholder_public_preprocessor::preprocessed_data_type - lpc_preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.move_public_table(), desc, lpc_scheme, max_quotient_poly_chunks - ); - - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.move_private_table(), desc - ); - - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, std::move(lpc_preprocessed_private_data), desc, constraint_system, lpc_scheme - ); - - bool verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, lpc_proof, desc, constraint_system, lpc_scheme - ); - return verifier_res; - } - - circuit_type circuit; - plonk_table_description desc; - typename policy_type::constraint_system_type constraint_system; - typename policy_type::variable_assignment_type assignments; - std::size_t table_rows_log; - typename lpc_type::fri_type::params_type fri_params; -}; - BOOST_AUTO_TEST_SUITE(placeholder_hashes_test) @@ -188,6 +109,26 @@ using TestRunners = boost::mpl::list< selector_columns_1, rows_amount_1 >, + placeholder_test_runner< + algebra::curves::pallas::base_field_type, + hashes::sha2<256>, + hashes::sha2<256>, + witness_columns_1, + public_columns_1, + constant_columns_1, + selector_columns_1, + rows_amount_1 + >, + placeholder_test_runner< + algebra::curves::pallas::base_field_type, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_1, + public_columns_1, + constant_columns_1, + selector_columns_1, + rows_amount_1 + >, placeholder_test_runner< algebra::curves::pallas::base_field_type, hashes::keccak_1600<512>, diff --git a/test/systems/plonk/placeholder/placeholder_kzg.cpp b/test/systems/plonk/placeholder/placeholder_kzg.cpp index b3108c67..1448e264 100644 --- a/test/systems/plonk/placeholder/placeholder_kzg.cpp +++ b/test/systems/plonk/placeholder/placeholder_kzg.cpp @@ -150,8 +150,7 @@ struct placeholder_kzg_test_runner { using circuit_type = circuit_description, - usable_rows_amount>; + placeholder_circuit_params >; placeholder_kzg_test_runner() : desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) @@ -305,8 +304,7 @@ struct placeholder_kzg_test_runner_v2 { using circuit_type = circuit_description, - usable_rows_amount>; + placeholder_circuit_params>; placeholder_kzg_test_runner_v2() : desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) diff --git a/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp b/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp index 2d8a952a..acd608ff 100644 --- a/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp +++ b/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp @@ -103,8 +103,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit3_lookup_test) constexpr static const std::size_t usable_rows = 4; struct placeholder_test_params { - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; + using merkle_hash_type = hashes::keccak_1600<256>; + using transcript_hash_type = hashes::keccak_1600<256>; constexpr static const std::size_t witness_columns = witness_columns_3; constexpr static const std::size_t public_input_columns = public_columns_3; @@ -278,8 +278,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit4_lookup_test) constexpr static const std::size_t usable_rows = 5; struct placeholder_test_params { - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; + using merkle_hash_type = hashes::keccak_1600<256>; + using transcript_hash_type = hashes::keccak_1600<256>; constexpr static const std::size_t witness_columns = witness_columns_4; constexpr static const std::size_t public_input_columns = public_columns_4; diff --git a/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp b/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp index 8710c9a1..eb854237 100644 --- a/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp +++ b/test/systems/plonk/placeholder/placeholder_permutation_argument.cpp @@ -99,8 +99,8 @@ BOOST_AUTO_TEST_SUITE(permutation_argument) using field_type = typename curve_type::scalar_field_type; struct placeholder_test_params { - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; + using merkle_hash_type = hashes::keccak_1600<256>; + using transcript_hash_type = hashes::keccak_1600<256>; constexpr static const std::size_t witness_columns = 3; constexpr static const std::size_t public_input_columns = 1; diff --git a/test/systems/plonk/placeholder/placeholder_test_runner.hpp b/test/systems/plonk/placeholder/placeholder_test_runner.hpp new file mode 100644 index 00000000..2b13e5c8 --- /dev/null +++ b/test/systems/plonk/placeholder/placeholder_test_runner.hpp @@ -0,0 +1,116 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2022 Mikhail Komarov +// Copyright (c) 2022 Nikita Kaskov +// Copyright (c) 2022 Ilia Shirobokov +// Copyright (c) 2022 Alisa Cherniaeva +// Copyright (c) 2022 Ilias Khairullin +// 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_PLACEHOLDER_TEST_RUNNER_HPP +#define CRYPTO3_ZK_TEST_PLACEHOLDER_TEST_RUNNER_HPP + +#include + +#include "circuits.hpp" + +using namespace nil::crypto3; +using namespace nil::crypto3::zk; +using namespace nil::crypto3::zk::snark; + + +template +struct placeholder_test_runner { + using field_type = FieldType; + + struct placeholder_test_params { + constexpr static const std::size_t lambda = 40; + constexpr static const std::size_t m = 2; + }; + + typedef placeholder_circuit_params circuit_params; + using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; + + using lpc_params_type = commitments::list_polynomial_commitment_params< + merkle_hash_type, + transcript_hash_type, + placeholder_test_params::m + >; + + using lpc_type = commitments::list_polynomial_commitment; + using lpc_scheme_type = typename commitments::lpc_commitment_scheme; + using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; + using policy_type = zk::snark::detail::placeholder_policy; + using circuit_type = circuit_description>; + + placeholder_test_runner(const circuit_type& circuit_in, std::size_t usable_rows, std::size_t table_rows) + : circuit(circuit_in) + , desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) + , constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables) + , assignments(circuit.table) + , table_rows_log(std::log2(table_rows)) + , fri_params(1,table_rows_log, placeholder_test_params::lambda, 4) + { + desc.rows_amount = table_rows; + desc.usable_rows_amount = usable_rows; + } + + bool run_test() { + lpc_scheme_type lpc_scheme(fri_params); + + typename placeholder_public_preprocessor::preprocessed_data_type + lpc_preprocessed_public_data = placeholder_public_preprocessor::process( + constraint_system, assignments.move_public_table(), desc, lpc_scheme, max_quotient_poly_chunks + ); + + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = placeholder_private_preprocessor::process( + constraint_system, assignments.move_private_table(), desc + ); + + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, std::move(lpc_preprocessed_private_data), desc, constraint_system, lpc_scheme + ); + + bool verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, lpc_proof, desc, constraint_system, lpc_scheme + ); + return verifier_res; + } + + circuit_type circuit; + plonk_table_description desc; + typename policy_type::constraint_system_type constraint_system; + typename policy_type::variable_assignment_type assignments; + std::size_t table_rows_log; + typename lpc_type::fri_type::params_type fri_params; +}; + +#endif // CRYPTO3_ZK_TEST_PLACEHOLDER_TEST_RUNNER_HPP +