Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Deduplication in Protogalaxy #8067

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions barretenberg/cpp/.clangd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Diagnostics:
- cert-dc21-cpp
# Noisy. As we don't need to return error types or raw allocations, really unlikely we'd cause problems by ignoring a return type.
- modernize-use-nodiscard
# Misleading; linker error fixed by adding const in declaration
- readability-avoid-const-params-in-decls

--- # this divider is necessary
# Disable some checks for Google Test/Bench
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "barretenberg/polynomials/pow.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp"
#include "barretenberg/protogalaxy/prover_verifier_shared.hpp"
#include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp"
#include "barretenberg/ultra_honk/decider_prover.hpp"
#include "barretenberg/ultra_honk/decider_verifier.hpp"
Expand Down Expand Up @@ -218,7 +219,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
accumulator->relation_parameters = relation_parameters;
accumulator->alphas = alphas;

auto deltas = ProtoGalaxyProver::compute_round_challenge_pows(log_instance_size, FF::random_element());
auto deltas = compute_round_challenge_pows(log_instance_size, FF::random_element());
auto perturbator = ProtoGalaxyProver::compute_perturbator(accumulator, deltas);

// Ensure the constant coefficient of the perturbator is equal to the target sum as indicated by the paper
Expand Down
222 changes: 67 additions & 155 deletions barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include "barretenberg/common/op_count.hpp"
#include "barretenberg/common/thread.hpp"
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/protogalaxy/prover_verifier_shared.hpp"
#include "barretenberg/ultra_honk/oink_prover.hpp"
#include "protogalaxy_prover.hpp"

namespace bb {
// See protogalaxy_prover.hpp for details
template <class ProverInstances_>
Expand Down Expand Up @@ -361,21 +363,6 @@ template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::pertu
}
};

template <class ProverInstances_>
std::vector<typename bb::ProtoGalaxyProver_<ProverInstances_>::FF> bb::ProtoGalaxyProver_<
ProverInstances_>::update_gate_challenges(const FF perturbator_challenge,
const std::vector<FF>& gate_challenges,
const std::vector<FF>& round_challenges)
{
auto log_instance_size = gate_challenges.size();
std::vector<FF> next_gate_challenges(log_instance_size);

for (size_t idx = 0; idx < log_instance_size; idx++) {
next_gate_challenges[idx] = gate_challenges[idx] + perturbator_challenge * round_challenges[idx];
}
return next_gate_challenges;
}

template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::combiner_quotient_round()
{
BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::combiner_quotient_round");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "protogalaxy_verifier.hpp"
#include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp"
#include "barretenberg/protogalaxy/prover_verifier_shared.hpp"
#include "barretenberg/ultra_honk/oink_verifier.hpp"

namespace bb {

template <class VerifierInstances>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,6 @@ template <class VerifierInstances> class ProtoGalaxyVerifier_ {
ProtoGalaxyVerifier_(const std::vector<std::shared_ptr<Instance>>& insts)
: instances(VerifierInstances(insts)){};
~ProtoGalaxyVerifier_() = default;
/**
* @brief Given a new round challenge δ for each iteration of the full ProtoGalaxy protocol, compute the vector
* [δ, δ^2,..., δ^t] where t = logn and n is the size of the instance.
*/
static std::vector<FF> compute_round_challenge_pows(size_t log_instance_size, FF round_challenge)
{
std::vector<FF> pows(log_instance_size);
pows[0] = round_challenge;
for (size_t i = 1; i < log_instance_size; i++) {
pows[i] = pows[i - 1].sqr();
}
return pows;
}

static std::vector<FF> update_gate_challenges(const FF perturbator_challenge,
const std::vector<FF>& gate_challenges,
const std::vector<FF>& round_challenges)
{
auto log_instance_size = gate_challenges.size();
std::vector<FF> next_gate_challenges(log_instance_size);

for (size_t idx = 0; idx < log_instance_size; idx++) {
next_gate_challenges[idx] = gate_challenges[idx] + perturbator_challenge * round_challenges[idx];
}
return next_gate_challenges;
}

std::shared_ptr<Instance> get_accumulator() { return instances[0]; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "barretenberg/protogalaxy/prover_verifier_shared.hpp"

namespace bb {
std::vector<fr> update_gate_challenges(const fr perturbator_challenge,
const std::vector<fr>& gate_challenges,
const std::vector<fr>& round_challenges)
{
auto log_instance_size = gate_challenges.size();
std::vector<fr> next_gate_challenges(log_instance_size);

for (size_t idx = 0; idx < log_instance_size; idx++) {
next_gate_challenges[idx] = gate_challenges[idx] + perturbator_challenge * round_challenges[idx];
}
return next_gate_challenges;
}

/**
* @brief For a new round challenge δ at each iteration of the ProtoGalaxy protocol, compute the vector
* [δ, δ^2,..., δ^t] where t = logn and n is the size of the instance.
*/
std::vector<fr> compute_round_challenge_pows(const size_t log_instance_size, const fr& round_challenge)
{
std::vector<fr> pows(log_instance_size);
pows[0] = round_challenge;
for (size_t i = 1; i < log_instance_size; i++) {
pows[i] = pows[i - 1].sqr();
}
return pows;
}

} // namespace bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include <vector>

namespace bb {
/**
* @brief Compute the gate challenges used int the combiner calculation.
* @details This is Step 8 of the protocol as written in the paper.
*/
std::vector<fr> update_gate_challenges(const fr perturbator_challenge,
const std::vector<fr>& gate_challenges,
const std::vector<fr>& round_challenges);

/**
* @brief For a new round challenge δ at each iteration of the ProtoGalaxy protocol, compute the vector
* [δ, δ^2,..., δ^t] where t = logn and n is the size of the instance.
*/
std::vector<fr> compute_round_challenge_pows(const size_t log_instance_size, const fr& round_challenge);

} // namespace bb
Loading