From edeefb6d7554e3dddff0155508db708b7493a401 Mon Sep 17 00:00:00 2001 From: Vasiliy Olekhov Date: Thu, 23 May 2024 19:29:07 +0300 Subject: [PATCH] Updates for test suite #330 --- test/CMakeLists.txt | 1 + test/systems/plonk/placeholder/circuits.hpp | 2 + .../placeholder/placeholder_circuits.cpp | 207 +++------- .../plonk/placeholder/placeholder_curves.cpp | 91 +++++ .../placeholder/placeholder_gate_argument.cpp | 73 +--- .../placeholder/placeholder_goldilocks.cpp | 75 +--- .../plonk/placeholder/placeholder_hashes.cpp | 93 +---- .../plonk/placeholder/placeholder_kzg.cpp | 369 ++---------------- .../placeholder_lookup_argument.cpp | 110 ++---- .../placeholder_permutation_argument.cpp | 62 +-- .../placeholder/placeholder_test_runner.hpp | 180 ++++++++- 11 files changed, 423 insertions(+), 840 deletions(-) create mode 100644 test/systems/plonk/placeholder/placeholder_curves.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ac349ec8..faf38e33 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -111,6 +111,7 @@ set(TESTS_NAMES "systems/plonk/placeholder/placeholder_permutation_argument" "systems/plonk/placeholder/placeholder_kzg" "systems/plonk/placeholder/placeholder_hashes" + "systems/plonk/placeholder/placeholder_curves" # "systems/pcd/r1cs_pcd/r1cs_mp_ppzkpcd/r1cs_mp_ppzkpcd" # "systems/pcd/r1cs_pcd/r1cs_sp_ppzkpcd/r1cs_sp_ppzkpcd" diff --git a/test/systems/plonk/placeholder/circuits.hpp b/test/systems/plonk/placeholder/circuits.hpp index 3f97de80..8b128276 100644 --- a/test/systems/plonk/placeholder/circuits.hpp +++ b/test/systems/plonk/placeholder/circuits.hpp @@ -31,6 +31,8 @@ #define _RND_ algebra::random_element(); +#include + #include #include diff --git a/test/systems/plonk/placeholder/placeholder_circuits.cpp b/test/systems/plonk/placeholder/placeholder_circuits.cpp index c5bb3f1f..c7230d69 100644 --- a/test/systems/plonk/placeholder/placeholder_circuits.cpp +++ b/test/systems/plonk/placeholder/placeholder_circuits.cpp @@ -27,230 +27,117 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //---------------------------------------------------------------------------// +// Test all circuits on one set of parameters (pallas and poseidon) +// #define BOOST_TEST_MODULE placeholder_circuits_test #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -/* -#include -#include -#include -*/ -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include "circuits.hpp" #include "placeholder_test_runner.hpp" -BOOST_AUTO_TEST_SUITE(placeholder_circuit1) +BOOST_AUTO_TEST_SUITE(placeholder_circuits) using curve_type = algebra::curves::pallas; using field_type = typename curve_type::base_field_type; -using poseidon_type = hashes::poseidon>; +using hash_type = hashes::poseidon>; +using test_runner_type = placeholder_test_runner; -using TestRunners = boost::mpl::list< - placeholder_test_runner< - algebra::curves::pallas::base_field_type, - poseidon_type, - poseidon_type, - 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 - > ->; - -BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { +BOOST_AUTO_TEST_CASE(circuit1) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_1( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, circuit.usable_rows, circuit.table_rows); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(placeholder_circuit3) - -using curve_type = algebra::curves::pallas; -using field_type = typename curve_type::base_field_type; -using poseidon_type = hashes::poseidon>; -const size_t usable_rows_3 = 4; +BOOST_AUTO_TEST_CASE(circuit2) +{ + test_tools::random_test_initializer random_test_initializer; + auto pi0 = random_test_initializer.alg_random_engines.template get_alg_engine()(); + auto circuit = circuit_test_t( + pi0, + random_test_initializer.alg_random_engines.template get_alg_engine(), + random_test_initializer.generic_random_engine + ); + test_runner_type test_runner(circuit); + BOOST_CHECK(test_runner.run_test()); +} -using TestRunners = boost::mpl::list< - placeholder_test_runner< - algebra::curves::pallas::base_field_type, - poseidon_type, - poseidon_type, - witness_columns_3, - public_columns_3, - constant_columns_3, - selector_columns_3, - usable_rows_3 - >, - placeholder_test_runner< - algebra::curves::pallas::base_field_type, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_3, - public_columns_3, - constant_columns_3, - selector_columns_3, - usable_rows_3 - > ->; -BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { +BOOST_AUTO_TEST_CASE(circuit3) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_3( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, usable_rows_3, 1 << 3); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(placeholder_circuit4) - -using curve_type = algebra::curves::pallas; -using field_type = typename curve_type::base_field_type; -using poseidon_type = hashes::poseidon>; -const size_t usable_rows_4 = 5; -using TestRunners = boost::mpl::list< - placeholder_test_runner, - 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) { +BOOST_AUTO_TEST_CASE(circuit4) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_4( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, usable_rows_4, 1 << 3); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(placeholder_circuit5) -using curve_type = algebra::curves::pallas; -using field_type = typename curve_type::base_field_type; -using poseidon_type = hashes::poseidon>; -using TestRunners = boost::mpl::list< - placeholder_test_runner, - 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) { +BOOST_AUTO_TEST_CASE(circuit5) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_5( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, circuit.usable_rows, circuit.table_rows); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE(placeholder_circuit6) - -using curve_type = algebra::curves::pallas; -using field_type = typename curve_type::base_field_type; -using poseidon_type = hashes::poseidon>; - -using TestRunners = boost::mpl::list< - placeholder_test_runner, - 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) { +BOOST_AUTO_TEST_CASE(circuit6) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_6( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, circuit.usable_rows, circuit.table_rows); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE(placeholder_circuit7) - -using curve_type = algebra::curves::pallas; -using field_type = typename curve_type::base_field_type; -using poseidon_type = hashes::poseidon>; - -using TestRunners = boost::mpl::list< - placeholder_test_runner, - 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) { +BOOST_AUTO_TEST_CASE(circuit7) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_7( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, circuit.usable_rows, circuit.table_rows); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } + +BOOST_AUTO_TEST_CASE(circuit_fib) +{ + test_tools::random_test_initializer random_test_initializer; + auto circuit = circuit_test_fib( + random_test_initializer.alg_random_engines.template get_alg_engine() + ); + test_runner_type test_runner(circuit); + BOOST_CHECK(test_runner.run_test()); +} + + BOOST_AUTO_TEST_SUITE_END() diff --git a/test/systems/plonk/placeholder/placeholder_curves.cpp b/test/systems/plonk/placeholder/placeholder_curves.cpp new file mode 100644 index 00000000..1402474f --- /dev/null +++ b/test/systems/plonk/placeholder/placeholder_curves.cpp @@ -0,0 +1,91 @@ +//---------------------------------------------------------------------------// +// 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 +// Copyright (c) 2024 Vasiliy Olekhov +// +// 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. +//---------------------------------------------------------------------------// +// Test circuit1 on different curves field: pallas, vesta, mnt4, mnt6, bls12 +// + +#define BOOST_TEST_MODULE placeholder_curves_test + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "circuits.hpp" +#include "placeholder_test_runner.hpp" + +using namespace nil::crypto3; +using namespace nil::crypto3::zk; +using namespace nil::crypto3::zk::snark; + + +BOOST_AUTO_TEST_SUITE(placeholder_curves_test) + +using hash_type = hashes::keccak_1600<256>; + +using TestRunners = boost::mpl::list< + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner +>; + +BOOST_AUTO_TEST_CASE_TEMPLATE(curve_test, TestRunner, TestRunners) { + using field_type = typename TestRunner::field_type; + test_tools::random_test_initializer random_test_initializer; + auto circuit = circuit_test_1( + random_test_initializer.alg_random_engines.template get_alg_engine(), + random_test_initializer.generic_random_engine + ); + TestRunner test_runner(circuit); + BOOST_CHECK(test_runner.run_test()); +} +BOOST_AUTO_TEST_SUITE_END() + diff --git a/test/systems/plonk/placeholder/placeholder_gate_argument.cpp b/test/systems/plonk/placeholder/placeholder_gate_argument.cpp index 4d10f533..a829c920 100644 --- a/test/systems/plonk/placeholder/placeholder_gate_argument.cpp +++ b/test/systems/plonk/placeholder/placeholder_gate_argument.cpp @@ -27,53 +27,19 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //---------------------------------------------------------------------------// +// Test gate argument for single circuit - circuit_test_t #define BOOST_TEST_MODULE placeholder_gate_argument_test -#include -#include -#include - #include #include #include #include -#include -#include -#include -#include -#include -#include -/* -#include -#include -#include -*/ -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include - -#include -#include -#include -#include #include #include #include -#include -#include #include #include @@ -83,9 +49,6 @@ #include #include #include -#include -#include -#include #include #include "circuits.hpp" @@ -102,11 +65,6 @@ BOOST_AUTO_TEST_SUITE(placeholder_gate_argument) 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; - constexpr static const std::size_t constant_columns = 0; - constexpr static const std::size_t selector_columns = 2; - constexpr static const std::size_t lambda = 10; constexpr static const std::size_t m = 2; }; @@ -141,14 +99,13 @@ BOOST_FIXTURE_TEST_CASE(placeholder_gate_argument_test, test_tools::random_test_ ); plonk_table_description desc( - placeholder_test_params::witness_columns, - placeholder_test_params::public_input_columns, - placeholder_test_params::constant_columns, - placeholder_test_params::selector_columns - ); + circuit.table.witnesses().size(), + circuit.table.public_inputs().size(), + circuit.table.constants().size(), + circuit.table.selectors().size(), + circuit.usable_rows, + circuit.table_rows); - desc.rows_amount = circuit.table_rows; - desc.usable_rows_amount = circuit.usable_rows; std::size_t table_rows_log = std::log2(desc.rows_amount); typename policy_type::constraint_system_type constraint_system( @@ -195,7 +152,7 @@ BOOST_FIXTURE_TEST_CASE(placeholder_gate_argument_test, test_tools::random_test_ typename field_type::value_type omega = preprocessed_public_data.common_data.basic_domain->get_domain_element(1); typename policy_type::evaluation_map columns_at_y; - for (std::size_t i = 0; i < placeholder_test_params::witness_columns; i++) { + for (std::size_t i = 0; i < desc.witness_columns; i++) { std::size_t i_global_index = i; @@ -204,9 +161,9 @@ BOOST_FIXTURE_TEST_CASE(placeholder_gate_argument_test, test_tools::random_test_ columns_at_y[key] = polynomial_table.witness(i).evaluate(y * omega.pow(rotation)); } } - for (std::size_t i = 0; i < 0 + placeholder_test_params::public_input_columns; i++) { + for (std::size_t i = 0; i < 0 + desc.public_input_columns; i++) { - std::size_t i_global_index = placeholder_test_params::witness_columns + i; + std::size_t i_global_index = desc.witness_columns + i; for (int rotation : preprocessed_public_data.common_data.columns_rotations[i_global_index]) { @@ -215,10 +172,10 @@ BOOST_FIXTURE_TEST_CASE(placeholder_gate_argument_test, test_tools::random_test_ columns_at_y[key] = polynomial_table.public_input(i).evaluate(y * omega.pow(rotation)); } } - for (std::size_t i = 0; i < 0 + placeholder_test_params::constant_columns; i++) { + for (std::size_t i = 0; i < 0 + desc.constant_columns; i++) { std::size_t i_global_index = - placeholder_test_params::witness_columns + placeholder_test_params::public_input_columns + i; + desc.witness_columns + desc.public_input_columns + i; for (int rotation : preprocessed_public_data.common_data.columns_rotations[i_global_index]) { auto key = std::make_tuple(i, rotation, plonk_variable::column_type::constant); @@ -226,11 +183,9 @@ BOOST_FIXTURE_TEST_CASE(placeholder_gate_argument_test, test_tools::random_test_ columns_at_y[key] = polynomial_table.constant(i).evaluate(y * omega.pow(rotation)); } } - for (std::size_t i = 0; i < placeholder_test_params::selector_columns; i++) { + for (std::size_t i = 0; i < desc.selector_columns; i++) { - std::size_t i_global_index = placeholder_test_params::witness_columns + - placeholder_test_params::constant_columns + - placeholder_test_params::public_input_columns + i; + std::size_t i_global_index = desc.witness_columns + desc.constant_columns + desc.public_input_columns + i; for (int rotation : preprocessed_public_data.common_data.columns_rotations[i_global_index]) { auto key = std::make_tuple(i, rotation, plonk_variable::column_type::selector); diff --git a/test/systems/plonk/placeholder/placeholder_goldilocks.cpp b/test/systems/plonk/placeholder/placeholder_goldilocks.cpp index d17de1a7..2a37ed7f 100644 --- a/test/systems/plonk/placeholder/placeholder_goldilocks.cpp +++ b/test/systems/plonk/placeholder/placeholder_goldilocks.cpp @@ -27,65 +27,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //---------------------------------------------------------------------------// +// Test circuit1 on goldilocks field +// #define BOOST_TEST_MODULE placeholder_goldilocks_test -#include -#include -#include - #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -/* -#include -#include -#include -*/ -#include -#include -#include - -#include -#include -#include +#include #include -#include -#include -#include - -#include -#include -#include #include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include "circuits.hpp" @@ -95,30 +48,20 @@ using namespace nil::crypto3; using namespace nil::crypto3::zk; using namespace nil::crypto3::zk::snark; -BOOST_AUTO_TEST_SUITE(placeholder_circuit1_goldilocks) +BOOST_AUTO_TEST_SUITE(placeholder_goldilocks) using field_type = typename algebra::fields::goldilocks64; -using poseidon_type = hashes::poseidon>; +using hash_type = hashes::keccak_1600<256>; +using test_runner_type = placeholder_test_runner; -using TestRunners = boost::mpl::list< - placeholder_test_runner< - 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 - > ->; -BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { +BOOST_AUTO_TEST_CASE(circuit1) +{ test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_1( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, circuit.usable_rows, circuit.table_rows); + test_runner_type test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/systems/plonk/placeholder/placeholder_hashes.cpp b/test/systems/plonk/placeholder/placeholder_hashes.cpp index b40c51b9..99adacc8 100644 --- a/test/systems/plonk/placeholder/placeholder_hashes.cpp +++ b/test/systems/plonk/placeholder/placeholder_hashes.cpp @@ -27,6 +27,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //---------------------------------------------------------------------------// +// Test circuit1 on different hashes: poseidon, keccak<256>, keccak<512>, sha2 +// #define BOOST_TEST_MODULE placeholder_hashes_test @@ -34,54 +36,14 @@ #include #include -#include -#include -#include #include #include -#include -#include -/* -#include -#include -#include -*/ -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include #include #include -#include #include #include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include "circuits.hpp" @@ -97,57 +59,24 @@ BOOST_AUTO_TEST_SUITE(placeholder_hashes_test) using curve_type = algebra::curves::pallas; using field_type = typename curve_type::base_field_type; using poseidon_type = hashes::poseidon>; +using keccak_256_type = hashes::keccak_1600<256>; +using keccak_512_type = hashes::keccak_1600<512>; +using sha2_256_type = hashes::sha2<256>; using TestRunners = boost::mpl::list< - placeholder_test_runner< - algebra::curves::pallas::base_field_type, - poseidon_type, - poseidon_type, - 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::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>, - hashes::keccak_1600<512>, - witness_columns_1, - public_columns_1, - constant_columns_1, - selector_columns_1, - rows_amount_1 - > + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner, + placeholder_test_runner >; -BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { +BOOST_AUTO_TEST_CASE_TEMPLATE(hash_test, TestRunner, TestRunners) { test_tools::random_test_initializer random_test_initializer; auto circuit = circuit_test_1( random_test_initializer.alg_random_engines.template get_alg_engine(), random_test_initializer.generic_random_engine ); - TestRunner test_runner(circuit, circuit.usable_rows, circuit.table_rows); + TestRunner test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/systems/plonk/placeholder/placeholder_kzg.cpp b/test/systems/plonk/placeholder/placeholder_kzg.cpp index 1448e264..27d301c8 100644 --- a/test/systems/plonk/placeholder/placeholder_kzg.cpp +++ b/test/systems/plonk/placeholder/placeholder_kzg.cpp @@ -27,48 +27,26 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //---------------------------------------------------------------------------// +// Test circuit2 with KZG commitment schemes, v1 and v2 on different curves +// #define BOOST_TEST_MODULE placeholder_kzg_test -#include -#include -#include - #include #include -#include -#include -#include -#include -#include -#include -#include -#include -/* -#include -#include -#include -*/ #include #include #include - #include #include #include -#include - -#include -#include -#include +#include +#include #include -#include -#include #include -#include #include #include @@ -81,343 +59,60 @@ #include #include #include -#include -#include #include #include #include #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 -typename kzg_type::params_type create_kzg_params(std::size_t degree_log) { - // TODO: what cases t != d? - typename kzg_type::field_type::value_type alpha (7); - std::size_t d = 1 << degree_log; - - typename kzg_type::params_type params(d, d, alpha); - return params; -} - -template -typename kzg_type::params_type create_kzg_v2_params(std::size_t degree_log) { - // TODO: what cases t != d? - typename kzg_type::field_type::value_type alpha (7); - std::size_t d = 1 << degree_log; - - typename kzg_type::params_type params(d, 1, alpha); - return params; -} - - -template< - typename curve_type, - typename merkle_hash_type, - typename transcript_hash_type, - std::size_t WitnessColumns, - std::size_t PublicInputColumns, - std::size_t ConstantColumns, - std::size_t SelectorColumns, - std::size_t usable_rows_amount, - std::size_t permutation, - bool UseGrinding = false> -struct placeholder_kzg_test_runner { - using field_type = typename curve_type::scalar_field_type; - - struct placeholder_test_params { - constexpr static const std::size_t usable_rows = usable_rows_amount; - - 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; - }; - - using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; - - using circuit_params = placeholder_circuit_params; - - using kzg_type = commitments::batched_kzg; - using kzg_scheme_type = typename commitments::kzg_commitment_scheme; - using kzg_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; - - using policy_type = zk::snark::detail::placeholder_policy; - - using circuit_type = - circuit_description >; - - placeholder_kzg_test_runner() - : desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) - { - } - - bool run_test() { - test_tools::random_test_initializer random_test_initializer; - auto pi0 = random_test_initializer.alg_random_engines.template get_alg_engine()(); - auto circuit = circuit_test_t( - pi0, - random_test_initializer.alg_random_engines.template get_alg_engine(), - random_test_initializer.generic_random_engine - ); - desc.rows_amount = circuit.table_rows; - desc.usable_rows_amount = circuit.usable_rows; - std::size_t table_rows_log = std::log2(circuit.table_rows); - - typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); - typename policy_type::variable_assignment_type assignments = circuit.table; - - bool verifier_res; - - // KZG commitment scheme - auto kzg_params = create_kzg_params(table_rows_log); - kzg_scheme_type kzg_scheme(kzg_params); - - typename placeholder_public_preprocessor::preprocessed_data_type - kzg_preprocessed_public_data = - placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, kzg_scheme - ); - - typename placeholder_private_preprocessor::preprocessed_data_type - kzg_preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc - ); - - auto kzg_proof = placeholder_prover::process( - kzg_preprocessed_public_data, std::move(kzg_preprocessed_private_data), desc, constraint_system, kzg_scheme - ); - - verifier_res = placeholder_verifier::process( - kzg_preprocessed_public_data.common_data, kzg_proof, desc, constraint_system, kzg_scheme - ); - return verifier_res; - } - - plonk_table_description desc; -}; - +using hash_type = hashes::keccak_1600<256>; BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg) using TestRunners = boost::mpl::list< - placeholder_kzg_test_runner< - algebra::curves::bls12<381>, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - /* - , placeholder_kzg_test_runner< - algebra::curves::alt_bn128_254, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - 4, true>*/ - , placeholder_kzg_test_runner< - algebra::curves::mnt4_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - , placeholder_kzg_test_runner< - algebra::curves::mnt6_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - /*, -- Not yet implemented - placeholder_kzg_test_runner< - algebra::curves::mnt6_298, - hashes::poseidon>, - hashes::poseidon>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - 4, - true> - */ + placeholder_kzg_test_runner, + placeholder_kzg_test_runner >; -BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { - TestRunner test_runner; +BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_test, TestRunner, TestRunners) +{ + using field_type = typename TestRunner::field_type; + test_tools::random_test_initializer random_test_initializer; + auto pi0 = random_test_initializer.alg_random_engines.template get_alg_engine()(); + auto circuit = circuit_test_t( + pi0, + random_test_initializer.alg_random_engines.template get_alg_engine(), + random_test_initializer.generic_random_engine + ); + TestRunner test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } BOOST_AUTO_TEST_SUITE_END() - -template< - typename curve_type, - typename merkle_hash_type, - typename transcript_hash_type, - std::size_t WitnessColumns, - std::size_t PublicInputColumns, - std::size_t ConstantColumns, - std::size_t SelectorColumns, - std::size_t usable_rows_amount, - std::size_t permutation, - bool UseGrinding = false> -struct placeholder_kzg_test_runner_v2 { - using field_type = typename curve_type::scalar_field_type; - - struct placeholder_test_params { - constexpr static const std::size_t usable_rows = usable_rows_amount; - - 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; - }; - - using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; - - using circuit_params = placeholder_circuit_params; - - using kzg_type = commitments::batched_kzg; - using kzg_scheme_type = typename commitments::kzg_commitment_scheme_v2; - using kzg_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; - - using policy_type = zk::snark::detail::placeholder_policy; - - using circuit_type = - circuit_description>; - - placeholder_kzg_test_runner_v2() - : desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) - { - } - - bool run_test() { - test_tools::random_test_initializer random_test_initializer; - auto pi0 = random_test_initializer.alg_random_engines.template get_alg_engine()(); - auto circuit = circuit_test_t( - pi0, - random_test_initializer.alg_random_engines.template get_alg_engine(), - random_test_initializer.generic_random_engine - ); - desc.rows_amount = circuit.table_rows; - desc.usable_rows_amount = circuit.usable_rows; - std::size_t table_rows_log = std::log2(circuit.table_rows); - - typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); - typename policy_type::variable_assignment_type assignments = circuit.table; - - bool verifier_res; - - // KZG commitment scheme - auto kzg_params = create_kzg_v2_params(table_rows_log); - kzg_scheme_type kzg_scheme(kzg_params); - - typename placeholder_public_preprocessor::preprocessed_data_type - kzg_preprocessed_public_data = - placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, kzg_scheme - ); - - typename placeholder_private_preprocessor::preprocessed_data_type - kzg_preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc - ); - - auto kzg_proof = placeholder_prover::process( - kzg_preprocessed_public_data, std::move(kzg_preprocessed_private_data), desc, constraint_system, kzg_scheme - ); - - verifier_res = placeholder_verifier::process( - kzg_preprocessed_public_data.common_data, kzg_proof, desc, constraint_system, kzg_scheme - ); - return verifier_res; - } - - plonk_table_description desc; -}; - - BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2) using TestRunners = boost::mpl::list< - placeholder_kzg_test_runner_v2< - algebra::curves::bls12_381, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> -/* , placeholder_kzg_test_runner< - algebra::curves::alt_bn128_254, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - 4, true>*/ - , placeholder_kzg_test_runner< - algebra::curves::mnt4_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - , placeholder_kzg_test_runner_v2< - algebra::curves::mnt6_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - /*, -- Not yet implemented - placeholder_kzg_test_runner< - algebra::curves::mnt6_298, - hashes::poseidon>, - hashes::poseidon>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - 4, - true> - */ + placeholder_kzg_test_runner_v2, + placeholder_kzg_test_runner_v2 >; -BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, TestRunner, TestRunners) { - TestRunner test_runner; +BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_v2_test, TestRunner, TestRunners) +{ + using field_type = typename TestRunner::field_type; + test_tools::random_test_initializer random_test_initializer; + auto pi0 = random_test_initializer.alg_random_engines.template get_alg_engine()(); + auto circuit = circuit_test_t( + pi0, + random_test_initializer.alg_random_engines.template get_alg_engine(), + random_test_initializer.generic_random_engine + ); + TestRunner test_runner(circuit); BOOST_CHECK(test_runner.run_test()); } - BOOST_AUTO_TEST_SUITE_END() diff --git a/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp b/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp index acd608ff..52788ecb 100644 --- a/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp +++ b/test/systems/plonk/placeholder/placeholder_lookup_argument.cpp @@ -27,38 +27,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //---------------------------------------------------------------------------// +// Lookup argument test for circuits circuit3 and circuit4 #define BOOST_TEST_MODULE placeholder_lookup_argument_test -#include -#include -#include - #include #include -#include -#include -#include -#include #include #include -#include -#include -/* -#include -#include -#include -*/ -#include -#include -#include - -#include -#include -#include - -#include #include #include @@ -83,9 +60,8 @@ #include #include #include -#include -#include #include + #include #include "circuits.hpp" @@ -98,19 +74,10 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit3_lookup_test) using curve_type = algebra::curves::pallas; using field_type = typename curve_type::base_field_type; - constexpr static const std::size_t table_rows_log = 3; - constexpr static const std::size_t table_rows = 1 << table_rows_log; - constexpr static const std::size_t usable_rows = 4; - struct placeholder_test_params { 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; - constexpr static const std::size_t constant_columns = constant_columns_3; - constexpr static const std::size_t selector_columns = selector_columns_3; - constexpr static const std::size_t lambda = 40; constexpr static const std::size_t m = 2; }; @@ -136,14 +103,14 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer desc( - placeholder_test_params::witness_columns, - placeholder_test_params::public_input_columns, - placeholder_test_params::constant_columns, - placeholder_test_params::selector_columns - ); + circuit.table.witnesses().size(), + circuit.table.public_inputs().size(), + circuit.table.constants().size(), + circuit.table.selectors().size(), + circuit.usable_rows, + circuit.table_rows); - desc.rows_amount = table_rows; - desc.usable_rows_amount = usable_rows; + std::size_t table_rows_log = std::log2(desc.rows_amount); typename policy_type::constraint_system_type constraint_system( circuit.gates, @@ -181,7 +148,7 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer(); typename policy_type::evaluation_map columns_at_y; - for (std::size_t i = 0; i < placeholder_test_params::witness_columns; i++) { + for (std::size_t i = 0; i < desc.witness_columns; i++) { std::size_t i_global_index = i; @@ -191,10 +158,10 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer::column_type::constant); @@ -203,11 +170,11 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer::column_type::selector); @@ -218,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer; 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; - constexpr static const std::size_t constant_columns = constant_columns_4; - constexpr static const std::size_t selector_columns = selector_columns_4; - constexpr static const std::size_t lambda = 40; constexpr static const std::size_t m = 2; }; @@ -311,14 +269,14 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer desc( - placeholder_test_params::witness_columns, - placeholder_test_params::public_input_columns, - placeholder_test_params::constant_columns, - placeholder_test_params::selector_columns - ); + circuit.table.witnesses().size(), + circuit.table.public_inputs().size(), + circuit.table.constants().size(), + circuit.table.selectors().size(), + circuit.usable_rows, + circuit.table_rows); - desc.rows_amount = table_rows; - desc.usable_rows_amount = usable_rows; + std::size_t table_rows_log = std::log2(desc.rows_amount); typename policy_type::constraint_system_type constraint_system( circuit.gates, @@ -358,7 +316,7 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializerget_domain_element(1); typename field_type::value_type y = alg_random_engines.template get_alg_engine()(); typename policy_type::evaluation_map columns_at_y; - for (std::size_t i = 0; i < placeholder_test_params::witness_columns; i++) { + for (std::size_t i = 0; i < desc.witness_columns; i++) { std::size_t i_global_index = i; @@ -368,10 +326,10 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer::column_type::constant); @@ -381,11 +339,11 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer::column_type::selector); @@ -396,7 +354,7 @@ BOOST_FIXTURE_TEST_CASE(lookup_test, test_tools::random_test_initializer -#include -#include - #include #include #include @@ -41,34 +39,13 @@ #include #include #include -#include -#include -#include -#include -/* -#include -#include -#include -*/ -#include -#include -#include - -#include -#include -#include - -#include #include #include #include #include -#include -#include #include -#include #include #include @@ -83,8 +60,6 @@ #include #include #include -#include -#include #include #include @@ -102,11 +77,6 @@ BOOST_AUTO_TEST_SUITE(permutation_argument) 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; - constexpr static const std::size_t constant_columns = 0; - constexpr static const std::size_t selector_columns = 2; - constexpr static const std::size_t lambda = 10; constexpr static const std::size_t m = 2; }; @@ -141,13 +111,13 @@ BOOST_FIXTURE_TEST_CASE(permutation_polynomials_test, test_tools::random_test_in ); plonk_table_description desc( - placeholder_test_params::witness_columns, - placeholder_test_params::public_input_columns, - placeholder_test_params::constant_columns, - placeholder_test_params::selector_columns - ); - desc.rows_amount = circuit.table_rows; - desc.usable_rows_amount = circuit.usable_rows; + circuit.table.witnesses().size(), + circuit.table.public_inputs().size(), + circuit.table.constants().size(), + circuit.table.selectors().size(), + circuit.usable_rows, + circuit.table_rows); + std::size_t table_rows_log = std::log2(desc.rows_amount); typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, @@ -242,13 +212,13 @@ BOOST_FIXTURE_TEST_CASE(permutation_argument_test, test_tools::random_test_initi ); plonk_table_description desc( - placeholder_test_params::witness_columns, - placeholder_test_params::public_input_columns, - placeholder_test_params::constant_columns, - placeholder_test_params::selector_columns - ); - desc.rows_amount = circuit.table_rows; - desc.usable_rows_amount = circuit.usable_rows; + circuit.table.witnesses().size(), + circuit.table.public_inputs().size(), + circuit.table.constants().size(), + circuit.table.selectors().size(), + circuit.usable_rows, + circuit.table_rows); + std::size_t table_rows_log = std::log2(desc.rows_amount); const std::size_t argument_size = 3; diff --git a/test/systems/plonk/placeholder/placeholder_test_runner.hpp b/test/systems/plonk/placeholder/placeholder_test_runner.hpp index 2b13e5c8..47837fdd 100644 --- a/test/systems/plonk/placeholder/placeholder_test_runner.hpp +++ b/test/systems/plonk/placeholder/placeholder_test_runner.hpp @@ -5,6 +5,7 @@ // Copyright (c) 2022 Alisa Cherniaeva // Copyright (c) 2022 Ilias Khairullin // Copyright (c) 2023 Elena Tatuzova +// Copyright (c) 2024 Vasiliy Olekhov // // MIT License // @@ -29,7 +30,18 @@ #ifndef CRYPTO3_ZK_TEST_PLACEHOLDER_TEST_RUNNER_HPP #define CRYPTO3_ZK_TEST_PLACEHOLDER_TEST_RUNNER_HPP -#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include #include "circuits.hpp" @@ -37,13 +49,10 @@ using namespace nil::crypto3; using namespace nil::crypto3::zk; using namespace nil::crypto3::zk::snark; - -template struct placeholder_test_runner { @@ -69,16 +78,19 @@ struct placeholder_test_runner { 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) + placeholder_test_runner(const circuit_type& circuit_in) : circuit(circuit_in) - , desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns) + , desc( circuit_in.table.witnesses().size(), + circuit_in.table.public_inputs().size(), + circuit_in.table.constants().size(), + circuit_in.table.selectors().size(), + circuit_in.usable_rows, + circuit_in.table_rows) , constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables) , assignments(circuit.table) - , table_rows_log(std::log2(table_rows)) + , table_rows_log(std::log2(circuit_in.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() { @@ -112,5 +124,145 @@ struct placeholder_test_runner { typename lpc_type::fri_type::params_type fri_params; }; -#endif // CRYPTO3_ZK_TEST_PLACEHOLDER_TEST_RUNNER_HPP +template< + typename curve_type, + typename transcript_hash_type, + bool UseGrinding = false> +struct placeholder_kzg_test_runner { + using field_type = typename curve_type::scalar_field_type; + + using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; + + using circuit_params = placeholder_circuit_params; + + using kzg_type = commitments::batched_kzg; + using kzg_scheme_type = typename commitments::kzg_commitment_scheme; + using kzg_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; + + using policy_type = zk::snark::detail::placeholder_policy; + + using circuit_type = + circuit_description >; + + placeholder_kzg_test_runner(const circuit_type& circuit_in) + : circuit(circuit_in), + desc(circuit_in.table.witnesses().size(), + circuit_in.table.public_inputs().size(), + circuit_in.table.constants().size(), + circuit_in.table.selectors().size(), + circuit_in.usable_rows, + circuit_in.table_rows) + { + } + + bool run_test() { + + typename policy_type::constraint_system_type + constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); + typename policy_type::variable_assignment_type + assignments = circuit.table; + + bool verifier_res; + + std::size_t d = circuit.table_rows; + std::size_t t = d; + typename kzg_scheme_type::params_type kzg_params(d, t); + kzg_scheme_type kzg_scheme(kzg_params); + + typename placeholder_public_preprocessor::preprocessed_data_type + kzg_preprocessed_public_data = + placeholder_public_preprocessor::process( + constraint_system, assignments.public_table(), desc, kzg_scheme + ); + + typename placeholder_private_preprocessor::preprocessed_data_type + kzg_preprocessed_private_data = placeholder_private_preprocessor::process( + constraint_system, assignments.private_table(), desc + ); + + auto kzg_proof = placeholder_prover::process( + kzg_preprocessed_public_data, std::move(kzg_preprocessed_private_data), desc, constraint_system, kzg_scheme + ); + + verifier_res = placeholder_verifier::process( + kzg_preprocessed_public_data.common_data, kzg_proof, desc, constraint_system, kzg_scheme + ); + return verifier_res; + } + + circuit_type circuit; + plonk_table_description desc; +}; + +template< + typename curve_type, + typename transcript_hash_type, + bool UseGrinding = false> +struct placeholder_kzg_test_runner_v2 { + using field_type = typename curve_type::scalar_field_type; + + using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; + + using circuit_params = placeholder_circuit_params; + + using kzg_type = commitments::batched_kzg; + using kzg_scheme_type = typename commitments::kzg_commitment_scheme_v2; + using kzg_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; + + using policy_type = zk::snark::detail::placeholder_policy; + + using circuit_type = + circuit_description>; + + placeholder_kzg_test_runner_v2(const circuit_type& circuit_in) + : circuit(circuit_in), + desc(circuit_in.table.witnesses().size(), + circuit_in.table.public_inputs().size(), + circuit_in.table.constants().size(), + circuit_in.table.selectors().size(), + circuit_in.usable_rows, + circuit_in.table_rows) + { + } + + bool run_test() { + typename policy_type::constraint_system_type + constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); + typename policy_type::variable_assignment_type + assignments = circuit.table; + + bool verifier_res; + + typename kzg_type::field_type::value_type alpha (7); + auto kzg_params = kzg_scheme_type::create_params(circuit.table_rows, alpha); + kzg_scheme_type kzg_scheme(kzg_params); + + typename placeholder_public_preprocessor::preprocessed_data_type + kzg_preprocessed_public_data = + placeholder_public_preprocessor::process( + constraint_system, assignments.public_table(), desc, kzg_scheme + ); + + typename placeholder_private_preprocessor::preprocessed_data_type + kzg_preprocessed_private_data = placeholder_private_preprocessor::process( + constraint_system, assignments.private_table(), desc + ); + + auto kzg_proof = placeholder_prover::process( + kzg_preprocessed_public_data, std::move(kzg_preprocessed_private_data), desc, constraint_system, kzg_scheme + ); + + verifier_res = placeholder_verifier::process( + kzg_preprocessed_public_data.common_data, kzg_proof, desc, constraint_system, kzg_scheme + ); + return verifier_res; + } + + circuit_type circuit; + plonk_table_description desc; +}; + +#endif // CRYPTO3_ZK_TEST_PLACEHOLDER_TEST_RUNNER_HPP