Skip to content

Commit

Permalink
Added partial prove step #13
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Sep 17, 2024
1 parent b3bb68d commit 9bc810c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP

#include <map>
#include <vector>

namespace nil {
namespace crypto3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,10 @@ namespace nil {
}
transcript(_proof.commitments[QUOTIENT_BATCH]);

// 8. Run evaluation proofs
_proof.eval_proof.challenge = transcript.template challenge<FieldType>();
if (!_skip_commitment_scheme_eval_proofs) {
// 8. Run evaluation proofs
_proof.eval_proof.challenge = transcript.template challenge<FieldType>();
generate_evaluation_points();

_proof.eval_proof.eval_proof = _commitment_scheme.proof_eval(transcript);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ namespace nil {
transcript(_proof.commitments[QUOTIENT_BATCH]);

// 8. Run evaluation proofs
_proof.eval_proof.challenge = transcript.template challenge<FieldType>();
if (!_skip_commitment_scheme_eval_proofs) {
// 8. Run evaluation proofs
_proof.eval_proof.challenge = transcript.template challenge<FieldType>();
generate_evaluation_points();

_proof.eval_proof.eval_proof = _commitment_scheme.proof_eval(transcript);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace nil {
boost::filesystem::path circuit_file_path;
boost::filesystem::path assignment_table_file_path;
boost::filesystem::path assignment_description_file_path;
boost::filesystem::path challenge_file_path;
std::vector<boost::filesystem::path> input_challenge_files;
boost::filesystem::path aggregated_challenge_file = "aggregated_challenge.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 @@ -174,6 +174,7 @@ namespace nil {
bool generate_to_file(
boost::filesystem::path proof_file_,
boost::filesystem::path json_file_,
std::optional<boost::filesystem::path> challenge_file_,
bool partial_proof,
bool skip_verification) {
if (!nil::proof_generator::can_write_to_file(proof_file_.string())) {
Expand Down Expand Up @@ -236,6 +237,29 @@ namespace nil {
.generate_input(*public_inputs_, proof, constraint_system_->public_input_sizes());
output_file->close();

if (partial_proof) {
if (!challenge_file_) {
BOOST_LOG_TRIVIAL(error) << "Challenge output file is not set.";
return false;
}
BOOST_LOG_TRIVIAL(info) << "Writing challenge";
using challenge_marshalling_type =
nil::crypto3::marshalling::types::field_element<
TTypeBase, typename BlueprintField::value_type>;

challenge_marshalling_type marshalled_challenge(proof.eval_proof.challenge);

bool res =
detail::encode_marshalling_to_file<challenge_marshalling_type>(
*challenge_file_,
marshalled_challenge);
if (res) {
BOOST_LOG_TRIVIAL(info) << "Challenge written.";
} else {
BOOST_LOG_TRIVIAL(error) << "Failed to write challenge to file.";
}
}

return res;
}

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 @@ -91,6 +91,8 @@ namespace nil {
("max-quotient-chunks,q", make_defaulted_option(prover_options.max_quotient_chunks), "Maximum quotient polynomial parts amount")
("input-challenge-files,u", po::value<std::vector<boost::filesystem::path>>(&prover_options.input_challenge_files)->multitoken(),
"Input challenge files. Used with 'generate-aggregated-challenge' stage.")
("challenge-file", po::value<boost::filesystem::path>(&prover_options.challenge_file_path),
"Input challenge files. Used with 'generate-aggregated-challenge' stage.")
("aggregated-challenge-file", po::value<boost::filesystem::path>(&prover_options.aggregated_challenge_file),
"Aggregated challenge file. Used with 'generate-aggregated-challenge' stage")
("combined-Q-polynomial-file", po::value<boost::filesystem::path>(&prover_options.combined_Q_polynomial_file),
Expand Down
3 changes: 3 additions & 0 deletions proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover.generate_to_file(
prover_options.proof_file_path,
prover_options.json_file_path,
std::nullopt,
false, /* partial proof */
false/*don't skip verification*/) &&
prover.save_preprocessed_common_data_to_file(prover_options.preprocessed_common_data_path) &&
Expand Down Expand Up @@ -77,6 +78,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover.generate_to_file(
prover_options.proof_file_path,
prover_options.json_file_path,
std::nullopt,
false, /*partial proof*/
true/*skip verification*/);
break;
Expand All @@ -91,6 +93,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover.generate_to_file(
prover_options.proof_file_path,
prover_options.json_file_path,
prover_options.challenge_file_path,
true, /* partial proof */
true/*skip verification*/);
break;
Expand Down
2 changes: 1 addition & 1 deletion proof-producer/tests/make_proof_for_pairs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ make_proof_for_pair() {

if [ -f "$crct_file" ]; then
mkdir -p "$proof_dir" # Ensure the output directory exists
echo -n "Processing $tbl_file and $crct_file (proof will be at $proof_dir): "
echo -n "Processing $tbl_file and $crct_file (proof will be at $proof_dir; binary name: $proof_generator_binary): "
if $proof_generator_binary -t "$tbl_file" --circuit "$crct_file" --proof "$proof_dir/proof.bin" ${args_to_forward[@]}; then
color_green "success"
else
Expand Down

0 comments on commit 9bc810c

Please sign in to comment.