Skip to content

Commit

Permalink
Split placeholder tests #330
Browse files Browse the repository at this point in the history
tests update

cmake bump #330

Updated circuit_description, keccak-256, sha2-256 #330

Updates for test suite #330

Added quotient polynomial chunks test #330
  • Loading branch information
vo-nil committed May 24, 2024
1 parent ca5f455 commit c39727c
Show file tree
Hide file tree
Showing 14 changed files with 1,808 additions and 27 deletions.
11 changes: 10 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ 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"
"systems/plonk/placeholder/placeholder_kzg"
"systems/plonk/placeholder/placeholder_hashes"
"systems/plonk/placeholder/placeholder_curves"
"systems/plonk/placeholder/placeholder_quotient_polynomial_chunks"

# "systems/pcd/r1cs_pcd/r1cs_mp_ppzkpcd/r1cs_mp_ppzkpcd"
# "systems/pcd/r1cs_pcd/r1cs_sp_ppzkpcd/r1cs_sp_ppzkpcd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#ifndef CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP
#define CRYPTO3_ZK_TEST_TOOLS_RANDOM_TEST_INITIALIZER_HPP

#include <boost/test/included/unit_test.hpp>
#include <regex>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/random/algebraic_random_device.hpp>
#include <nil/crypto3/random/algebraic_engine.hpp>
Expand Down
53 changes: 28 additions & 25 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 All @@ -54,7 +56,7 @@ namespace nil {
namespace crypto3 {
namespace zk {
namespace snark {
template<typename FieldType, typename ParamsType, std::size_t usable_rows_amount>
template<typename FieldType, typename ParamsType>
class circuit_description {
typedef zk::snark::detail::placeholder_policy<FieldType, ParamsType> policy_type;

Expand All @@ -63,7 +65,7 @@ namespace nil {

public:
std::size_t table_rows;
std::size_t usable_rows = usable_rows_amount;
std::size_t usable_rows;

typename policy_type::variable_assignment_type table;

Expand Down Expand Up @@ -96,14 +98,12 @@ namespace nil {
const std::size_t rows_amount_1 = 13;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, rows_amount_1> circuit_test_1(
circuit_description<FieldType, placeholder_circuit_params<FieldType>> circuit_test_1(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
) {
using assignment_type = typename FieldType::value_type;

constexpr static const std::size_t usable_rows = rows_amount_1;

constexpr static const std::size_t witness_columns = witness_columns_1;
constexpr static const std::size_t public_columns = public_columns_1;
constexpr static const std::size_t constant_columns = constant_columns_1;
Expand All @@ -112,7 +112,8 @@ namespace nil {
witness_columns + public_columns + constant_columns;

typedef placeholder_circuit_params<FieldType> circuit_params;
circuit_description<FieldType, circuit_params, usable_rows> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.usable_rows = rows_amount_1;
std::vector<std::vector<typename FieldType::value_type>> table(table_columns);

std::vector<typename FieldType::value_type> q_add(test_circuit.usable_rows);
Expand Down Expand Up @@ -229,15 +230,14 @@ namespace nil {
constexpr static const std::size_t usable_rows_t = 5;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, usable_rows_t>
circuit_description<FieldType, placeholder_circuit_params<FieldType>>
circuit_test_t(
typename FieldType::value_type pi0 = 0u,
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
) {
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;
Expand All @@ -247,8 +247,9 @@ namespace nil {

typedef placeholder_circuit_params<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.public_input_sizes = {3};
test_circuit.usable_rows = usable_rows_t;

std::vector<std::vector<typename FieldType::value_type>> table(table_columns);

Expand Down Expand Up @@ -362,7 +363,7 @@ namespace nil {
constexpr static const std::size_t usable_rows_3 = 4;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, usable_rows_3> circuit_test_3(
circuit_description<FieldType, placeholder_circuit_params<FieldType>> circuit_test_3(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
) {
Expand All @@ -374,11 +375,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<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.usable_rows = usable_rows_3;

std::vector<std::vector<typename FieldType::value_type>> table(table_columns);
for (std::size_t j = 0; j < table_columns; j++) {
Expand Down Expand Up @@ -467,7 +468,7 @@ namespace nil {
constexpr static const std::size_t selector_columns_4 = 3;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, 5> circuit_test_4(
circuit_description<FieldType, placeholder_circuit_params<FieldType>> circuit_test_4(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
) {
Expand All @@ -484,8 +485,9 @@ namespace nil {

typedef placeholder_circuit_params<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, 5> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.table_rows = 1 << rows_log;
test_circuit.usable_rows = 5;

std::vector<std::vector<typename FieldType::value_type>> table(table_columns);
for (std::size_t j = 0; j < table_columns; j++) {
Expand Down Expand Up @@ -579,25 +581,23 @@ namespace nil {
constexpr static const std::size_t usable_rows_5 = 30;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, usable_rows_5>
circuit_description<FieldType, placeholder_circuit_params<FieldType>>
circuit_test_5(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
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<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.public_input_sizes = {witness_columns};
test_circuit.usable_rows = usable_rows_5;

std::vector<std::vector<typename FieldType::value_type>> private_assignment(witness_columns);
std::vector<std::vector<typename FieldType::value_type>> public_input_assignment(public_input_columns);
Expand Down Expand Up @@ -657,7 +657,7 @@ namespace nil {
constexpr static const std::size_t selector_columns_fib = 1;

template<typename FieldType, std::size_t usable_rows>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, usable_rows>
circuit_description<FieldType, placeholder_circuit_params<FieldType> >
circuit_test_fib(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>()
) {
Expand All @@ -672,7 +672,8 @@ namespace nil {

typedef placeholder_circuit_params<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.usable_rows = usable_rows;
std::vector<std::vector<typename FieldType::value_type>> table(table_columns);

std::vector<typename FieldType::value_type> q_add(test_circuit.usable_rows);
Expand Down Expand Up @@ -774,7 +775,7 @@ namespace nil {
constexpr static const std::size_t usable_rows_6 = 6;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, usable_rows_6> circuit_test_6(
circuit_description<FieldType, placeholder_circuit_params<FieldType>> circuit_test_6(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
) {
Expand All @@ -789,7 +790,8 @@ namespace nil {

typedef placeholder_circuit_params<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows_6> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.usable_rows = usable_rows_6;

std::vector<std::vector<typename FieldType::value_type>> table(table_columns);
for (std::size_t j = 0; j < table_columns; j++) {
Expand Down Expand Up @@ -914,7 +916,7 @@ namespace nil {
constexpr static const std::size_t usable_rows_7 = 14;

template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType>, usable_rows_7> circuit_test_7(
circuit_description<FieldType, placeholder_circuit_params<FieldType>> circuit_test_7(
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
) {
Expand All @@ -929,7 +931,8 @@ namespace nil {

typedef placeholder_circuit_params<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows_7> test_circuit;
circuit_description<FieldType, circuit_params> test_circuit;
test_circuit.usable_rows = usable_rows_7;

std::vector<std::vector<typename FieldType::value_type>> table(table_columns);
for (std::size_t j = 0; j < table_columns; j++) {
Expand Down
143 changes: 143 additions & 0 deletions test/systems/plonk/placeholder/placeholder_circuits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//---------------------------------------------------------------------------//
// 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 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 <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"

BOOST_AUTO_TEST_SUITE(placeholder_circuits)

using curve_type = algebra::curves::pallas;
using field_type = typename curve_type::base_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>;

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
);
test_runner_type test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}

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());
}

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
);
test_runner_type test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}

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
);
test_runner_type test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}

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
);
test_runner_type test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}

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
);
test_runner_type test_runner(circuit);
BOOST_CHECK(test_runner.run_test());
}

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
);
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()
Loading

0 comments on commit c39727c

Please sign in to comment.