Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add merge-proofs stage to proof-producer #33

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions proof-producer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,20 @@ Compute LPC consistency check proofs for polynomial combined_Q, done on each pro
--proof="$CIRCUIT-LPC_consistency_check_proof.bin"
```

Merge proofs into one final proof:
```bash
#!/bin/sh

CIRCUIT1=fri_array_swap
CIRCUIT2=merkle_tree_poseidon_cpp_example

bin/proof-producer/proof-producer-single-threaded \
--stage merge-proofs \
--partial-proof $CIRCUIT1-proof.dat \
--partial-proof $CIRCUIT2-proof.dat \
--initial-proof $CIRCUIT1-LPC_consistency_check_proof.bin \
--initial-proof $CIRCUIT2-LPC_consistency_check_proof.bin \
--last-proof aggregated_FRI_proof.bin \
--proof final-proof.dat
```

Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ namespace nil {
boost::filesystem::path theta_power_file_path;
std::vector<boost::filesystem::path> input_challenge_files;
std::vector<boost::filesystem::path> partial_proof_files;
std::vector<boost::filesystem::path> initial_proof_files;
std::vector<boost::filesystem::path> aggregated_proof_files;
boost::filesystem::path last_proof_file;
boost::filesystem::path aggregated_FRI_proof_file = "aggregated_FRI_proof.bin";
boost::filesystem::path aggregated_challenge_file = "aggregated_challenge.dat";
boost::filesystem::path consistency_checks_challenges_file = "consistency_check_challenges.dat";
boost::filesystem::path combined_Q_polynomial_file = "combined_Q.dat";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,41 +704,85 @@ namespace nil {

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 std::vector<boost::filesystem::path> &initial_proof_files,
const boost::filesystem::path &aggregated_FRI_file,
const boost::filesystem::path &merged_proof_file)
{
nil::crypto3::zk::snark::placeholder_aggregated_proof<BlueprintField, PlaceholderParams>
merged_proof;
/* ZK types */
using placeholder_aggregated_proof_type = nil::crypto3::zk::snark::
placeholder_aggregated_proof<BlueprintField, PlaceholderParams>;

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

using initial_proof_type = typename LpcScheme::lpc_proof_type;

/* Marshalling types */
using partial_proof_marshalled_type = nil::crypto3::marshalling::types::
placeholder_proof<nil::marshalling::field_type<Endianness>, Proof>;

using initial_proof_marshalling_type = nil::crypto3::marshalling::types::
inital_eval_proof<TTypeBase, LpcScheme>;

using fri_proof_marshalling_type = nil::crypto3::marshalling::types::
initial_fri_proof_type<TTypeBase, LpcScheme>;

using merged_proof_marshalling_type = nil::crypto3::marshalling::types::
placeholder_aggregated_proof_type<TTypeBase, placeholder_aggregated_proof_type>;


placeholder_aggregated_proof_type merged_proof;

if (partial_proof_files.size() != initial_proof_files.size() ) {
BOOST_LOG_TRIVIAL(error) << "Number of partial and initial proof files should match.";
return false;
}

for(auto const& partial_proof_file: partial_proof_files) {
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) {
auto marshalled_partial_proof = detail::decode_marshalling_from_file<partial_proof_marshalled_type>(partial_proof_file, true);
if (!marshalled_partial_proof) {
BOOST_LOG_TRIVIAL(error) << "Error reading partial_proof from from \"" << partial_proof_file << "\"";
return false;
}
auto partial_proof = nil::crypto3::marshalling::types::make_placeholder_proof<Endianness, Proof>(*marshalled_proof);

partial_proof_type partial_proof = nil::crypto3::marshalling::types::
make_placeholder_proof<Endianness, Proof>(*marshalled_partial_proof);

merged_proof.partial_proofs.emplace_back(partial_proof);
}

for(auto const& aggregated_proof_file: aggregated_proof_files) {
for(auto const& initial_proof_file: initial_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);
BOOST_LOG_TRIVIAL(info) << "Reading initial proof from file \"" << initial_proof_file << "\"";
auto initial_proof =
detail::decode_marshalling_from_file<initial_proof_marshalling_type>(initial_proof_file);
if (!initial_proof) {
BOOST_LOG_TRIVIAL(error) << "Error reading lpc_consistency_proof from \"" << initial_proof_file << "\"";
}

merged_proof.aggregated_proof.intial_proofs_per_prover.emplace_back(
nil::crypto3::marshalling::types::make_initial_eval_proof<Endianness, LpcScheme>(*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) << "Reading aggregated FRI proof from file \"" << aggregated_FRI_file << "\"";

auto marshalled_fri_proof = detail::decode_marshalling_from_file<fri_proof_marshalling_type>(aggregated_FRI_file);

if (!marshalled_fri_proof) {
BOOST_LOG_TRIVIAL(error) << "Error reading fri_proof from \"" << aggregated_FRI_file << "\"";
return false;
}
merged_proof.aggregated_proof.fri_proof =
nil::crypto3::marshalling::types::make_initial_fri_proof<Endianness, LpcScheme>(*marshalled_fri_proof);

BOOST_LOG_TRIVIAL(info) << "Writing merged proof to \"" << merged_proof_file << "\"";

return true;
auto marshalled_proof = nil::crypto3::marshalling::types::fill_placeholder_aggregated_proof
<Endianness, placeholder_aggregated_proof_type, partial_proof_type>
(merged_proof, lpc_scheme_->get_fri_params());

return detail::encode_marshalling_to_file<merged_proof_marshalling_type>(merged_proof_file, marshalled_proof);
}

bool save_fri_proof_to_file(
Expand Down
6 changes: 4 additions & 2 deletions proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ namespace nil {
"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.")
("initial-proof", po::value<std::vector<boost::filesystem::path>>(&prover_options.initial_proof_files)->multitoken(),
"Inital proofs, produced by consistency-check stage. Used with 'merge-proofs' stage.")
("aggregated-FRI-proof", po::value<boost::filesystem::path>(&prover_options.aggregated_FRI_proof_file),
"Aggregated FRI proof part of the final proof. Used with 'merge-proofs' stage.")
("input-combined-Q-polynomial-files", po::value<std::vector<boost::filesystem::path>>(&prover_options.input_combined_Q_polynomial_files),
"Files containing polynomials combined-Q, 1 per prover instance.")
("proof-of-work-file", make_defaulted_option(prover_options.proof_of_work_output_file), "File with proof of work.");
Expand Down
5 changes: 3 additions & 2 deletions proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover_result =
prover.merge_proofs(
prover_options.partial_proof_files,
prover_options.aggregated_proof_files,
prover_options.last_proof_file,
prover_options.initial_proof_files,
prover_options.aggregated_FRI_proof_file,
prover_options.proof_file_path);
break;
case nil::proof_generator::detail::ProverStage::COMPUTE_COMBINED_Q:
prover_result =
prover.read_commitment_scheme_from_file(prover_options.commitment_scheme_state_path) &&
Expand Down
Loading