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

evm-verifier option added to proof-producer#100 #102

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions crypto3/libs/blueprint/test/verifiers/flexible/poseidon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ void test_poseidon(std::vector<typename BlueprintFieldType::value_type> public_i
zk::snark::plonk_table_description<BlueprintFieldType> desc(
WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns);

crypto3::test_component<component_type, BlueprintFieldType, hash_type, Lambda>(
nil::crypto3::test_component_extended<component_type, BlueprintFieldType, hash_type, Lambda>(
component_instance, desc, public_input, result_check, instance_input,
blueprint::connectedness_check_type::type::STRONG
true, nil::blueprint::connectedness_check_type::type::STRONG, "flexible_poseidon", true,
2046
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ namespace nil {

void print(){
if(_use_lookups && _placeholder_info.lookup_poly_amount > 1){
std::cout << "Lookup argument chunking not supported" << std::endl;
exit(1);
std::cout << "Lookup argument chunking not supported in evm contracts" << std::endl;
return;
}
std::filesystem::create_directory(_folder_name);
std::string gate_argument = print_gate_argument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,16 @@ namespace nil {
for(std::size_t j = 0; j < public_inputs[i].size(); j++){
if( public_inputs[i][j] != 0 ) max_non_zero = j;
}
if( max_non_zero + 1 > public_input_sizes[i] ) {
std::cout << "Public input size is larger than reserved. Real size = " << max_non_zero + 1 << " reserved = " << public_input_sizes[i] << std::endl;
exit(1);
}
BOOST_ASSERT(max_non_zero <= public_input_sizes[i]);
for(std::size_t j = 0; j < public_input_sizes[i]; j++){
// Public_input_sizes in constraint system were supported by zkllvm, but they are not supported for zkevm circuits
// TODO: think about it later
//
// std::cout << "\t max_non_zero = " << max_non_zero << std::endl;
// if( max_non_zero + 1 > public_input_sizes[i] ) {
// std::cout << "Public input size is larger than reserved. Real size = " << max_non_zero + 1 << " reserved = " << public_input_sizes[i] << std::endl;
// exit(1);
// }
// BOOST_ASSERT(max_non_zero <= public_input_sizes[i]);
for(std::size_t j = 0; j < max_non_zero; j++){
if(cur != 0) out << "," << std::endl;
if( j >= public_inputs[i].size() )
out << "\t\t{\"field\": \"" << typename field_type::value_type(0) << "\"}";
Expand All @@ -396,7 +400,6 @@ namespace nil {
proof.eval_proof.eval_proof
) << std::endl;
out << "\t]}" << std::endl;

out << "]" << std::endl;
return out.str();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include <nil/crypto3/zk/transcript/fiat_shamir.hpp>

#include <nil/blueprint/transpiler/recursive_verifier_generator.hpp>

#include <nil/blueprint/transpiler/lpc_evm_verifier_gen.hpp>

#include <nil/proof-generator/arithmetization_params.hpp>
#include <nil/proof-generator/file_operations.hpp>
Expand Down Expand Up @@ -173,6 +173,45 @@ namespace nil {
grind_(grind) {
}

bool print_evm_verifier(
boost::filesystem::path output_folder
){
BOOST_LOG_TRIVIAL(info) << "Print evm verifier";
nil::blueprint::lpc_evm_verifier_printer<PlaceholderParams> evm_verifier_printer(
*constraint_system_,
public_preprocessed_data_->common_data,
output_folder.string()
);
evm_verifier_printer.print();
return true;
}

bool print_public_input_for_evm(
boost::filesystem::path output_folder
){
BOOST_LOG_TRIVIAL(info) << "Print public input for EVM";
std::ofstream pi_stream;
pi_stream.open(output_folder.string() + "/public_input.inp");
if( !pi_stream.is_open() ) return false;

// Does not support public input columns.
if( table_description_->public_input_columns != 0 ) {
std::size_t max_non_zero = 0;
const auto&public_input = assignment_table_->public_input(0);
for (std::size_t i = 0; i < public_input.size(); i++) {
std::cout << "i = " << i << public_input[i] << std::endl;
if (public_input[i] != 0u) {
max_non_zero = i + 1;
}
}
for (std::size_t i = 0; i < std::min(public_input.size(), max_non_zero); i++) {
pi_stream << public_input[i] << "\n";
}
} // else empty file is generated
pi_stream.close();
return true;
}

// The caller must call the preprocessor or load the preprocessed data before calling this function.
bool generate_to_file(
boost::filesystem::path proof_file_,
Expand Down Expand Up @@ -233,10 +272,8 @@ namespace nil {
BlueprintField,
PlaceholderParams>::preprocessed_data_type::common_data_type>(
*table_description_
)
.generate_input(*public_inputs_, proof, constraint_system_->public_input_sizes());
).generate_input(*public_inputs_, proof, constraint_system_->public_input_sizes());
output_file->close();

return res;
}

Expand Down
1 change: 1 addition & 0 deletions proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace nil {
("grind-param", make_defaulted_option(prover_options.grind), "Grind param (0)")
("expand-factor,x", make_defaulted_option(prover_options.expand_factor), "Expand factor")
("max-quotient-chunks,q", make_defaulted_option(prover_options.max_quotient_chunks), "Maximum quotient polynomial parts amount")
("evm-verifier", make_defaulted_option(prover_options.evm_verifier_path), "Output folder for EVM verifier (evm_verifier)")
("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),
Expand Down
1 change: 1 addition & 0 deletions proof-producer/bin/proof-producer/src/arg_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace nil {
boost::filesystem::path assignment_description_file_path;
boost::filesystem::path challenge_file_path;
boost::filesystem::path theta_power_file_path;
boost::filesystem::path evm_verifier_path = "evm_verifier";
std::vector<boost::filesystem::path> input_challenge_files;
std::vector<boost::filesystem::path> partial_proof_files;
std::vector<boost::filesystem::path> initial_proof_files;
Expand Down
19 changes: 12 additions & 7 deletions proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover_result =
prover.read_circuit(prover_options.circuit_file_path) &&
prover.read_assignment_table(prover_options.assignment_table_file_path) &&
prover.print_public_input_for_evm(prover_options.evm_verifier_path) &&
prover.preprocess_public_data() &&
prover.preprocess_private_data() &&
prover.generate_to_file(
prover_options.proof_file_path,
prover_options.json_file_path,
false/*don't skip verification*/) &&
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);
prover.save_commitment_state_to_file(prover_options.commitment_scheme_state_path) &&
prover.print_evm_verifier(prover_options.evm_verifier_path);
break;
case nil::proof_generator::detail::ProverStage::PREPROCESS:
prover_result =
Expand All @@ -63,20 +65,23 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover.preprocess_public_data() &&
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);
prover.save_commitment_state_to_file(prover_options.commitment_scheme_state_path)&&
prover.print_evm_verifier(prover_options.evm_verifier_path);
break;
case nil::proof_generator::detail::ProverStage::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.print_public_input_for_evm(prover_options.evm_verifier_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/*skip verification*/);
true/*skip verification*/)&&
prover.print_evm_verifier(prover_options.evm_verifier_path);
break;
case nil::proof_generator::detail::ProverStage::GENERATE_PARTIAL_PROOF:
// Load preprocessed data from file and generate the proof.
Expand Down Expand Up @@ -116,14 +121,14 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover_options.proof_file_path);
break;
case nil::proof_generator::detail::ProverStage::COMPUTE_COMBINED_Q:
prover_result =
prover_result =
prover.read_commitment_scheme_from_file(prover_options.commitment_scheme_state_path) &&
prover.generate_combined_Q_to_file(
prover_options.aggregated_challenge_file, prover_options.combined_Q_starting_power,
prover_options.combined_Q_polynomial_file);
break;
case nil::proof_generator::detail::ProverStage::GENERATE_AGGREGATED_FRI_PROOF:
prover_result =
prover_result =
prover.read_assignment_description(prover_options.assignment_description_file_path) &&
prover.generate_aggregated_FRI_proof_to_file(
prover_options.aggregated_challenge_file,
Expand All @@ -133,7 +138,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
prover_options.consistency_checks_challenges_file);
break;
case nil::proof_generator::detail::ProverStage::GENERATE_CONSISTENCY_CHECKS_PROOF:
prover_result =
prover_result =
prover.read_commitment_scheme_from_file(prover_options.commitment_scheme_state_path) &&
prover.generate_consistency_checks_to_file(
prover_options.combined_Q_polynomial_file,
Expand Down
Loading