Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Sep 17, 2024
1 parent 9b3ac0d commit 1b49279
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldType, ParamsType> 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<FieldType> &table_description,
const plonk_constraint_system<FieldType> &constraint_system,
commitment_scheme_type commitment_scheme,
const commitment_scheme_type& commitment_scheme,
bool skip_commitment_scheme_eval_proofs = false
) {
auto prover = placeholder_prover<FieldType, ParamsType>(
Expand Down Expand Up @@ -209,14 +210,18 @@ namespace nil {

// 8. Run evaluation proofs
_proof.eval_proof.challenge = transcript.template challenge<FieldType>();
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<polynomial_dfs_type> quotient_polynomial_split_dfs() {
PROFILE_SCOPE("quotient_polynomial_split_dfs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::filesystem::path> input_challenge_files;
std::vector<boost::filesystem::path> partial_proof_files;
std::vector<boost::filesystem::path> aggregated_proof_files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ namespace nil {
boost::filesystem::path proof_file_,
boost::filesystem::path json_file_,
std::optional<boost::filesystem::path> challenge_file_,
std::optional<boost::filesystem::path> theta_power_file,
bool partial_proof,
bool skip_verification) {
if (!nil::proof_generator::can_write_to_file(proof_file_.string())) {
Expand All @@ -190,14 +191,14 @@ namespace nil {
BOOST_ASSERT(lpc_scheme_);

BOOST_LOG_TRIVIAL(info) << "Generating proof...";
Proof proof = nil::crypto3::zk::snark::placeholder_prover<BlueprintField, PlaceholderParams>::process(
*public_preprocessed_data_,
*private_preprocessed_data_,
*table_description_,
*constraint_system_,
*lpc_scheme_,
partial_proof
);
auto prover = nil::crypto3::zk::snark::placeholder_prover<BlueprintField, PlaceholderParams>(
*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) {
Expand Down Expand Up @@ -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<
Expand All @@ -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<std::ofstream>(theta_power_file->string(), std::ios_base::out);
(*output_file) << theta_power << std::endl;
output_file->close();
}

return res;
Expand Down
2 changes: 2 additions & 0 deletions proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ namespace nil {
"Input challenge files. Used with 'generate-aggregated-challenge' stage.")
("challenge-file", po::value<boost::filesystem::path>(&prover_options.challenge_file_path),
"Input challenge files. Used with 'generate-aggregated-challenge' stage.")
("theta-power-file", po::value<boost::filesystem::path>(&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<boost::filesystem::path>(&prover_options.aggregated_challenge_file),
"Aggregated challenge file. Used with 'generate-aggregated-challenge' stage")
("combined-Q-polynomial-file", po::value<boost::filesystem::path>(&prover_options.combined_Q_polynomial_file),
Expand Down
5 changes: 4 additions & 1 deletion proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 1b49279

Please sign in to comment.