Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Dec 4, 2023
1 parent 5c29867 commit c5c7c61
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 174 deletions.
211 changes: 120 additions & 91 deletions barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp
Original file line number Diff line number Diff line change
@@ -1,103 +1,132 @@
#include "protogalaxy_prover.hpp"
#include "barretenberg/flavor/flavor.hpp"
namespace proof_system::honk {
template <class ProverInstances>
void ProtoGalaxyProver_<ProverInstances>::finalise_and_send_instance(std::shared_ptr<Instance> instance,
std::string domain_separator)
{
instance->initialize_prover_polynomials();

const auto instance_size = static_cast<uint32_t>(instance->instance_size);
const auto num_public_inputs = static_cast<uint32_t>(instance->public_inputs.size());
transcript.send_to_verifier(domain_separator + "_instance_size", instance_size);
transcript.send_to_verifier(domain_separator + "_public_input_size", num_public_inputs);

for (size_t i = 0; i < instance->public_inputs.size(); ++i) {
auto public_input_i = instance->public_inputs[i];
transcript.send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i);
}
transcript.send_to_verifier(domain_separator + "_pub_inputs_offset",
static_cast<uint32_t>(instance->pub_inputs_offset));

auto& witness_commitments = instance->witness_commitments;

// Commit to the first three wire polynomials of the instance
// We only commit to the fourth wire polynomial after adding memory recordss
witness_commitments.w_l = commitment_key->commit(instance->proving_key->w_l);
witness_commitments.w_r = commitment_key->commit(instance->proving_key->w_r);
witness_commitments.w_o = commitment_key->commit(instance->proving_key->w_o);

auto wire_comms = witness_commitments.get_wires();
auto commitment_labels = instance->commitment_labels;
auto wire_labels = commitment_labels.get_wires();
for (size_t idx = 0; idx < 3; ++idx) {
transcript.send_to_verifier(domain_separator + "_" + wire_labels[idx], wire_comms[idx]);
}

auto eta = transcript.get_challenge(domain_separator + "_eta");
instance->compute_sorted_accumulator_polynomials(eta);

// Commit to the sorted withness-table accumulator and the finalized (i.e. with memory records) fourth wire
// polynomial
witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum);
witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4);

transcript.send_to_verifier(domain_separator + "_" + commitment_labels.sorted_accum,
witness_commitments.sorted_accum);
transcript.send_to_verifier(domain_separator + "_" + commitment_labels.w_4, witness_commitments.w_4);

auto [beta, gamma] = transcript.get_challenges(domain_separator + "_beta", domain_separator + "_gamma");
instance->compute_grand_product_polynomials(beta, gamma);

witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm);
witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup);

transcript.send_to_verifier(domain_separator + "_" + commitment_labels.z_perm,
instance->witness_commitments.z_perm);
transcript.send_to_verifier(domain_separator + "_" + commitment_labels.z_lookup,
instance->witness_commitments.z_lookup);

instance->alpha = transcript.get_challenge(domain_separator + "_alpha");

auto vk_view = instance->verification_key->pointer_view();
auto labels = instance->commitment_labels.get_precomputed();
for (size_t idx = 0; idx < labels.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_" + labels[idx], (*vk_view[idx]));
}
}

template <class ProverInstances>
void ProtoGalaxyProver_<ProverInstances>::send_accumulator(std::shared_ptr<Instance> instance,
std::string domain_separator)
{
const auto instance_size = static_cast<uint32_t>(instance->instance_size);
const auto num_public_inputs = static_cast<uint32_t>(instance->public_inputs.size());
transcript.send_to_verifier(domain_separator + "_instance_size", instance_size);
transcript.send_to_verifier(domain_separator + "_public_input_size", num_public_inputs);

for (size_t i = 0; i < instance->public_inputs.size(); ++i) {
auto public_input_i = instance->public_inputs[i];
transcript.send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i);
}

transcript.send_to_verifier(domain_separator + "_eta", instance->relation_parameters.eta);
transcript.send_to_verifier(domain_separator + "_beta", instance->relation_parameters.beta);
transcript.send_to_verifier(domain_separator + "_gamma", instance->relation_parameters.gamma);
transcript.send_to_verifier(domain_separator + "_public_input_delta",
instance->relation_parameters.public_input_delta);
transcript.send_to_verifier(domain_separator + "_lookup_grand_product_delta",
instance->relation_parameters.lookup_grand_product_delta);

transcript.send_to_verifier(domain_separator + "_alpha", instance->alpha);

auto folding_parameters = instance->folding_parameters;
transcript.send_to_verifier(domain_separator + "_target_sum", folding_parameters.target_sum);
for (size_t idx = 0; idx < folding_parameters.gate_challenges.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_gate_challenge_" + std::to_string(idx),
folding_parameters.gate_challenges[idx]);
}

auto comm_view = instance->witness_commitments.pointer_view();
auto witness_labels = instance->commitment_labels.get_witness();
for (size_t idx = 0; idx < witness_labels.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_" + witness_labels[idx], (*comm_view[idx]));
}

auto vk_view = instance->verification_key->pointer_view();
auto vk_labels = instance->commitment_labels.get_precomputed();
for (size_t idx = 0; idx < vk_labels.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_" + vk_labels[idx], (*vk_view[idx]));
}
}

template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::prepare_for_folding()
{
auto idx = 0;
for (auto it = instances.begin(); it != instances.end(); it++, idx++) {
auto instance = instances[0];
auto domain_separator = std::to_string(idx);
transcript.send_to_verifier(domain_separator + "is_accumulator", instance->is_accumulator);
if (instance->is_accumulator) {
send_accumulator(instance, domain_separator);
} else {
finalise_and_send_instance(instance, domain_separator);
}
idx++;

for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) {
auto instance = *it;
auto domain_separator = std::to_string(idx);
transcript.send_to_verifier(domain_separator + "is_accumulator", instance->is_accumulator);

if (!static_cast<bool>(instance->is_accumulator)) {
instance->initialize_prover_polynomials();
}

const auto instance_size = static_cast<uint32_t>(instance->instance_size);
const auto num_public_inputs = static_cast<uint32_t>(instance->public_inputs.size());
transcript.send_to_verifier(domain_separator + "_instance_size", instance_size);
transcript.send_to_verifier(domain_separator + "_public_input_size", num_public_inputs);

for (size_t i = 0; i < instance->public_inputs.size(); ++i) {
auto public_input_i = instance->public_inputs[i];
transcript.send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i);
}

if (!static_cast<bool>(instance->is_accumulator)) {
transcript.send_to_verifier(domain_separator + "_pub_inputs_offset",
static_cast<uint32_t>(instance->pub_inputs_offset));

auto& witness_commitments = instance->witness_commitments;

// Commit to the first three wire polynomials of the instance
// We only commit to the fourth wire polynomial after adding memory recordss
witness_commitments.w_l = commitment_key->commit(instance->proving_key->w_l);
witness_commitments.w_r = commitment_key->commit(instance->proving_key->w_r);
witness_commitments.w_o = commitment_key->commit(instance->proving_key->w_o);

auto wire_comms = witness_commitments.get_wires();
auto commitment_labels = instance->commitment_labels;
auto wire_labels = commitment_labels.get_wires();
for (size_t idx = 0; idx < 3; ++idx) {
transcript.send_to_verifier(domain_separator + "_" + wire_labels[idx], wire_comms[idx]);
}

auto eta = transcript.get_challenge(domain_separator + "_eta");
instance->compute_sorted_accumulator_polynomials(eta);

// Commit to the sorted withness-table accumulator and the finalized (i.e. with memory records) fourth wire
// polynomial
witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum);
witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4);

transcript.send_to_verifier(domain_separator + "_" + commitment_labels.sorted_accum,
witness_commitments.sorted_accum);
transcript.send_to_verifier(domain_separator + "_" + commitment_labels.w_4, witness_commitments.w_4);

auto [beta, gamma] = transcript.get_challenges(domain_separator + "_beta", domain_separator + "_gamma");
instance->compute_grand_product_polynomials(beta, gamma);

witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm);
witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup);

transcript.send_to_verifier(domain_separator + "_" + commitment_labels.z_perm,
instance->witness_commitments.z_perm);
transcript.send_to_verifier(domain_separator + "_" + commitment_labels.z_lookup,
instance->witness_commitments.z_lookup);

instance->alpha = transcript.get_challenge(domain_separator + "_alpha");

} else {
transcript.send_to_verifier(domain_separator + "_eta", instance->relation_parameters.eta);
transcript.send_to_verifier(domain_separator + "_beta", instance->relation_parameters.beta);
transcript.send_to_verifier(domain_separator + "_gamma", instance->relation_parameters.gamma);
transcript.send_to_verifier(domain_separator + "_public_input_delta",
instance->relation_parameters.public_input_delta);
transcript.send_to_verifier(domain_separator + "_lookup_grand_product_delta",
instance->relation_parameters.lookup_grand_product_delta);

transcript.send_to_verifier(domain_separator + "_alpha", instance->alpha);

auto folding_parameters = instance->folding_parameters;
transcript.send_to_verifier(domain_separator + "_target_sum", folding_parameters.target_sum);
for (size_t idx = 0; idx < folding_parameters.gate_challenges.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_gate_challenge_" + std::to_string(idx),
folding_parameters.gate_challenges[idx]);
}

auto comm_view = instance->witness_commitments.pointer_view();
auto labels = instance->commitment_labels.get_witness();
for (size_t idx = 0; idx < labels.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_" + labels[idx], (*comm_view[idx]));
}
}

auto vk_view = instance->verification_key->pointer_view();
auto labels = instance->commitment_labels.get_precomputed();
for (size_t idx = 0; idx < labels.size(); idx++) {
transcript.send_to_verifier(domain_separator + "_" + labels[idx], (*vk_view[idx]));
}
finalise_and_send_instance(instance, domain_separator);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
*/
void prepare_for_folding();

void send_accumulator(std::shared_ptr<Instance>, std::string);

void finalise_and_send_instance(std::shared_ptr<Instance>, std::string);

/**
* @brief Given a vector \vec{\beta} of values, compute the pow polynomial on these values as defined in the paper.
*/
Expand Down
Loading

0 comments on commit c5c7c61

Please sign in to comment.