Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Done with merge-proofs #28

update readme

remove TODO
  • Loading branch information
vo-nil committed Sep 20, 2024
1 parent 03e321a commit 76e4639
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 22 deletions.
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,6 +48,7 @@ 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_challenge_file = "aggregated_challenge.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
2 changes: 2 additions & 0 deletions proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ 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.")
("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.")
("last-proof", po::value<boost::filesystem::path>(&prover_options.last_proof_file)->multitoken(),
"Last proof of aggregated 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),
Expand Down
3 changes: 2 additions & 1 deletion 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.initial_proof_files,
prover_options.last_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

0 comments on commit 76e4639

Please sign in to comment.