From 828edfb5194a369c498b355ee4688d7b7082b03c Mon Sep 17 00:00:00 2001 From: color-typea Date: Wed, 1 Nov 2023 21:57:16 +0800 Subject: [PATCH] Added an option to skip verifying the proof --- README.md | 9 +++++++ .../aspects/prover_vanilla.hpp | 3 +++ .../include/nil/proof-generator/prover.hpp | 26 +++++++++++-------- .../src/aspects/prover_vanilla.cpp | 12 +++++++-- bin/proof-generator/src/main.cpp | 3 ++- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1f51bb67..4140f267 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,12 @@ ${ZKLLVM_BUILD:-build}/bin/assigner/assigner -b ${ZKLLVM_BUILD:-build}/examples/ ``` ./bin/proof-generator/proof-generator --circuit=./merkle_tree_sha2_256_circuit.crt --assignment-table=/balances_tree.tbl --proof=./proof.txt ``` + +3. Enable/disable proof verification + +By default, proof-producer verifies the generated proof, and errors if validation fails - proof file is **NOT** +written to disk in this case. To skip verification (and write the file unconditionally), pass `--skip-verification` flag to the proof-generator. + +``` +./bin/proof-generator/proof-generator --circuit=./merkle_tree_sha2_256_circuit.crt --assignment-table=/balances_tree.tbl --proof=./proof.txt --skip-verification +``` diff --git a/bin/proof-generator/include/nil/proof-generator/aspects/prover_vanilla.hpp b/bin/proof-generator/include/nil/proof-generator/aspects/prover_vanilla.hpp index 5769ee16..9001bd06 100644 --- a/bin/proof-generator/include/nil/proof-generator/aspects/prover_vanilla.hpp +++ b/bin/proof-generator/include/nil/proof-generator/aspects/prover_vanilla.hpp @@ -53,6 +53,7 @@ namespace nil { boost::filesystem::path input_circuit_file_path() const; boost::filesystem::path input_assignment_file_path() const; + bool input_skip_verification() const; boost::filesystem::path output_proof_file_path() const; boost::filesystem::path default_config_path() const; @@ -63,6 +64,8 @@ namespace nil { boost::filesystem::path circuit_file_path; boost::filesystem::path assignment_table_file_path; boost::filesystem::path proof_file_path; + + bool skip_verification; }; } // namespace aspects } // namespace proof_generator diff --git a/bin/proof-generator/include/nil/proof-generator/prover.hpp b/bin/proof-generator/include/nil/proof-generator/prover.hpp index 717054bd..09ced3ba 100644 --- a/bin/proof-generator/include/nil/proof-generator/prover.hpp +++ b/bin/proof-generator/include/nil/proof-generator/prover.hpp @@ -126,7 +126,7 @@ namespace nil { } // namespace detail - void prover(boost::filesystem::path circuit_file_name, boost::filesystem::path assignment_table_file_name, boost::filesystem::path proof_file) { + void prover(boost::filesystem::path circuit_file_name, boost::filesystem::path assignment_table_file_name, boost::filesystem::path proof_file, bool skip_verification) { using curve_type = nil::crypto3::algebra::curves::pallas; using BlueprintFieldType = typename curve_type::base_field_type; constexpr std::size_t WitnessColumns = 15; @@ -254,18 +254,22 @@ namespace nil { lpc_scheme); std::cout << "Proof generated" << std::endl; - std::cout << "Verifying proof..." << std::endl; - bool verification_result = - nil::crypto3::zk::snark::placeholder_verifier::process( - public_preprocessed_data, proof, constraint_system, lpc_scheme - ); + if (!skip_verification) { + std::cout << "Verifying proof..." << std::endl; + bool verification_result = + nil::crypto3::zk::snark::placeholder_verifier::process( + public_preprocessed_data, proof, constraint_system, lpc_scheme + ); - if (!verification_result) { - std::cout << "Something went wrong - proof is not verified" << std::endl; - return; - } + if (!verification_result) { + std::cout << "Something went wrong - proof is not verified" << std::endl; + return; + } - std::cout << "Proof is verified" << std::endl; + std::cout << "Proof is verified" << std::endl; + } else { + std::cout << "Proof verification skipped" << std::endl; + } std::cout << "Writing proof to " << proof_file << "..." << std::endl; auto filled_placeholder_proof = diff --git a/bin/proof-generator/src/aspects/prover_vanilla.cpp b/bin/proof-generator/src/aspects/prover_vanilla.cpp index 926205a1..315e9995 100644 --- a/bin/proof-generator/src/aspects/prover_vanilla.cpp +++ b/bin/proof-generator/src/aspects/prover_vanilla.cpp @@ -47,7 +47,8 @@ namespace nil { ("version,v", "Display version") ("proof", boost::program_options::value(),"Output proof file") ("circuit,c", boost::program_options::value(), "Circuit input file") - ("assignment-table,t", boost::program_options::value(), "Assignment table input file"); + ("assignment-table,t", boost::program_options::value(), "Assignment table input file") + ("skip-verification", "Skip verification"); // clang-format on cli.add(options); } @@ -59,7 +60,8 @@ namespace nil { ("version,v", "Display version") ("proof", boost::program_options::value(),"Output proof file") ("circuit,c", boost::program_options::value(), "Circuit input file") - ("assignment-table,t", boost::program_options::value(), "Assignment table input file"); + ("assignment-table,t", boost::program_options::value(), "Assignment table input file") + ("skip-verification", "Skip verification"); // clang-format on cfg.add(options); } @@ -84,6 +86,8 @@ namespace nil { if (vm.count("proof")) { proof_file_path = vm["proof"].as(); } + + skip_verification = (vm.count("skip-verification") != 0); } boost::filesystem::path prover_vanilla::default_config_path() const { @@ -101,6 +105,10 @@ namespace nil { boost::filesystem::path prover_vanilla::output_proof_file_path() const { return proof_file_path; } + + bool prover_vanilla::input_skip_verification() const { + return skip_verification; + } } // namespace aspects } // namespace proof_generator } // namespace nil diff --git a/bin/proof-generator/src/main.cpp b/bin/proof-generator/src/main.cpp index 1c067fc6..f08070c8 100644 --- a/bin/proof-generator/src/main.cpp +++ b/bin/proof-generator/src/main.cpp @@ -106,10 +106,11 @@ struct prover { context_.find()->input_circuit_file_path(); boost::filesystem::path assignment_file_path = context_.find()->input_assignment_file_path(); + bool skip_verification = context_.find()->input_skip_verification(); boost::filesystem::path proof_file = context_.find()->output_proof_file_path(); - nil::proof_generator::prover(circuit_file_path, assignment_file_path, proof_file); + nil::proof_generator::prover(circuit_file_path, assignment_file_path, proof_file, skip_verification); return 0; }