From 1b4927950549a9521c1267db5ba65188548c58c9 Mon Sep 17 00:00:00 2001 From: Vasiliy Olekhov Date: Tue, 17 Sep 2024 11:55:10 +0300 Subject: [PATCH] wip --- .../zk/commitments/batched_commitment.hpp | 1 + .../crypto3/zk/commitments/polynomial/lpc.hpp | 11 ++++++-- .../systems/plonk/placeholder/prover.hpp | 11 +++++--- .../nil/proof-generator/arg_parser.hpp | 1 + .../include/nil/proof-generator/prover.hpp | 27 +++++++++++++------ .../bin/proof-producer/src/arg_parser.cpp | 2 ++ .../bin/proof-producer/src/main.cpp | 5 +++- 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/crypto3/libs/zk/include/nil/crypto3/zk/commitments/batched_commitment.hpp b/crypto3/libs/zk/include/nil/crypto3/zk/commitments/batched_commitment.hpp index 0cb037003e..54352f7283 100644 --- a/crypto3/libs/zk/include/nil/crypto3/zk/commitments/batched_commitment.hpp +++ b/crypto3/libs/zk/include/nil/crypto3/zk/commitments/batched_commitment.hpp @@ -262,6 +262,7 @@ namespace nil { BOOST_ASSERT(_locked[batch_id]); _points[batch_id][poly_id].push_back(point); + std::cout << "Point appended to batch " << batch_id << ": " << poly_id << " value: " << point << std::endl; } // This function don't check evaluation points repeats diff --git a/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp b/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp index 120adf3767..8f18f711cc 100644 --- a/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp +++ b/crypto3/libs/zk/include/nil/crypto3/zk/commitments/polynomial/lpc.hpp @@ -352,27 +352,34 @@ namespace nil { } // Computes and returns the maximal power of theta used to compute the value of Combined_Q. - std::size_t compute_theta_power_for_combined_Q() const { + std::size_t compute_theta_power_for_combined_Q() { std::size_t theta_power = 0; + this->eval_polys(); this->build_points_map(); auto points = this->get_unique_points(); for (auto const &point: points) { + std::cout << "processing point " << point << std::endl; for (std::size_t i: this->_z.get_batches()) { + std::cout << "For a batch " << i << std::endl; for (std::size_t j = 0; j < this->_z.get_batch_size(i); j++) { auto iter = this->_points_map[i][j].find(point); if (iter == this->_points_map[i][j].end()) continue; theta_power++; + std::cout << "This batch has this point, rising power to " << theta_power << std::endl; } } } for (std::size_t i: this->_z.get_batches()) { - if (!_batch_fixed.at(i)) + std::cout << "Testing whether " << i << " batch is fixed.." << std::endl; + if (!_batch_fixed.at(i)) { + std::cout << "The batch " << i << " is not fixed yet, skipping!" << std::endl; continue; + } theta_power += this->_z.get_batch_size(i); } diff --git a/crypto3/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp b/crypto3/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp index 8e0a6cc7d0..1037b78d75 100644 --- a/crypto3/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp +++ b/crypto3/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp @@ -90,14 +90,15 @@ namespace nil { constexpr static const std::size_t permutation_parts = 3; constexpr static const std::size_t lookup_parts = 6; constexpr static const std::size_t f_parts = 8; - public: + + public: static inline placeholder_proof process( const typename public_preprocessor_type::preprocessed_data_type &preprocessed_public_data, typename private_preprocessor_type::preprocessed_data_type preprocessed_private_data, const plonk_table_description &table_description, const plonk_constraint_system &constraint_system, - commitment_scheme_type commitment_scheme, + const commitment_scheme_type& commitment_scheme, bool skip_commitment_scheme_eval_proofs = false ) { auto prover = placeholder_prover( @@ -209,14 +210,18 @@ namespace nil { // 8. Run evaluation proofs _proof.eval_proof.challenge = transcript.template challenge(); + generate_evaluation_points(); if (!_skip_commitment_scheme_eval_proofs) { - generate_evaluation_points(); _proof.eval_proof.eval_proof = _commitment_scheme.proof_eval(transcript); } return _proof; } + commitment_scheme_type& get_commitment_scheme() { + return _commitment_scheme; + } + private: std::vector quotient_polynomial_split_dfs() { PROFILE_SCOPE("quotient_polynomial_split_dfs"); diff --git a/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp b/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp index cbfdcbcaf1..065a26b090 100644 --- a/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp +++ b/proof-producer/bin/proof-producer/include/nil/proof-generator/arg_parser.hpp @@ -45,6 +45,7 @@ namespace nil { boost::filesystem::path assignment_table_file_path; boost::filesystem::path assignment_description_file_path; boost::filesystem::path challenge_file_path; + boost::filesystem::path theta_power_file_path; std::vector input_challenge_files; std::vector partial_proof_files; std::vector aggregated_proof_files; 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 2ea866c846..1ae71668a5 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 @@ -176,6 +176,7 @@ namespace nil { boost::filesystem::path proof_file_, boost::filesystem::path json_file_, std::optional challenge_file_, + std::optional theta_power_file, bool partial_proof, bool skip_verification) { if (!nil::proof_generator::can_write_to_file(proof_file_.string())) { @@ -190,14 +191,14 @@ namespace nil { BOOST_ASSERT(lpc_scheme_); BOOST_LOG_TRIVIAL(info) << "Generating proof..."; - Proof proof = nil::crypto3::zk::snark::placeholder_prover::process( - *public_preprocessed_data_, - *private_preprocessed_data_, - *table_description_, - *constraint_system_, - *lpc_scheme_, - partial_proof - ); + auto prover = nil::crypto3::zk::snark::placeholder_prover( + *public_preprocessed_data_, + *private_preprocessed_data_, + *table_description_, + *constraint_system_, + *lpc_scheme_, + partial_proof); + Proof proof = prover.process(); BOOST_LOG_TRIVIAL(info) << "Proof generated"; if (skip_verification || partial_proof) { @@ -243,6 +244,10 @@ namespace nil { BOOST_LOG_TRIVIAL(error) << "Challenge output file is not set."; return false; } + if (!theta_power_file) { + BOOST_LOG_TRIVIAL(error) << "Theta power file is not set."; + return false; + } BOOST_LOG_TRIVIAL(info) << "Writing challenge"; using challenge_marshalling_type = nil::crypto3::marshalling::types::field_element< @@ -259,6 +264,12 @@ namespace nil { } else { BOOST_LOG_TRIVIAL(error) << "Failed to write challenge to file."; } + + std::size_t theta_power = prover.get_commitment_scheme().compute_theta_power_for_combined_Q(); + + auto output_file = open_file(theta_power_file->string(), std::ios_base::out); + (*output_file) << theta_power << std::endl; + 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 b14d391df4..12b9ec9b1d 100644 --- a/proof-producer/bin/proof-producer/src/arg_parser.cpp +++ b/proof-producer/bin/proof-producer/src/arg_parser.cpp @@ -93,6 +93,8 @@ namespace nil { "Input challenge files. Used with 'generate-aggregated-challenge' stage.") ("challenge-file", po::value(&prover_options.challenge_file_path), "Input challenge files. Used with 'generate-aggregated-challenge' stage.") + ("theta-power-file", po::value(&prover_options.theta_power_file_path), + "File to output theta power. Used by main prover to arrange starting powers of Q") ("aggregated-challenge-file", po::value(&prover_options.aggregated_challenge_file), "Aggregated challenge file. Used with 'generate-aggregated-challenge' stage") ("combined-Q-polynomial-file", po::value(&prover_options.combined_Q_polynomial_file), diff --git a/proof-producer/bin/proof-producer/src/main.cpp b/proof-producer/bin/proof-producer/src/main.cpp index 45626ad8f3..2f3359b211 100644 --- a/proof-producer/bin/proof-producer/src/main.cpp +++ b/proof-producer/bin/proof-producer/src/main.cpp @@ -51,6 +51,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { prover_options.proof_file_path, prover_options.json_file_path, std::nullopt, + std::nullopt, false, /* partial proof */ false/*don't skip verification*/) && prover.save_preprocessed_common_data_to_file(prover_options.preprocessed_common_data_path) && @@ -79,6 +80,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { prover_options.proof_file_path, prover_options.json_file_path, std::nullopt, + std::nullopt, false, /*partial proof*/ true/*skip verification*/); break; @@ -89,11 +91,12 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { 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.preprocess_private_data() && prover.generate_to_file( prover_options.proof_file_path, prover_options.json_file_path, prover_options.challenge_file_path, + prover_options.theta_power_file_path, true, /* partial proof */ true/*skip verification*/); break;