From 3823550b4dedde539b91b632bad59e8f83fc6e5b Mon Sep 17 00:00:00 2001 From: Vasiliy Olekhov Date: Mon, 16 Sep 2024 09:52:34 +0300 Subject: [PATCH] wip Add partial proof stage --- proof-producer/CMakeLists.txt | 20 +++++++++++++++++++ .../include/nil/proof-generator/prover.hpp | 13 ++++++++---- .../bin/proof-producer/src/arg_parser.cpp | 2 +- .../bin/proof-producer/src/main.cpp | 18 ++++++++++++++++- proof-producer/tests/make_proof_for_pairs.sh | 2 +- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/proof-producer/CMakeLists.txt b/proof-producer/CMakeLists.txt index 9eefb3270e..3d5a995a9d 100644 --- a/proof-producer/CMakeLists.txt +++ b/proof-producer/CMakeLists.txt @@ -26,6 +26,26 @@ include(CMSetupVersion) cm_project(proof-producer WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES CXX) +# This is useful due to some build systems (Ninja in particular) are piping +# compiler output and compiler switches it's output to plain text +option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." FALSE) +if (${FORCE_COLORED_OUTPUT}) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + add_compile_options (-fdiagnostics-color=always) + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_compile_options (-fcolor-diagnostics) + endif () +endif () + +# The file compile_commands.json is generated in build directory, so LSP could +# pick it up and guess all include paths, defines and other stuff. +# If Nix is used, LSP could not guess the locations of implicit include +# directories, so we need to include them explicitly. +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES + ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") find_package(crypto3 REQUIRED) 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 ab88ecd573..1782c13b46 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 @@ -104,7 +104,8 @@ namespace nil { PREPROCESS = 1, PROVE = 2, VERIFY = 3, - GENERATE_AGGREGATED_CHALLENGE = 4 + GENERATE_AGGREGATED_CHALLENGE = 4, + PARTIAL_PROVE = 5, }; ProverStage prover_stage_from_string(const std::string& stage) { @@ -113,7 +114,8 @@ namespace nil { {"preprocess", ProverStage::PREPROCESS}, {"prove", ProverStage::PROVE}, {"verify", ProverStage::VERIFY}, - {"generate-aggregated-challenge", ProverStage::GENERATE_AGGREGATED_CHALLENGE} + {"generate-aggregated-challenge", ProverStage::GENERATE_AGGREGATED_CHALLENGE}, + {"partial_prove", ProverStage::PARTIAL_PROVE}, }; auto it = stage_map.find(stage); if (it == stage_map.end()) { @@ -164,6 +166,7 @@ namespace nil { bool generate_to_file( boost::filesystem::path proof_file_, boost::filesystem::path json_file_, + bool partial_proof, bool skip_verification) { if (!nil::proof_generator::can_write_to_file(proof_file_.string())) { BOOST_LOG_TRIVIAL(error) << "Can't write to file " << proof_file_; @@ -182,11 +185,12 @@ namespace nil { *private_preprocessed_data_, *table_description_, *constraint_system_, - *lpc_scheme_ + *lpc_scheme_, + partial_proof ); BOOST_LOG_TRIVIAL(info) << "Proof generated"; - if (skip_verification) { + if (skip_verification || partial_proof) { BOOST_LOG_TRIVIAL(info) << "Skipping proof verification"; } else { if (!verify(proof)) { @@ -410,6 +414,7 @@ namespace nil { ); table_description_.emplace(table_description); assignment_table_.emplace(std::move(assignment_table)); + public_inputs_.emplace(assignment_table_->public_inputs()); return true; } diff --git a/proof-producer/bin/proof-producer/src/arg_parser.cpp b/proof-producer/bin/proof-producer/src/arg_parser.cpp index efd8ced431..5de333fa6a 100644 --- a/proof-producer/bin/proof-producer/src/arg_parser.cpp +++ b/proof-producer/bin/proof-producer/src/arg_parser.cpp @@ -73,7 +73,7 @@ namespace nil { // clang-format off auto options_appender = config.add_options() ("stage", make_defaulted_option(prover_options.stage), - "Stage of the prover to run, one of (all, preprocess, prove, verify, generate-aggregated-challenge). Defaults to 'all'.") + "Stage of the prover to run, one of (all, preprocess, prove, verify, generate-aggregated-challenge, partial_proof). Defaults to 'all'.") ("proof,p", make_defaulted_option(prover_options.proof_file_path), "Proof file") ("json,j", make_defaulted_option(prover_options.json_file_path), "JSON proof file") ("common-data", make_defaulted_option(prover_options.preprocessed_common_data_path), "Preprocessed common data file") diff --git a/proof-producer/bin/proof-producer/src/main.cpp b/proof-producer/bin/proof-producer/src/main.cpp index 41a5fad19d..7e6132bdaa 100644 --- a/proof-producer/bin/proof-producer/src/main.cpp +++ b/proof-producer/bin/proof-producer/src/main.cpp @@ -50,7 +50,8 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { prover.generate_to_file( prover_options.proof_file_path, prover_options.json_file_path, - false/*don't skip verification*/) && + false, /* partial proof */ + false/*don't skip verification*/) && prover.save_preprocessed_common_data_to_file(prover_options.preprocessed_common_data_path) && prover.save_public_preprocessed_data_to_file(prover_options.preprocessed_public_data_path) && prover.save_commitment_state_to_file(prover_options.commitment_scheme_state_path); @@ -76,6 +77,21 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { prover.generate_to_file( prover_options.proof_file_path, prover_options.json_file_path, + false, /*partial proof*/ + true/*skip verification*/); + break; + case nil::proof_generator::detail::ProverStage::PARTIAL_PROVE: + // Load preprocessed data from file and generate the proof. + prover_result = + prover.read_circuit(prover_options.circuit_file_path) && + prover.read_assignment_table(prover_options.assignment_table_file_path) && + prover.read_public_preprocessed_data_from_file(prover_options.preprocessed_public_data_path) && + prover.read_commitment_scheme_from_file(prover_options.commitment_scheme_state_path) && + prover.preprocess_private_data() && + prover.generate_to_file( + prover_options.proof_file_path, + prover_options.json_file_path, + true, /* partial proof */ true/*skip verification*/); break; case nil::proof_generator::detail::ProverStage::VERIFY: diff --git a/proof-producer/tests/make_proof_for_pairs.sh b/proof-producer/tests/make_proof_for_pairs.sh index 5af16aa379..be2bba08fe 100755 --- a/proof-producer/tests/make_proof_for_pairs.sh +++ b/proof-producer/tests/make_proof_for_pairs.sh @@ -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; binary name: $proof_generator_binary): " + echo -n "Processing $tbl_file and $crct_file (proof will be at $proof_dir): " if $proof_generator_binary -t "$tbl_file" --circuit "$crct_file" --proof "$proof_dir/proof.bin" ${args_to_forward[@]}; then color_green "success" else