Skip to content

Commit

Permalink
Updates for test suite #330
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed May 23, 2024
1 parent 1112191 commit edeefb6
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 840 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions test/systems/plonk/placeholder/circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#define _RND_ algebra::random_element<FieldType>();

#include <map>

#include <nil/crypto3/algebra/random_element.hpp>

#include <nil/crypto3/math/polynomial/polynomial.hpp>
Expand Down
207 changes: 47 additions & 160 deletions test/systems/plonk/placeholder/placeholder_circuits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <nil/crypto3/algebra/curves/bls12.hpp>
#include <nil/crypto3/algebra/pairing/bls12.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>
#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>
#include <nil/crypto3/algebra/curves/vesta.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/vesta.hpp>
/*
#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/pairing/alt_bn128.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>
*/
#include <nil/crypto3/algebra/curves/mnt4.hpp>
#include <nil/crypto3/algebra/pairing/mnt4.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt4.hpp>

#include <nil/crypto3/algebra/curves/mnt6.hpp>
#include <nil/crypto3/algebra/pairing/mnt6.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt6.hpp>

#include <nil/crypto3/algebra/fields/arithmetic_params/goldilocks64.hpp>

#include <nil/crypto3/math/algorithms/unity_root.hpp>
#include <nil/crypto3/math/polynomial/lagrange_interpolation.hpp>
#include <nil/crypto3/math/algorithms/calculate_domain_set.hpp>

#include <nil/crypto3/hash/algorithm/hash.hpp>
#include <nil/crypto3/hash/sha2.hpp>
#include <nil/crypto3/hash/md5.hpp>
#include <nil/crypto3/hash/keccak.hpp>
#include <nil/crypto3/hash/poseidon.hpp>

#include <nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/permutation_argument.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/gates_argument.hpp>

#include <nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/detail/placeholder_policy.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/gate.hpp>
#include <nil/crypto3/zk/transcript/fiat_shamir.hpp>
#include <nil/crypto3/zk/commitments/polynomial/fri.hpp>
#include <nil/crypto3/zk/commitments/polynomial/lpc.hpp>
#include <nil/crypto3/zk/commitments/polynomial/kzg.hpp>
#include <nil/crypto3/zk/commitments/polynomial/kzg_v2.hpp>
#include <nil/crypto3/zk/commitments/batched_commitment.hpp>
#include <nil/crypto3/zk/test_tools/random_test_initializer.hpp>

#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<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;
using hash_type = hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;
using test_runner_type = placeholder_test_runner<field_type, hash_type, hash_type>;

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<field_type> random_test_initializer;
auto circuit = circuit_test_1<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;
const size_t usable_rows_3 = 4;
BOOST_AUTO_TEST_CASE(circuit2)
{
test_tools::random_test_initializer<field_type> random_test_initializer;
auto pi0 = random_test_initializer.alg_random_engines.template get_alg_engine<field_type>()();
auto circuit = circuit_test_t<field_type>(
pi0,
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<field_type> random_test_initializer;
auto circuit = circuit_test_3<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;
const size_t usable_rows_4 = 5;

using TestRunners = boost::mpl::list<
placeholder_test_runner<algebra::curves::pallas::base_field_type, poseidon_type, poseidon_type, witness_columns_4, public_columns_4, constant_columns_4, selector_columns_4, usable_rows_4>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, 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<field_type> random_test_initializer;
auto circuit = circuit_test_4<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;

using TestRunners = boost::mpl::list<
placeholder_test_runner<algebra::curves::pallas::base_field_type, poseidon_type, poseidon_type, witness_columns_5, public_columns_5, constant_columns_5, selector_columns_5, usable_rows_5, false, 10>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, 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<field_type> random_test_initializer;
auto circuit = circuit_test_5<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;

using TestRunners = boost::mpl::list<
placeholder_test_runner<algebra::curves::pallas::base_field_type, poseidon_type, poseidon_type, witness_columns_6, public_columns_6, constant_columns_6, selector_columns_6, usable_rows_6, true>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, 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<field_type> random_test_initializer;
auto circuit = circuit_test_6<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<nil::crypto3::hashes::detail::mina_poseidon_policy<field_type>>;

using TestRunners = boost::mpl::list<
placeholder_test_runner<algebra::curves::pallas::base_field_type, poseidon_type, poseidon_type, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 8>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 8>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 10>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, hashes::keccak_1600<256>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, true, 30>,
placeholder_test_runner<algebra::curves::pallas::base_field_type, hashes::keccak_1600<256>, 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<field_type> random_test_initializer;
auto circuit = circuit_test_7<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
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<field_type> random_test_initializer;
auto circuit = circuit_test_fib<field_type, 100>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>()
);
test_runner_type test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}


BOOST_AUTO_TEST_SUITE_END()
91 changes: 91 additions & 0 deletions test/systems/plonk/placeholder/placeholder_curves.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2022 Mikhail Komarov <[email protected]>
// Copyright (c) 2022 Nikita Kaskov <[email protected]>
// Copyright (c) 2022 Ilia Shirobokov <[email protected]>
// Copyright (c) 2022 Alisa Cherniaeva <[email protected]>
// Copyright (c) 2022 Ilias Khairullin <[email protected]>
// Copyright (c) 2023 Elena Tatuzova <[email protected]>
// Copyright (c) 2024 Vasiliy Olekhov <[email protected]>
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//---------------------------------------------------------------------------//
// Test circuit1 on different curves field: pallas, vesta, mnt4, mnt6, bls12
//

#define BOOST_TEST_MODULE placeholder_curves_test

#include <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/curves/vesta.hpp>
#include <nil/crypto3/algebra/curves/mnt4.hpp>
#include <nil/crypto3/algebra/curves/mnt6.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
#include <nil/crypto3/algebra/curves/alt_bn128.hpp>

#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/vesta.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt4.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt6.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/bls12.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>

#include <nil/crypto3/hash/algorithm/hash.hpp>
#include <nil/crypto3/hash/poseidon.hpp>

#include <nil/crypto3/zk/test_tools/random_test_initializer.hpp>

#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<algebra::curves::pallas ::scalar_field_type, hash_type, hash_type>,
placeholder_test_runner<algebra::curves::vesta ::scalar_field_type, hash_type, hash_type>,
placeholder_test_runner<algebra::curves::mnt4_298 ::scalar_field_type, hash_type, hash_type>,
placeholder_test_runner<algebra::curves::mnt6_298 ::scalar_field_type, hash_type, hash_type>,
placeholder_test_runner<algebra::curves::bls12_381 ::scalar_field_type, hash_type, hash_type>,
placeholder_test_runner<algebra::curves::bls12_377 ::scalar_field_type, hash_type, hash_type>,
placeholder_test_runner<algebra::curves::alt_bn128_254::scalar_field_type, hash_type, hash_type>
>;

BOOST_AUTO_TEST_CASE_TEMPLATE(curve_test, TestRunner, TestRunners) {
using field_type = typename TestRunner::field_type;
test_tools::random_test_initializer<field_type> random_test_initializer;
auto circuit = circuit_test_1<field_type>(
random_test_initializer.alg_random_engines.template get_alg_engine<field_type>(),
random_test_initializer.generic_random_engine
);
TestRunner test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}
BOOST_AUTO_TEST_SUITE_END()

Loading

0 comments on commit edeefb6

Please sign in to comment.