Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Feb 13, 2024
1 parent 60d75e5 commit 8a65de1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 105 deletions.
181 changes: 80 additions & 101 deletions barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,119 +5,98 @@ template <class ProverInstances>
void ProtoGalaxyProver_<ProverInstances>::finalise_and_send_instance(std::shared_ptr<Instance> instance,
const std::string& domain_separator)
{
const auto preamble_round = [&](std::shared_ptr<Instance>& instance) {
instance->initialize_prover_polynomials();
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));
};
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);

const auto wire_commitments_round = [&](std::shared_ptr<Instance>& instance) {
auto& witness_commitments = instance->witness_commitments;
auto& commitment_labels = instance->commitment_labels;
// 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 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]);
}
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]);
}

if constexpr (IsGoblinFlavor<Flavor>) {
// Commit to Goblin ECC op wires
witness_commitments.ecc_op_wire_1 = commitment_key->commit(instance->proving_key->ecc_op_wire_1);
witness_commitments.ecc_op_wire_2 = commitment_key->commit(instance->proving_key->ecc_op_wire_2);
witness_commitments.ecc_op_wire_3 = commitment_key->commit(instance->proving_key->ecc_op_wire_3);
witness_commitments.ecc_op_wire_4 = commitment_key->commit(instance->proving_key->ecc_op_wire_4);

auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires();
auto labels = commitment_labels.get_ecc_op_wires();
for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) {
transcript->send_to_verifier(domain_separator + "_" + labels[idx], op_wire_comms[idx]);
}
// Commit to DataBus columns
witness_commitments.calldata = commitment_key->commit(instance->proving_key->calldata);
witness_commitments.calldata_read_counts =
commitment_key->commit(instance->proving_key->calldata_read_counts);
transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata,
instance->witness_commitments.calldata);
transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata_read_counts,
instance->witness_commitments.calldata_read_counts);
if constexpr (IsGoblinFlavor<Flavor>) {
// Commit to Goblin ECC op wires
witness_commitments.ecc_op_wire_1 = commitment_key->commit(instance->proving_key->ecc_op_wire_1);
witness_commitments.ecc_op_wire_2 = commitment_key->commit(instance->proving_key->ecc_op_wire_2);
witness_commitments.ecc_op_wire_3 = commitment_key->commit(instance->proving_key->ecc_op_wire_3);
witness_commitments.ecc_op_wire_4 = commitment_key->commit(instance->proving_key->ecc_op_wire_4);

auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires();
auto labels = commitment_labels.get_ecc_op_wires();
for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) {
transcript->send_to_verifier(domain_separator + "_" + labels[idx], op_wire_comms[idx]);
}
};
// Commit to DataBus columns
witness_commitments.calldata = commitment_key->commit(instance->proving_key->calldata);
witness_commitments.calldata_read_counts = commitment_key->commit(instance->proving_key->calldata_read_counts);
transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata,
instance->witness_commitments.calldata);
transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata_read_counts,
instance->witness_commitments.calldata_read_counts);
}

const auto sorted_accumulators_round = [&](std::shared_ptr<Instance>& instance) {
auto& witness_commitments = instance->witness_commitments;
auto& commitment_labels = instance->commitment_labels;
auto eta = transcript->template get_challenge<FF>(domain_separator + "_eta");
instance->compute_sorted_accumulator_polynomials(eta);

auto eta = transcript->template get_challenge<FF>(domain_separator + "_eta");
instance->compute_sorted_accumulator_polynomials(eta);
// Commit to the sorted witness-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);

// Commit to the sorted witness-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);

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->template get_challenges<FF>(domain_separator + "_beta", domain_separator + "_gamma");

const auto grand_products_round = [&](std::shared_ptr<Instance>& instance) {
auto& witness_commitments = instance->witness_commitments;
auto& commitment_labels = instance->commitment_labels;
auto [beta, gamma] =
transcript->template get_challenges<FF>(domain_separator + "_beta", domain_separator + "_gamma");

if constexpr (IsGoblinFlavor<Flavor>) {
// Compute and commit to the logderivative inverse used in DataBus
instance->compute_logderivative_inverse(beta, gamma);
instance->witness_commitments.lookup_inverses =
commitment_key->commit(instance->prover_polynomials.lookup_inverses);
transcript->send_to_verifier(domain_separator + "_" + commitment_labels.lookup_inverses,
instance->witness_commitments.lookup_inverses);
}

instance->compute_grand_product_polynomials(beta, gamma);
if constexpr (IsGoblinFlavor<Flavor>) {
// Compute and commit to the logderivative inverse used in DataBus
instance->compute_logderivative_inverse(beta, gamma);
instance->witness_commitments.lookup_inverses =
commitment_key->commit(instance->prover_polynomials.lookup_inverses);
transcript->send_to_verifier(domain_separator + "_" + commitment_labels.lookup_inverses,
instance->witness_commitments.lookup_inverses);
}

witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm);
witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup);
instance->compute_grand_product_polynomials(beta, gamma);

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);
};
witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm);
witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup);

const auto vk_folding_round = [&](std::shared_ptr<Instance>& instance) {
for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) {
instance->alphas[idx] =
transcript->template get_challenge<FF>(domain_separator + "_alpha_" + std::to_string(idx));
}
auto vk_view = instance->verification_key->get_all();
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]);
}
};
preamble_round(instance);
wire_commitments_round(instance);
sorted_accumulators_round(instance);
grand_products_round(instance);
vk_folding_round(instance);
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);
for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) {
instance->alphas[idx] =
transcript->template get_challenge<FF>(domain_separator + "_alpha_" + std::to_string(idx));
}
auto vk_view = instance->verification_key->get_all();
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
}

/**
* @brief Recursively compute the parent nodes of each level in the tree, starting from the leaves. Note that
* at each level, the resulting parent nodes will be polynomials of degree (level+1) because we multiply by an
* @brief Recursively compute the parent nodes of each level in the tree, starting from the leaves. Note that at
* each level, the resulting parent nodes will be polynomials of degree (level+1) because we multiply by an
* additional factor of X.
*/
static std::vector<FF> construct_coefficients_tree(const std::vector<FF>& betas,
const std::vector<FF>& deltas,
const std::vector<std::vector<FF>>& prev_level_coeffs,
size_t level = 1)
{
// if we are at level t in the tree, where t = logn and n is the instance size, we have reached the root
// which contains the coefficients of the perturbator polynomial
// if we are at level t in the tree, where t = logn and n is the instance size, we have reached the root which
// contains the coefficients of the perturbator polynomial
if (level == betas.size()) {
return prev_level_coeffs[0];
}
Expand Down

0 comments on commit 8a65de1

Please sign in to comment.