Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Add partial proof stage
  • Loading branch information
vo-nil committed Sep 17, 2024
1 parent c9b99a9 commit f15fcbf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
20 changes: 20 additions & 0 deletions proof-producer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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_,
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_;
Expand All @@ -192,11 +193,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)) {
Expand Down Expand Up @@ -420,6 +422,7 @@ namespace nil {
);
table_description_.emplace(table_description);
assignment_table_.emplace(std::move(assignment_table));
public_inputs_.emplace(assignment_table_->public_inputs());
return true;
}

Expand Down
18 changes: 17 additions & 1 deletion proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
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; 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
Expand Down

0 comments on commit f15fcbf

Please sign in to comment.