From 09a739574ede0e464e59d175a9149f5cab25b36b Mon Sep 17 00:00:00 2001 From: "e.tatuzova" Date: Tue, 22 Oct 2024 11:43:36 +0400 Subject: [PATCH 1/2] evm-verifier option added to proof-producer#100 --- .../test/verifiers/flexible/poseidon.cpp | 5 +- .../transpiler/lpc_evm_verifier_gen.hpp | 4 +- .../recursive_verifier_generator.hpp | 17 ++++--- .../include/nil/proof-generator/prover.hpp | 48 +++++++++++++++++-- .../bin/proof-producer/src/arg_parser.cpp | 1 + .../bin/proof-producer/src/arg_parser.hpp | 1 + .../bin/proof-producer/src/main.cpp | 19 +++++--- 7 files changed, 73 insertions(+), 22 deletions(-) diff --git a/crypto3/libs/blueprint/test/verifiers/flexible/poseidon.cpp b/crypto3/libs/blueprint/test/verifiers/flexible/poseidon.cpp index 83536cd59d..d534271cf5 100644 --- a/crypto3/libs/blueprint/test/verifiers/flexible/poseidon.cpp +++ b/crypto3/libs/blueprint/test/verifiers/flexible/poseidon.cpp @@ -86,9 +86,10 @@ void test_poseidon(std::vector public_i zk::snark::plonk_table_description desc( WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns); - crypto3::test_component( + nil::crypto3::test_component_extended( 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 ); } diff --git a/crypto3/libs/transpiler/include/nil/blueprint/transpiler/lpc_evm_verifier_gen.hpp b/crypto3/libs/transpiler/include/nil/blueprint/transpiler/lpc_evm_verifier_gen.hpp index 7f92f29ad7..3e20e550bf 100644 --- a/crypto3/libs/transpiler/include/nil/blueprint/transpiler/lpc_evm_verifier_gen.hpp +++ b/crypto3/libs/transpiler/include/nil/blueprint/transpiler/lpc_evm_verifier_gen.hpp @@ -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(); diff --git a/crypto3/libs/transpiler/include/nil/blueprint/transpiler/recursive_verifier_generator.hpp b/crypto3/libs/transpiler/include/nil/blueprint/transpiler/recursive_verifier_generator.hpp index ff3b8d0489..4eb258c823 100644 --- a/crypto3/libs/transpiler/include/nil/blueprint/transpiler/recursive_verifier_generator.hpp +++ b/crypto3/libs/transpiler/include/nil/blueprint/transpiler/recursive_verifier_generator.hpp @@ -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) << "\"}"; @@ -396,7 +400,6 @@ namespace nil { proof.eval_proof.eval_proof ) << std::endl; out << "\t]}" << std::endl; - out << "]" << std::endl; return out.str(); } 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 cf510c6c7c..1b2d97a703 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 @@ -54,7 +54,7 @@ #include #include - +#include #include #include @@ -173,6 +173,48 @@ 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 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::cout << "I have real input" << std::endl; + std::size_t max_non_zero = 0; + const auto&public_input = assignment_table_->public_input(0); + std::cout << "Public input size = " << public_input.size() << std::endl; + 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; + } + } + std::cout << "Max non zero = " << max_non_zero << std::endl; + 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_, @@ -233,10 +275,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; } diff --git a/proof-producer/bin/proof-producer/src/arg_parser.cpp b/proof-producer/bin/proof-producer/src/arg_parser.cpp index 61210149e5..347f067ca4 100644 --- a/proof-producer/bin/proof-producer/src/arg_parser.cpp +++ b/proof-producer/bin/proof-producer/src/arg_parser.cpp @@ -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>(&prover_options.input_challenge_files)->multitoken(), "Input challenge files. Used with 'generate-aggregated-challenge' stage.") ("challenge-file", po::value(&prover_options.challenge_file_path), diff --git a/proof-producer/bin/proof-producer/src/arg_parser.hpp b/proof-producer/bin/proof-producer/src/arg_parser.hpp index e36dca7862..8dc9d1b306 100644 --- a/proof-producer/bin/proof-producer/src/arg_parser.hpp +++ b/proof-producer/bin/proof-producer/src/arg_parser.hpp @@ -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 input_challenge_files; std::vector partial_proof_files; std::vector initial_proof_files; diff --git a/proof-producer/bin/proof-producer/src/main.cpp b/proof-producer/bin/proof-producer/src/main.cpp index 1d6c8a20a2..9d8a83f5aa 100644 --- a/proof-producer/bin/proof-producer/src/main.cpp +++ b/proof-producer/bin/proof-producer/src/main.cpp @@ -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 = @@ -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. @@ -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, @@ -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, From c8160b501b15723c8f67cf9423282ac2133efde7 Mon Sep 17 00:00:00 2001 From: "e.tatuzova" Date: Wed, 23 Oct 2024 08:51:39 +0400 Subject: [PATCH 2/2] Removed couts #100 --- .../bin/proof-producer/include/nil/proof-generator/prover.hpp | 3 --- 1 file changed, 3 deletions(-) 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 1b2d97a703..2bae298dad 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 @@ -196,17 +196,14 @@ namespace nil { // Does not support public input columns. if( table_description_->public_input_columns != 0 ) { - std::cout << "I have real input" << std::endl; std::size_t max_non_zero = 0; const auto&public_input = assignment_table_->public_input(0); - std::cout << "Public input size = " << public_input.size() << std::endl; 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; } } - std::cout << "Max non zero = " << max_non_zero << std::endl; for (std::size_t i = 0; i < std::min(public_input.size(), max_non_zero); i++) { pi_stream << public_input[i] << "\n"; }