diff --git a/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/proof.hpp b/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/proof.hpp index ed54ead563..25c256be20 100644 --- a/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/proof.hpp +++ b/crypto3/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/proof.hpp @@ -42,6 +42,7 @@ #include #include +#include namespace nil { namespace crypto3 { @@ -226,6 +227,65 @@ namespace nil { return proof; } + template + using placeholder_aggregated_proof_type = nil::marshalling::types::bundle< + TTypeBase, + std::tuple< + nil::marshalling::types::standard_array_list< + TTypeBase, + placeholder_partial_evaluation_proof + >, + nil::crypto3::marshalling::types::aggregated_proof + > + >; + + template + placeholder_aggregated_proof_type, Proof> + fill_placeholder_aggregated_proof( + const AggregatedProof &proof, + const typename Proof::commitment_scheme_type::fri_type::params_type &fri_params + ) { + + using TTypeBase = nil::marshalling::field_type; + + nil::marshalling::types::standard_array_list< + TTypeBase, + placeholder_partial_evaluation_proof + > filled_partial_proofs; + for (const auto &it:proof.partial_proofs) { + filled_partial_proofs.value().push_back( + fill_placeholder_partial_evaluation_proof(it) + ); + } + + return placeholder_aggregated_proof_type(std::make_tuple( + filled_partial_proofs, + fill_aggregated_proof( + proof.aggregated_proof, fri_params) + )); + } + + template + AggregatedProof make_placeholder_aggregated_proof( + const placeholder_aggregated_proof_type, Proof> &filled_proof) { + AggregatedProof proof; + + // std::vector> partial_proofs; + auto filled_partial_proofs = std::get<0>(filled_proof.value()).value(); + for( const auto &it:filled_partial_proofs){ + proof.partial_proofs.push_back( + make_placeholder_partial_evaluation_proof(it) + ); + } + + // typename commitment_scheme_type::aggregated_proof_type aggregated_proof; + proof.aggregated_proof = make_aggregated_proof< + Endianness, typename AggregatedProof::commitment_scheme_type>( + std::get<1>(filled_proof.value()) + ); + + return proof; + } } // namespace types } // namespace marshalling } // namespace crypto3 diff --git a/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp b/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp index 89e25d4030..cafb311f26 100644 --- a/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp +++ b/crypto3/libs/marshalling/zk/test/placeholder_proof.cpp @@ -94,6 +94,7 @@ #include #include "./detail/circuits.hpp" +#include "random_test_data_generation.hpp" using namespace nil; using namespace nil::crypto3; @@ -250,6 +251,39 @@ void test_placeholder_partial_proof(const typename ProofType::partial_proof_type BOOST_CHECK(proof == constructed_val_read); } +template +void test_placeholder_aggregated_proof( + const AggregatedProofType &proof, const CommitmentParamsType& params, std::string output_file = "" +) { + using namespace nil::crypto3::marshalling; + + using TTypeBase = nil::marshalling::field_type; + using proof_marshalling_type = nil::crypto3::marshalling::types::placeholder_aggregated_proof_type; + + auto filled_placeholder_proof = types::fill_placeholder_aggregated_proof( + proof, params); + AggregatedProofType _proof = types::make_placeholder_aggregated_proof< + Endianness, AggregatedProofType, ProofType>(filled_placeholder_proof); + BOOST_CHECK(_proof == proof); + + std::vector cv; + cv.resize(filled_placeholder_proof.length(), 0x00); + auto write_iter = cv.begin(); + auto status = filled_placeholder_proof.write(write_iter, cv.size()); + BOOST_CHECK(status == nil::marshalling::status_type::success); + + if (output_file != "") { + print_placeholder_proof(cv.cbegin(), cv.cend(), false, output_file.c_str()); + } + + proof_marshalling_type test_val_read; + auto read_iter = cv.begin(); + status = test_val_read.read(read_iter, cv.size()); + BOOST_CHECK(status == nil::marshalling::status_type::success); + auto constructed_val_read = types::make_placeholder_aggregated_proof(test_val_read); + BOOST_CHECK(proof == constructed_val_read); +} + bool has_argv(std::string name){ bool result = false; for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc); i++) { @@ -1149,6 +1183,73 @@ BOOST_FIXTURE_TEST_CASE(proof_marshalling_test10, test_tools::random_test_initia preprocessed_public_data.common_data, proof, desc, constraint_system, lpc_scheme); BOOST_CHECK(verifier_res); } + +BOOST_FIXTURE_TEST_CASE(aggregated_proof_marshalling_test, test_tools::random_test_initializer) { + auto circuit = circuit_test_7( + alg_random_engines.template get_alg_engine(), + generic_random_engine + ); + 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 + ); + using batch_lpc_type = commitments::list_polynomial_commitment; + using batch_lpc_scheme_type = typename commitments::lpc_commitment_scheme; + using batch_lpc_placeholder_params_type = + nil::crypto3::zk::snark::placeholder_params; + + 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; + + typename batch_lpc_type::fri_type::params_type fri_params( + 1, table_rows_log, placeholder_test_params::lambda, 4 + ); + batch_lpc_scheme_type lpc_scheme(fri_params); + + typename placeholder_public_preprocessor::preprocessed_data_type + preprocessed_public_data = placeholder_public_preprocessor::process( + constraint_system, assignments.public_table(), desc, lpc_scheme, 10 + ); + + 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, lpc_scheme + ); + // now we get a vector of partial proofs + std::vector> partial_proofs; + for (std::size_t i = 0; i < 5; i++) { + partial_proofs.push_back(proof); + } + // and lpc aggregated proof + auto lpc_proof = generate_random_lpc_aggregated_proof( + 7, 5, + fri_params.step_list, + 20, + false, + alg_random_engines.template get_alg_engine(), + generic_random_engine + ); + test_placeholder_aggregated_proof< + Endianness, placeholder_aggregated_proof, + placeholder_proof, + decltype(fri_params)>( + {partial_proofs, lpc_proof}, fri_params); +} + BOOST_AUTO_TEST_SUITE_END() template<