Skip to content

Commit

Permalink
Added merge-proof action #13
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Sep 17, 2024
1 parent 9bc810c commit 0cbdcb3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define PROOF_GENERATOR_ARG_PARSER_HPP

#include <optional>
#include <string>

#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
Expand Down Expand Up @@ -45,6 +46,9 @@ namespace nil {
boost::filesystem::path assignment_description_file_path;
boost::filesystem::path challenge_file_path;
std::vector<boost::filesystem::path> input_challenge_files;
std::vector<boost::filesystem::path> partial_proof_files;
std::vector<boost::filesystem::path> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -615,6 +616,45 @@ namespace nil {
return save_poly_to_file(combined_Q, output_combined_Q_file);
}

bool merge_proofs(
const std::vector<boost::filesystem::path> &partial_proof_files,
const std::vector<boost::filesystem::path> &aggregated_proof_files,
const boost::filesystem::path &last_proof_file,
const boost::filesystem::path &merged_proof_file)
{
nil::crypto3::zk::snark::placeholder_aggregated_proof<BlueprintField, PlaceholderParams>
merged_proof;

for(auto const& partial_proof_file: partial_proof_files) {
using ProofMarshalling = nil::crypto3::marshalling::types::
placeholder_proof<nil::marshalling::field_type<Endianness>, Proof>;

BOOST_LOG_TRIVIAL(info) << "Reading partial proof from file \"" << partial_proof_file << "\"";
auto marshalled_proof = detail::decode_marshalling_from_file<ProofMarshalling>(partial_proof_file, true);
if (!marshalled_proof) {
return false;
}
auto partial_proof = nil::crypto3::marshalling::types::make_placeholder_proof<Endianness, 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_;
Expand Down
9 changes: 8 additions & 1 deletion proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ namespace nil {
("combined-Q-polynomial-file", po::value<boost::filesystem::path>(&prover_options.combined_Q_polynomial_file),
"File containing the polynomial combined-Q, generated on a single prover.")
("combined-Q-starting-power", po::value<std::size_t>(&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<std::vector<boost::filesystem::path>>(&prover_options.partial_proof_files)->multitoken(),
"Partial proofs. Used with 'merge-proofs' stage.")
("aggregated-proof", po::value<std::vector<boost::filesystem::path>>(&prover_options.aggregated_proof_files)->multitoken(),
"Parts of aggregated proof. Used with 'merge-proofs' stage.")
("last-proof", po::value<boost::filesystem::path>(&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");
Expand Down
9 changes: 9 additions & 0 deletions proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0cbdcb3

Please sign in to comment.