diff --git a/.github/workflows/pull-request-action.yml b/.github/workflows/pull-request-action.yml index 1d790bdec..b75dee03f 100644 --- a/.github/workflows/pull-request-action.yml +++ b/.github/workflows/pull-request-action.yml @@ -11,9 +11,9 @@ on: jobs: handle-syncwith: name: Call Reusable SyncWith Handler - uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1.1.0 + uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1.2.0 with: - ci-cd-ref: 'v1.1.3' + ci-cd-ref: 'v1.2.0' secrets: inherit matrix-test-linux: diff --git a/include/nil/crypto3/zk/transcript/fiat_shamir.hpp b/include/nil/crypto3/zk/transcript/fiat_shamir.hpp index 93f6c3b68..a863a8154 100644 --- a/include/nil/crypto3/zk/transcript/fiat_shamir.hpp +++ b/include/nil/crypto3/zk/transcript/fiat_shamir.hpp @@ -30,12 +30,23 @@ #include #include +#include #include #include #include -#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include namespace nil { namespace crypto3 { namespace zk { @@ -116,8 +127,9 @@ namespace nil { } }; - template - struct fiat_shamir_heuristic_sequential { + template + struct fiat_shamir_heuristic_sequential + { typedef Hash hash_type; fiat_shamir_heuristic_sequential() : state(hash({0})) { @@ -184,6 +196,85 @@ namespace nil { private: typename hash_type::digest_type state; }; + + // Specialize for posseidon. + template + struct fiat_shamir_heuristic_sequential< + Hash, + typename std::enable_if_t::value>> { + + typedef Hash hash_type; + using field_type = nil::crypto3::algebra::curves::pallas::base_field_type; + using poseidon_policy = nil::crypto3::hashes::detail::mina_poseidon_policy; + using permutation_type = nil::crypto3::hashes::detail::poseidon_permutation; + using state_type = typename permutation_type::state_type; + + fiat_shamir_heuristic_sequential() { + } + + template + fiat_shamir_heuristic_sequential(const InputRange &r) { + sponge.absorb(hash(r)); + } + + template + fiat_shamir_heuristic_sequential(InputIterator first, InputIterator last) { + sponge.absorb(hash(first, last)); + } + + void operator()(const typename hash_type::digest_type input) { + sponge.absorb(input); + } + + template + void operator()(const InputRange &r) { + sponge.absorb(hash(r)); + } + + template + void operator()(InputIterator first, InputIterator last) { + sponge.absorb(hash(first, last)); + } + + template + typename Field::value_type challenge() { + return sponge.squeeze(); + } + + template + Integral int_challenge() { + auto c = challenge(); + nil::marshalling::status_type status; + + nil::crypto3::multiprecision::cpp_int intermediate_result = + c.data.template convert_to(); + Integral result = 0; + Integral factor = 1; + size_t bytes_to_fill = sizeof(Integral); + while (intermediate_result > 0 && bytes_to_fill != 0) { + result += factor * (Integral)(intermediate_result % 0x100); + factor *= 0x100; + intermediate_result = intermediate_result / 0x100; + bytes_to_fill -= 2; + } + return result; + } + + template + std::array challenges() { + + std::array result; + for (auto &ch : result) { + ch = challenge(); + } + + return result; + } + + private: + hashes::detail::poseidon_sponge_construction sponge; + }; + } // namespace transcript } // namespace zk } // namespace crypto3 diff --git a/test/systems/plonk/placeholder/circuits.hpp b/test/systems/plonk/placeholder/circuits.hpp index dcd2c2c26..7ef993718 100644 --- a/test/systems/plonk/placeholder/circuits.hpp +++ b/test/systems/plonk/placeholder/circuits.hpp @@ -486,7 +486,7 @@ namespace nil { template circuit_description, 3, 3> circuit_test_4( + arithmetization_params_4>, 5, 3> circuit_test_4( typename nil::crypto3::random::algebraic_engine alg_rnd = nil::crypto3::random::algebraic_engine(), boost::random::mt11213b rnd = boost::random::mt11213b() ) { @@ -504,7 +504,8 @@ namespace nil { typedef placeholder_circuit_params circuit_params; - circuit_description test_circuit; + circuit_description test_circuit; + test_circuit.table_rows = 1 << rows_log; std::array, table_columns> table; for (std::size_t j = 0; j < table_columns; j++) { @@ -534,18 +535,9 @@ namespace nil { std::array, public_columns> public_input_assignment = {}; std::array, constant_columns> constant_assignment; - std::vector sel_lookup(test_circuit.table_rows); - sel_lookup ={1, 1, 0, 1, 1, 0, 0, 0}; - selectors_assignment[0] = sel_lookup; - - std::vector sel_gate0(test_circuit.table_rows); - sel_gate0 = {1, 1, 1, 1, 1, 0, 0, 0}; - selectors_assignment[1] = sel_gate0; - - - std::vector sel_lookup_table(test_circuit.table_rows); - sel_lookup_table = {0, 1, 1, 1, 1, 0, 0, 0}; - selectors_assignment[2] = sel_lookup_table; + selectors_assignment[0] = {1, 1, 0, 1, 1, 0, 0, 0}; + selectors_assignment[1] = {1, 1, 1, 1, 1, 0, 0, 0}; + selectors_assignment[2] = {0, 1, 1, 1, 1, 0, 0, 0}; for (std::size_t i = 0; i < constant_columns; i++) { constant_assignment[i] = table[witness_columns + i]; @@ -555,6 +547,7 @@ namespace nil { plonk_public_assignment_table( public_input_assignment, constant_assignment, selectors_assignment)); + plonk_variable w0(0, 0, true, plonk_variable::column_type::witness); plonk_variable w1(1, 0, true, plonk_variable::column_type::witness); plonk_variable w2(2, 0, true, plonk_variable::column_type::witness); diff --git a/test/systems/plonk/placeholder/placeholder.cpp b/test/systems/plonk/placeholder/placeholder.cpp index dc0eeed87..25047cf75 100644 --- a/test/systems/plonk/placeholder/placeholder.cpp +++ b/test/systems/plonk/placeholder/placeholder.cpp @@ -57,12 +57,14 @@ #include #include #include +#include #include #include #include #include -// #include +#include + #include #include #include @@ -225,19 +227,20 @@ struct test_initializer { } }; -BOOST_AUTO_TEST_SUITE(placeholder_circuit1) - using curve_type = algebra::curves::pallas; +template +struct placeholder_test_fixture : public test_initializer { + using curve_type = CurveType; using field_type = typename curve_type::base_field_type; - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; struct placeholder_test_params { constexpr static const std::size_t usable_rows = 13; - constexpr static const std::size_t witness_columns = witness_columns_1; - constexpr static const std::size_t public_input_columns = public_columns_1; - constexpr static const std::size_t constant_columns = constant_columns_1; - constexpr static const std::size_t selector_columns = selector_columns_1; + 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 arithmetization_params = plonk_arithmetization_params; @@ -245,6 +248,7 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit1) 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; @@ -252,51 +256,63 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit1) merkle_hash_type, transcript_hash_type, placeholder_test_params::lambda, - placeholder_test_params::m + placeholder_test_params::m, + UseGrinding >; 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, permutation>; + + placeholder_test_fixture(const circuit_type& circuit_in, std::size_t usable_rows, std::size_t table_rows) + : circuit(circuit_in) + , 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(create_fri_params(table_rows_log)) + { + desc.rows_amount = table_rows; + desc.usable_rows_amount = usable_rows; + } -BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { - auto circuit = circuit_test_1(test_global_alg_rnd_engine); - - plonk_table_description desc; + bool run_test() { + test_initializer::setup(); + lpc_scheme_type lpc_scheme(fri_params); - 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(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); - typename policy_type::variable_assignment_type assignments = circuit.table; + std::vector columns_with_copy_constraints = {0, 1, 2, 3}; - std::vector columns_with_copy_constraints = {0, 1, 2, 3}; + typename placeholder_public_preprocessor::preprocessed_data_type + lpc_preprocessed_public_data = placeholder_public_preprocessor::process( + constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size() + ); - typename lpc_type::fri_type::params_type fri_params = create_fri_params(table_rows_log); - lpc_scheme_type lpc_scheme(fri_params); + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = placeholder_private_preprocessor::process( + constraint_system, assignments.private_table(), desc + ); - typename placeholder_public_preprocessor::preprocessed_data_type - lpc_preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size() + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, lpc_preprocessed_private_data, desc, constraint_system, assignments, lpc_scheme ); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc + bool verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data, lpc_proof, constraint_system, lpc_scheme ); + test_initializer::teardown(); + 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; +}; - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, lpc_preprocessed_private_data, desc, constraint_system, assignments, lpc_scheme - ); - bool verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data, lpc_proof, constraint_system, lpc_scheme - ); - BOOST_CHECK(verifier_res); -} -BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(placeholder_circuit2) using curve_type = algebra::curves::bls12<381>; @@ -739,7 +755,7 @@ BOOST_AUTO_TEST_CASE(placeholder_gate_argument_test) { BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE(placeholder_circuit3) +BOOST_AUTO_TEST_SUITE(placeholder_circuit3_lookup_test) using curve_type = algebra::curves::pallas; using field_type = typename curve_type::base_field_type; @@ -779,43 +795,6 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit3) using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; using policy_type = zk::snark::detail::placeholder_policy; -BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { - auto circuit = circuit_test_3(test_global_alg_rnd_engine); - - plonk_table_description desc; - - desc.rows_amount = table_rows; - desc.usable_rows_amount = usable_rows; - - typename policy_type::constraint_system_type constraint_system( - circuit.gates, - circuit.copy_constraints, - circuit.lookup_gates, - circuit.lookup_tables - ); - typename policy_type::variable_assignment_type assignments = circuit.table; - - auto fri_params = create_fri_params(table_rows_log); - lpc_scheme_type lpc_scheme(fri_params); - - std::vector columns_with_copy_constraints = {0, 1, 2, 3}; - - typename placeholder_public_preprocessor::preprocessed_data_type - preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size()); - - typename placeholder_private_preprocessor::preprocessed_data_type - preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc); - - auto proof = placeholder_prover::process( - preprocessed_public_data, preprocessed_private_data, desc, constraint_system, assignments, lpc_scheme); - - bool verifier_res = placeholder_verifier::process( - preprocessed_public_data, proof, constraint_system, lpc_scheme); - BOOST_CHECK(verifier_res); -} - BOOST_AUTO_TEST_CASE(lookup_test) { auto circuit = circuit_test_3(); constexpr std::size_t argument_size = 4; @@ -943,13 +922,13 @@ BOOST_AUTO_TEST_CASE(lookup_test) { } BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE(placeholder_circuit4) +BOOST_AUTO_TEST_SUITE(placeholder_circuit4_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 permutation_size = 4; + constexpr static const std::size_t permutation_size = 3; constexpr static const std::size_t usable_rows = 5; struct placeholder_test_params { @@ -983,43 +962,6 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit4) using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params; using policy_type = zk::snark::detail::placeholder_policy; -BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { - auto circuit = circuit_test_4(test_global_alg_rnd_engine); - - plonk_table_description desc; - - desc.rows_amount = table_rows; - desc.usable_rows_amount = usable_rows; - - typename policy_type::constraint_system_type constraint_system( - circuit.gates, - circuit.copy_constraints, - circuit.lookup_gates, - circuit.lookup_tables - ); - typename policy_type::variable_assignment_type assignments = circuit.table; - - auto fri_params = create_fri_params(table_rows_log); - lpc_scheme_type lpc_scheme(fri_params); - - std::vector columns_with_copy_constraints = {0, 1, 2, 3}; - - typename placeholder_public_preprocessor::preprocessed_data_type - preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size()); - - typename placeholder_private_preprocessor::preprocessed_data_type - preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc); - - auto proof = placeholder_prover::process( - preprocessed_public_data, preprocessed_private_data, desc, constraint_system, assignments, lpc_scheme); - - bool verifier_res = placeholder_verifier::process( - preprocessed_public_data, proof, constraint_system, lpc_scheme); - BOOST_CHECK(verifier_res); -} - BOOST_AUTO_TEST_CASE(lookup_test) { auto circuit = circuit_test_4(test_global_alg_rnd_engine); constexpr std::size_t argument_size = 4; @@ -1137,165 +1079,104 @@ BOOST_AUTO_TEST_CASE(lookup_test) { for (int i = 0; i < argument_size; i++) { BOOST_CHECK(prover_res.F_dfs[i].evaluate(y) == verifier_res[i]); for (std::size_t j = 0; j < desc.rows_amount; j++) { - if(prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) != field_type::value_type::zero()){ + if (prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) != + field_type::value_type::zero()){ std::cout << "!["<< i << "][" << j << "]" << std::endl; - } - BOOST_CHECK(prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) == field_type::value_type::zero()); + BOOST_CHECK( + prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) == + field_type::value_type::zero()); } } } 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; - - struct placeholder_test_params { - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; - - constexpr static const std::size_t witness_columns = witness_columns_6; - constexpr static const std::size_t public_input_columns = public_columns_6; - constexpr static const std::size_t constant_columns = constant_columns_6; - constexpr static const std::size_t selector_columns = selector_columns_6; - - using arithmetization_params = - plonk_arithmetization_params; +BOOST_AUTO_TEST_SUITE(placeholder_circuit1) - constexpr static const std::size_t lambda = 40; - constexpr static const std::size_t m = 2; - }; +using curve_type = algebra::curves::pallas; +using field_type = typename curve_type::base_field_type; +using poseidon_type = hashes::poseidon>; - using circuit_params = placeholder_circuit_params; - using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; - using lpc_params_type = commitments::list_polynomial_commitment_params< - typename placeholder_test_params::merkle_hash_type, - typename placeholder_test_params::transcript_hash_type, - placeholder_test_params::lambda, - placeholder_test_params::m, - true +using TestFixtures = boost::mpl::list< + placeholder_test_fixture, + placeholder_test_fixture, hashes::keccak_1600<512>, witness_columns_1, public_columns_1, constant_columns_1, selector_columns_1, rows_amount_1, 4> >; +BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) { + auto circuit = circuit_test_1(test_global_alg_rnd_engine); + F fixture(circuit, circuit.usable_rows, circuit.table_rows); + BOOST_CHECK(fixture.run_test()); +} +BOOST_AUTO_TEST_SUITE_END() - 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; - -BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { - auto circuit = circuit_test_6(test_global_alg_rnd_engine); - - plonk_table_description desc; +BOOST_AUTO_TEST_SUITE(placeholder_circuit3) - desc.rows_amount = circuit.table_rows; - desc.usable_rows_amount = circuit.usable_rows; - std::size_t table_rows_log = std::log2(circuit.table_rows); +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; +const size_t permutation_size = 3; - typename policy_type::constraint_system_type constraint_system( - circuit.gates, - circuit.copy_constraints, - circuit.lookup_gates, - circuit.lookup_tables - ); - typename policy_type::variable_assignment_type assignments = circuit.table; +using TestFixtures = boost::mpl::list< + placeholder_test_fixture, + placeholder_test_fixture, hashes::keccak_1600<512>, witness_columns_3, public_columns_3, constant_columns_3, selector_columns_3, usable_rows_3, permutation_size> + >; +BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) { + auto circuit = circuit_test_3(test_global_alg_rnd_engine); + F fixture(circuit, usable_rows_3, 1 << 3); + BOOST_CHECK(fixture.run_test()); +} +BOOST_AUTO_TEST_SUITE_END() - auto fri_params = create_fri_params(table_rows_log); - lpc_scheme_type lpc_scheme(fri_params); +BOOST_AUTO_TEST_SUITE(placeholder_circuit4) - std::vector columns_with_copy_constraints = {0, 1, 2, 3}; - transcript_type transcript; +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; +const size_t permutation_size = 3; - typename placeholder_public_preprocessor::preprocessed_data_type - preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size()); +using TestFixtures = boost::mpl::list< + placeholder_test_fixture, + placeholder_test_fixture, hashes::keccak_1600<512>, witness_columns_4, public_columns_4, constant_columns_4, selector_columns_4, usable_rows_4, permutation_size> + >; +BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) { + auto circuit = circuit_test_4(test_global_alg_rnd_engine); + F fixture(circuit, usable_rows_4, 1 << 3); + BOOST_CHECK(fixture.run_test()); +} +BOOST_AUTO_TEST_SUITE_END() - typename placeholder_private_preprocessor::preprocessed_data_type - preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc); +BOOST_AUTO_TEST_SUITE(placeholder_circuit6) - auto proof = placeholder_prover::process( - preprocessed_public_data, preprocessed_private_data, desc, constraint_system, assignments, lpc_scheme); +using curve_type = algebra::curves::pallas; +using field_type = typename curve_type::base_field_type; +using poseidon_type = hashes::poseidon>; - bool verifier_res = placeholder_verifier::process( - preprocessed_public_data, proof, constraint_system, lpc_scheme); - BOOST_CHECK(verifier_res); +using TestFixtures = boost::mpl::list< + placeholder_test_fixture, + placeholder_test_fixture, hashes::keccak_1600<512>, witness_columns_6, public_columns_6, constant_columns_6, selector_columns_6, usable_rows_6, 3, true> + >; +BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) { + auto circuit = circuit_test_6(test_global_alg_rnd_engine); + F fixture(circuit, circuit.usable_rows, circuit.table_rows); + BOOST_CHECK(fixture.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; - - constexpr static const std::size_t permutation_size = 3; - struct placeholder_test_params { - using merkle_hash_type = hashes::keccak_1600<512>; - using transcript_hash_type = hashes::keccak_1600<512>; - - constexpr static const std::size_t witness_columns = witness_columns_7; - constexpr static const std::size_t public_input_columns = public_columns_7; - constexpr static const std::size_t constant_columns = constant_columns_7; - constexpr static const std::size_t selector_columns = selector_columns_7; - - using arithmetization_params = - plonk_arithmetization_params; - - constexpr static const std::size_t lambda = 40; - constexpr static const std::size_t m = 2; - }; +using curve_type = algebra::curves::pallas; +using field_type = typename curve_type::base_field_type; +using poseidon_type = hashes::poseidon>; - using circuit_params = placeholder_circuit_params; - using transcript_type = typename transcript::fiat_shamir_heuristic_sequential; - using lpc_params_type = commitments::list_polynomial_commitment_params< - typename placeholder_test_params::merkle_hash_type, - typename placeholder_test_params::transcript_hash_type, - placeholder_test_params::lambda, - placeholder_test_params::m, - true +using TestFixtures = boost::mpl::list< + placeholder_test_fixture, + placeholder_test_fixture, hashes::keccak_1600<512>, witness_columns_7, public_columns_7, constant_columns_7, selector_columns_7, usable_rows_7, 3, true> >; - - 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; - -BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { - auto circuit = circuit_test_7(test_global_alg_rnd_engine, test_global_rnd_engine); - plonk_table_description desc; - - 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, - circuit.lookup_tables - ); - typename policy_type::variable_assignment_type assignments = circuit.table; - - auto fri_params = create_fri_params(table_rows_log); - lpc_scheme_type lpc_scheme(fri_params); - - std::vector columns_with_copy_constraints = {0, 1, 2, 3}; - transcript_type transcript; - - typename placeholder_public_preprocessor::preprocessed_data_type - preprocessed_public_data = placeholder_public_preprocessor::process( - constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size()); - - typename placeholder_private_preprocessor::preprocessed_data_type - preprocessed_private_data = placeholder_private_preprocessor::process( - constraint_system, assignments.private_table(), desc); - - auto proof = placeholder_prover::process( - preprocessed_public_data, preprocessed_private_data, desc, constraint_system, assignments, lpc_scheme); - - bool verifier_res = placeholder_verifier::process( - preprocessed_public_data, proof, constraint_system, lpc_scheme); - BOOST_CHECK(verifier_res); +BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) { + auto circuit = circuit_test_7(test_global_alg_rnd_engine); + F fixture(circuit, circuit.usable_rows, circuit.table_rows); + BOOST_CHECK(fixture.run_test()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/transcript/transcript.cpp b/test/transcript/transcript.cpp index d4e0182d2..0ccd9198a 100644 --- a/test/transcript/transcript.cpp +++ b/test/transcript/transcript.cpp @@ -36,6 +36,9 @@ #include #include +#include +#include + #include using namespace nil::crypto3; @@ -51,19 +54,49 @@ BOOST_AUTO_TEST_CASE(zk_transcript_manual_test) { auto ch2 = tr.challenge(); auto ch_n = tr.challenges(); - std::cout << ch1.data << std::endl; - std::cout << ch2.data << std::endl; - for (const auto &ch : ch_n) { - std::cout << ch.data << std::endl; - } + BOOST_CHECK_EQUAL(ch1.data, field_type::value_type(0xe858ba005424eabd6d97de7e930779def59a85c1a9ff7e8a5d001cdb07f6e4_cppui256).data); + BOOST_CHECK_EQUAL(ch2.data, field_type::value_type(0xf61f38f58a55b3bbee0480fc5ec3cf8df81603579f4f7134f764bfd3ca5938b_cppui256).data); + + BOOST_CHECK_EQUAL(ch_n[0].data, field_type::value_type(0x4f6b97a9bc99d6996fab5e03d1cd0b418a9b3c97ed64cca070e15777e7cc99a_cppui256).data); + BOOST_CHECK_EQUAL(ch_n[1].data, field_type::value_type(0x2414ddf7ecff246500beb2c01b0c5912a400bc3cdca6d7f24bd2bd4987b21e04_cppui256).data); + BOOST_CHECK_EQUAL(ch_n[2].data, field_type::value_type(0x10bfe2f4a414eec551dda5fd9899e9b46e327648b4fa564ed0517b6a99396aec_cppui256).data); +} + +BOOST_AUTO_TEST_SUITE_END() - std::vector updated_blob {0xa, 0xb, 0xc, 0xd, 0xe, 0xf}; - tr(updated_blob); - ch_n = tr.challenges(); - for (const auto &ch : ch_n) { - std::cout << ch.data << std::endl; - } +BOOST_AUTO_TEST_SUITE(zk_poseidon_transcript_test_suite) + +// We need this test to make sure that poseidon keeps working exactly the same after any refactoring/code changes. +BOOST_AUTO_TEST_CASE(zk_poseidon_transcript_init_test) { + using curve_type = algebra::curves::pallas; + using field_type = typename curve_type::base_field_type; + using poseidon_type = hashes::poseidon>; + + std::vector init_blob {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + transcript::fiat_shamir_heuristic_sequential tr(init_blob); + auto ch1 = tr.challenge(); + auto ch2 = tr.challenge(); + int ch_int = tr.int_challenge(); + + BOOST_CHECK_EQUAL(ch1.data, field_type::value_type(0x7f034babb3066560c2597048bdbbd61327f13734ebe59a225e0c162e869e8f4_cppui256).data); + BOOST_CHECK_EQUAL(ch2.data, field_type::value_type(0x3a60c875ae6475d5ac1d73178284ee752e8ad78066aa688752b1436960948b93_cppui256).data); + BOOST_CHECK_EQUAL(ch_int, 0x7574); +} + +BOOST_AUTO_TEST_CASE(zk_poseidon_transcript_no_init_test) { + using curve_type = algebra::curves::pallas; + using field_type = typename curve_type::base_field_type; + using poseidon_type = hashes::poseidon>; + + transcript::fiat_shamir_heuristic_sequential tr; + auto ch1 = tr.challenge(); + auto ch2 = tr.challenge(); + int ch_int = tr.int_challenge(); + + BOOST_CHECK_EQUAL(ch1.data, field_type::value_type(0x35626947fa1063436f4e5434029ccaec64075c9fc80034c0923054a2b1d30bd2_cppui256).data); + BOOST_CHECK_EQUAL(ch2.data, field_type::value_type(0x1b961886411ee8722dd6b576cba5876eb30999b5237fe0e14255e6d006cff63c_cppui256).data); + BOOST_CHECK_EQUAL(ch_int, 0xc92); } BOOST_AUTO_TEST_SUITE_END()