Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to skip verifying the proof #11

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
26 changes: 15 additions & 11 deletions bin/proof-generator/include/nil/proof-generator/prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<BlueprintFieldType, placeholder_params>::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<BlueprintFieldType, placeholder_params>::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 =
Expand Down
12 changes: 10 additions & 2 deletions bin/proof-generator/src/aspects/prover_vanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace nil {
("version,v", "Display version")
("proof", boost::program_options::value<std::string>(),"Output proof file")
("circuit,c", boost::program_options::value<std::string>(), "Circuit input file")
("assignment-table,t", boost::program_options::value<std::string>(), "Assignment table input file");
("assignment-table,t", boost::program_options::value<std::string>(), "Assignment table input file")
("skip-verification", "Skip verification");
// clang-format on
cli.add(options);
}
Expand All @@ -59,7 +60,8 @@ namespace nil {
("version,v", "Display version")
("proof", boost::program_options::value<std::string>(),"Output proof file")
("circuit,c", boost::program_options::value<std::string>(), "Circuit input file")
("assignment-table,t", boost::program_options::value<std::string>(), "Assignment table input file");
("assignment-table,t", boost::program_options::value<std::string>(), "Assignment table input file")
("skip-verification", "Skip verification");
// clang-format on
cfg.add(options);
}
Expand All @@ -84,6 +86,8 @@ namespace nil {
if (vm.count("proof")) {
proof_file_path = vm["proof"].as<std::string>();
}

skip_verification = (vm.count("skip-verification") != 0);
}

boost::filesystem::path prover_vanilla::default_config_path() const {
Expand All @@ -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
3 changes: 2 additions & 1 deletion bin/proof-generator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ struct prover {
context_.find<nil::proof_generator::aspects::prover_vanilla>()->input_circuit_file_path();
boost::filesystem::path assignment_file_path =
context_.find<nil::proof_generator::aspects::prover_vanilla>()->input_assignment_file_path();
bool skip_verification = context_.find<nil::proof_generator::aspects::prover_vanilla>()->input_skip_verification();

boost::filesystem::path proof_file = context_.find<nil::proof_generator::aspects::prover_vanilla>()->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;
}
Expand Down