From 0cbdcb30c672d347e64b482c5c57f3903155a69a Mon Sep 17 00:00:00 2001 From: Vasiliy Olekhov Date: Mon, 16 Sep 2024 18:00:49 +0300 Subject: [PATCH] Added merge-proof action #13 --- .../nil/proof-generator/arg_parser.hpp | 4 ++ .../include/nil/proof-generator/prover.hpp | 42 ++++++++++++++++++- .../bin/proof-producer/src/arg_parser.cpp | 9 +++- .../bin/proof-producer/src/main.cpp | 9 ++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp b/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp index f62b813ba8..cbfdcbcaf1 100644 --- a/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp +++ b/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp @@ -18,6 +18,7 @@ #define PROOF_GENERATOR_ARG_PARSER_HPP #include +#include #include #include @@ -45,6 +46,9 @@ namespace nil { boost::filesystem::path assignment_description_file_path; boost::filesystem::path challenge_file_path; std::vector input_challenge_files; + std::vector partial_proof_files; + std::vector aggregated_proof_files; + boost::filesystem::path last_proof_file; boost::filesystem::path aggregated_challenge_file = "aggregated_challenge.dat"; boost::filesystem::path combined_Q_polynomial_file = "combined_Q.dat"; std::size_t combined_Q_starting_power; diff --git a/proof-producer/bin/proof-producer/include/nil/proof-generator/prover.hpp b/proof-producer/bin/proof-producer/include/nil/proof-generator/prover.hpp index 4163b05cd8..2ea866c846 100644 --- a/proof-producer/bin/proof-producer/include/nil/proof-generator/prover.hpp +++ b/proof-producer/bin/proof-producer/include/nil/proof-generator/prover.hpp @@ -122,7 +122,8 @@ namespace nil { {"verify", ProverStage::VERIFY}, {"generate-aggregated-challenge", ProverStage::GENERATE_AGGREGATED_CHALLENGE}, {"partial-prove", ProverStage::PARTIAL_PROVE}, - {"compute-combined-Q", ProverStage::COMPUTE_COMBINED_Q} + {"compute-combined-Q", ProverStage::COMPUTE_COMBINED_Q}, + {"merge-proofs", ProverStage::MERGE_PROOFS}, }; auto it = stage_map.find(stage); if (it == stage_map.end()) { @@ -615,6 +616,45 @@ namespace nil { return save_poly_to_file(combined_Q, output_combined_Q_file); } + bool merge_proofs( + const std::vector &partial_proof_files, + const std::vector &aggregated_proof_files, + const boost::filesystem::path &last_proof_file, + const boost::filesystem::path &merged_proof_file) + { + nil::crypto3::zk::snark::placeholder_aggregated_proof + merged_proof; + + for(auto const& partial_proof_file: partial_proof_files) { + using ProofMarshalling = nil::crypto3::marshalling::types:: + placeholder_proof, Proof>; + + BOOST_LOG_TRIVIAL(info) << "Reading partial proof from file \"" << partial_proof_file << "\""; + auto marshalled_proof = detail::decode_marshalling_from_file(partial_proof_file, true); + if (!marshalled_proof) { + return false; + } + auto partial_proof = nil::crypto3::marshalling::types::make_placeholder_proof(*marshalled_proof); + merged_proof.partial_proofs.emplace_back(partial_proof); + } + + for(auto const& aggregated_proof_file: aggregated_proof_files) { + + /* TODO: Need marshalling for initial_proofs (lpc_proof_type) */ + BOOST_LOG_TRIVIAL(info) << "Reading aggregated part proof from file \"" << aggregated_proof_file << "\""; + // merged_proof.aggregated_proof.intial_proofs_per_prover.emplace_back(initial_proof); + } + + /* TODO: Need marshalling for top-level proof, (fri_proof_type) */ + BOOST_LOG_TRIVIAL(info) << "Reading single round part proof from file \"" << last_proof_file << "\""; + // merged_proof.fri_proof = ... + + + BOOST_LOG_TRIVIAL(info) << "Writing merged proof to \"" << merged_proof_file << "\""; + + return true; + } + private: const std::size_t expand_factor_; const std::size_t max_quotient_chunks_; diff --git a/proof-producer/bin/proof-producer/src/arg_parser.cpp b/proof-producer/bin/proof-producer/src/arg_parser.cpp index 2255983dbd..b14d391df4 100644 --- a/proof-producer/bin/proof-producer/src/arg_parser.cpp +++ b/proof-producer/bin/proof-producer/src/arg_parser.cpp @@ -98,7 +98,14 @@ namespace nil { ("combined-Q-polynomial-file", po::value(&prover_options.combined_Q_polynomial_file), "File containing the polynomial combined-Q, generated on a single prover.") ("combined-Q-starting-power", po::value(&prover_options.combined_Q_starting_power), - "The starting power for combined-Q polynomial for the current prover."); + "The starting power for combined-Q polynomial for the current prover.") + ("partial-proof", po::value>(&prover_options.partial_proof_files)->multitoken(), + "Partial proofs. Used with 'merge-proofs' stage.") + ("aggregated-proof", po::value>(&prover_options.aggregated_proof_files)->multitoken(), + "Parts of aggregated proof. Used with 'merge-proofs' stage.") + ("last-proof", po::value(&prover_options.last_proof_file)->multitoken(), + "Last proof of aggregated proof. Used with 'merge-proofs' stage.") + ; // clang-format on po::options_description cmdline_options("nil; Proof Producer"); diff --git a/proof-producer/bin/proof-producer/src/main.cpp b/proof-producer/bin/proof-producer/src/main.cpp index 5b3246b5b5..45626ad8f3 100644 --- a/proof-producer/bin/proof-producer/src/main.cpp +++ b/proof-producer/bin/proof-producer/src/main.cpp @@ -110,6 +110,15 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { prover_options.input_challenge_files, prover_options.aggregated_challenge_file ); + break; + case nil::proof_generator::detail::ProverStage::MERGE_PROOFS: + prover_result = + prover.merge_proofs( + prover_options.partial_proof_files, + prover_options.aggregated_proof_files, + prover_options.last_proof_file, + prover_options.proof_file_path); + break; } } catch (const std::exception& e) { BOOST_LOG_TRIVIAL(error) << e.what();