Skip to content

Commit

Permalink
refactor: collapse bb::honk (#4318)
Browse files Browse the repository at this point in the history
Per crypto team thinking, the following namespaces
```
namespace bb::honk {
namespace bb::honk::flavor {
namespace bb::honk::grand_product_library {
namespace bb::honk::logderivative_library {
namespace bb::honk::pcs {
namespace bb::honk::pcs::gemini {
namespace bb::honk::pcs::ipa {
namespace bb::honk::pcs::kzg {
namespace bb::honk::pcs::shplonk {
namespace bb::honk::pcs::zeromorph {
namespace bb::honk::permutation_library {
namespace bb::honk::sumcheck {
```
are now all in 'bb'. If any names are unclear, they should be improved
(feel free to point them out here). If details really need to be grouped
and used by multiple source units, they can have a namespace like I kept
with gemini partially.

---------

Co-authored-by: ludamad <adam@aztecprotocol.com>
  • Loading branch information
ludamad and ludamad0 authored Feb 1, 2024
1 parent 1615803 commit 5853af4
Show file tree
Hide file tree
Showing 176 changed files with 780 additions and 877 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using namespace benchmark;
using namespace bb;

using Flavor = honk::flavor::ECCVM;
using Flavor = ECCVMFlavor;
using Builder = ECCVMCircuitBuilder<Flavor>;
using Composer = honk::ECCVMComposer;
using Composer = ECCVMComposer;

namespace {

Expand Down
32 changes: 13 additions & 19 deletions barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,22 @@

using namespace benchmark;
using namespace bb;
using namespace bb::honk::pcs::ipa;

namespace {
using Curve = curve::Grumpkin;
using Fr = Curve::ScalarField;
using IPA = IPA<Curve>;
using OpeningPair = honk::pcs::OpeningPair<Curve>;
using OpeningClaim = honk::pcs::OpeningClaim<Curve>;
using Polynomial = Polynomial<Curve::ScalarField>;
using CommitmentKey = honk::pcs::CommitmentKey<Curve>;
using VerifierCommitmentKey = honk::pcs::VerifierCommitmentKey<Curve>;

constexpr size_t MIN_POLYNOMIAL_DEGREE_LOG2 = 10;
constexpr size_t MAX_POLYNOMIAL_DEGREE_LOG2 = 16;
std::shared_ptr<bb::srs::factories::CrsFactory<curve::Grumpkin>> crs_factory(
new bb::srs::factories::FileCrsFactory<curve::Grumpkin>("../srs_db/grumpkin", 1 << 16));

auto ck = std::make_shared<CommitmentKey>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, crs_factory);
auto vk = std::make_shared<VerifierCommitmentKey>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, crs_factory);
auto ck = std::make_shared<CommitmentKey<Curve>>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, crs_factory);
auto vk = std::make_shared<VerifierCommitmentKey<Curve>>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, crs_factory);

std::vector<std::shared_ptr<honk::BaseTranscript>> prover_transcripts(MAX_POLYNOMIAL_DEGREE_LOG2 -
MIN_POLYNOMIAL_DEGREE_LOG2 + 1);
std::vector<OpeningClaim> opening_claims(MAX_POLYNOMIAL_DEGREE_LOG2 - MIN_POLYNOMIAL_DEGREE_LOG2 + 1);
std::vector<std::shared_ptr<BaseTranscript>> prover_transcripts(MAX_POLYNOMIAL_DEGREE_LOG2 -
MIN_POLYNOMIAL_DEGREE_LOG2 + 1);
std::vector<OpeningClaim<Curve>> opening_claims(MAX_POLYNOMIAL_DEGREE_LOG2 - MIN_POLYNOMIAL_DEGREE_LOG2 + 1);

void ipa_open(State& state) noexcept
{
Expand All @@ -33,19 +27,19 @@ void ipa_open(State& state) noexcept
state.PauseTiming();
size_t n = 1 << static_cast<size_t>(state.range(0));
// Construct the polynomial
Polynomial poly(n);
Polynomial<Fr> poly(n);
for (size_t i = 0; i < n; ++i) {
poly[i] = Fr::random_element(&engine);
}
auto x = Fr::random_element(&engine);
auto eval = poly.evaluate(x);
const OpeningPair opening_pair = { x, eval };
const OpeningClaim opening_claim{ opening_pair, ck->commit(poly) };
const OpeningPair<Curve> opening_pair = { x, eval };
const OpeningClaim<Curve> opening_claim{ opening_pair, ck->commit(poly) };
// initialize empty prover transcript
auto prover_transcript = std::make_shared<honk::BaseTranscript>();
auto prover_transcript = std::make_shared<BaseTranscript>();
state.ResumeTiming();
// Compute proof
IPA::compute_opening_proof(ck, opening_pair, poly, prover_transcript);
IPA<Curve>::compute_opening_proof(ck, opening_pair, poly, prover_transcript);
// Store info for verifier
prover_transcripts[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2] = prover_transcript;
opening_claims[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2] = opening_claim;
Expand All @@ -59,10 +53,10 @@ void ipa_verify(State& state) noexcept
auto prover_transcript = prover_transcripts[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2];
auto opening_claim = opening_claims[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2];
// initialize verifier transcript from proof data
auto verifier_transcript = std::make_shared<honk::BaseTranscript>(prover_transcript->proof_data);
auto verifier_transcript = std::make_shared<BaseTranscript>(prover_transcript->proof_data);

state.ResumeTiming();
auto result = IPA::verify(vk, opening_claim, verifier_transcript);
auto result = IPA<Curve>::verify(vk, opening_claim, verifier_transcript);
ASSERT(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

using namespace benchmark;

namespace bb::honk {
using Flavor = flavor::Ultra;
namespace bb {
using Flavor = UltraFlavor;
using Instance = ProverInstance_<Flavor>;
using Instances = ProverInstances_<Flavor, 2>;
using ProtoGalaxyProver = ProtoGalaxyProver_<Instances>;
Expand Down Expand Up @@ -38,6 +38,6 @@ void fold_one(State& state) noexcept
}

BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
} // namespace bb::honk
} // namespace bb

BENCHMARK_MAIN();
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace {
auto& engine = bb::numeric::get_debug_randomness();
}

using namespace bb::honk::sumcheck;

namespace bb::benchmark::relations {

using Fr = bb::fr;
Expand All @@ -33,28 +31,28 @@ template <typename Flavor, typename Relation> void execute_relation(::benchmark:
Relation::accumulate(accumulator, new_value, params, 1);
}
}
BENCHMARK(execute_relation<honk::flavor::Ultra, UltraArithmeticRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::Ultra, GenPermSortRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::Ultra, EllipticRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::Ultra, AuxiliaryRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::Ultra, LookupRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::Ultra, UltraPermutationRelation<Fr>>);

BENCHMARK(execute_relation<honk::flavor::GoblinUltra, EccOpQueueRelation<Fr>>);

BENCHMARK(execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorDecompositionRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorOpcodeConstraintRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorAccumulatorTransferRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorGenPermSortRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorNonNativeFieldRelation<Fr>>);
BENCHMARK(execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorPermutationRelation<Fr>>);

BENCHMARK(execute_relation<honk::flavor::ECCVM, ECCVMLookupRelation<Fq>>);
BENCHMARK(execute_relation<honk::flavor::ECCVM, ECCVMMSMRelation<Fq>>);
BENCHMARK(execute_relation<honk::flavor::ECCVM, ECCVMPointTableRelation<Fq>>);
BENCHMARK(execute_relation<honk::flavor::ECCVM, ECCVMSetRelation<Fq>>);
BENCHMARK(execute_relation<honk::flavor::ECCVM, ECCVMTranscriptRelation<Fq>>);
BENCHMARK(execute_relation<honk::flavor::ECCVM, ECCVMWnafRelation<Fq>>);
BENCHMARK(execute_relation<UltraFlavor, UltraArithmeticRelation<Fr>>);
BENCHMARK(execute_relation<UltraFlavor, GenPermSortRelation<Fr>>);
BENCHMARK(execute_relation<UltraFlavor, EllipticRelation<Fr>>);
BENCHMARK(execute_relation<UltraFlavor, AuxiliaryRelation<Fr>>);
BENCHMARK(execute_relation<UltraFlavor, LookupRelation<Fr>>);
BENCHMARK(execute_relation<UltraFlavor, UltraPermutationRelation<Fr>>);

BENCHMARK(execute_relation<GoblinUltraFlavor, EccOpQueueRelation<Fr>>);

BENCHMARK(execute_relation<GoblinTranslatorFlavor, GoblinTranslatorDecompositionRelation<Fr>>);
BENCHMARK(execute_relation<GoblinTranslatorFlavor, GoblinTranslatorOpcodeConstraintRelation<Fr>>);
BENCHMARK(execute_relation<GoblinTranslatorFlavor, GoblinTranslatorAccumulatorTransferRelation<Fr>>);
BENCHMARK(execute_relation<GoblinTranslatorFlavor, GoblinTranslatorGenPermSortRelation<Fr>>);
BENCHMARK(execute_relation<GoblinTranslatorFlavor, GoblinTranslatorNonNativeFieldRelation<Fr>>);
BENCHMARK(execute_relation<GoblinTranslatorFlavor, GoblinTranslatorPermutationRelation<Fr>>);

BENCHMARK(execute_relation<ECCVMFlavor, ECCVMLookupRelation<Fq>>);
BENCHMARK(execute_relation<ECCVMFlavor, ECCVMMSMRelation<Fq>>);
BENCHMARK(execute_relation<ECCVMFlavor, ECCVMPointTableRelation<Fq>>);
BENCHMARK(execute_relation<ECCVMFlavor, ECCVMSetRelation<Fq>>);
BENCHMARK(execute_relation<ECCVMFlavor, ECCVMTranscriptRelation<Fq>>);
BENCHMARK(execute_relation<ECCVMFlavor, ECCVMWnafRelation<Fq>>);

} // namespace bb::benchmark::relations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ template <typename Builder> void generate_basic_arithmetic_circuit(Builder& buil
}

// ultrahonk
inline honk::UltraProver get_prover(honk::UltraComposer& composer,
void (*test_circuit_function)(honk::UltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
inline UltraProver get_prover(UltraComposer& composer,
void (*test_circuit_function)(UltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
{
honk::UltraComposer::CircuitBuilder builder;
UltraComposer::CircuitBuilder builder;
test_circuit_function(builder, num_iterations);
std::shared_ptr<honk::UltraComposer::Instance> instance = composer.create_instance(builder);
std::shared_ptr<UltraComposer::Instance> instance = composer.create_instance(builder);
return composer.create_prover(instance);
}

Expand All @@ -70,7 +70,7 @@ inline plonk::Prover get_prover(plonk::StandardComposer& composer,

// ultraplonk
inline plonk::UltraProver get_prover(plonk::UltraComposer& composer,
void (*test_circuit_function)(honk::UltraComposer::CircuitBuilder&, size_t),
void (*test_circuit_function)(UltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
{
plonk::UltraComposer::CircuitBuilder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void construct_proof_ultrahonk(State& state,
void (*test_circuit_function)(UltraCircuitBuilder&, size_t)) noexcept
{
size_t num_iterations = 10; // 10x the circuit
bb::mock_proofs::construct_proof_with_specified_num_iterations<honk::UltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<UltraComposer>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -24,7 +24,7 @@ static void construct_proof_ultrahonk(State& state,
static void construct_proof_ultrahonk_power_of_2(State& state) noexcept
{
auto log2_of_gates = static_cast<size_t>(state.range(0));
bb::mock_proofs::construct_proof_with_specified_num_iterations<honk::UltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<UltraComposer>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum {
* @param prover - The ultrahonk prover.
* @param index - The pass to measure.
**/
BBERG_PROFILE static void test_round_inner(State& state, honk::UltraProver& prover, size_t index) noexcept
BBERG_PROFILE static void test_round_inner(State& state, UltraProver& prover, size_t index) noexcept
{
auto time_if_index = [&](size_t target_index, auto&& func) -> void {
if (index == target_index) {
Expand All @@ -53,9 +53,9 @@ BBERG_PROFILE static void test_round(State& state, size_t index) noexcept

for (auto _ : state) {
state.PauseTiming();
honk::UltraComposer composer;
UltraComposer composer;
// TODO(https://github.com/AztecProtocol/barretenberg/issues/761) benchmark both sparse and dense circuits
honk::UltraProver prover = bb::mock_proofs::get_prover(
UltraProver prover = bb::mock_proofs::get_prover(
composer, &bb::stdlib::generate_ecdsa_verification_test_circuit<UltraCircuitBuilder>, 10);
test_round_inner(state, prover, index);
state.ResumeTiming();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "barretenberg/commitment_schemes/commitment_key.hpp"
#include "barretenberg/polynomials/polynomial.hpp"

namespace bb::honk::pcs {
namespace bb {
/**
* @brief Opening pair (r,v) for some witness polynomial p(X) such that p(r) = v
*
Expand Down Expand Up @@ -72,4 +72,4 @@ template <typename Curve> class OpeningClaim {

bool operator==(const OpeningClaim& other) const = default;
};
} // namespace bb::honk::pcs
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

namespace bb {

template <typename Curve>
std::shared_ptr<honk::pcs::CommitmentKey<Curve>> create_commitment_key(const size_t num_points)
template <typename Curve> std::shared_ptr<CommitmentKey<Curve>> create_commitment_key(const size_t num_points)
{
std::string srs_path;
if constexpr (std::same_as<Curve, curve::BN254>) {
Expand All @@ -16,7 +15,7 @@ std::shared_ptr<honk::pcs::CommitmentKey<Curve>> create_commitment_key(const siz
srs_path = "../srs_db/grumpkin";
}
auto crs_factory = std::make_shared<bb::srs::factories::FileCrsFactory<Curve>>(srs_path, num_points);
return std::make_shared<honk::pcs::CommitmentKey<Curve>>(num_points, crs_factory);
return std::make_shared<CommitmentKey<Curve>>(num_points, crs_factory);
}

constexpr size_t MAX_LOG_NUM_POINTS = 24;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <memory>
#include <string_view>

namespace bb::honk::pcs {
namespace bb {

/**
* @brief CommitmentKey object over a pairing group 𝔾₁.
Expand Down Expand Up @@ -74,4 +74,4 @@ template <class Curve> class CommitmentKey {
std::shared_ptr<bb::srs::factories::ProverCrs<Curve>> srs;
};

} // namespace bb::honk::pcs
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <gtest/gtest.h>

namespace bb::honk::pcs {
namespace bb {

template <class CK> inline std::shared_ptr<CK> CreateCommitmentKey();

Expand Down Expand Up @@ -202,8 +202,5 @@ typename std::shared_ptr<VerifierCommitmentKey<Curve>> CommitmentTest<Curve>::ve

using CommitmentSchemeParams = ::testing::Types<curve::BN254>;
using IpaCommitmentSchemeParams = ::testing::Types<curve::Grumpkin>;
// IMPROVEMENT: reinstate typed-tests for multiple field types, i.e.:
// using CommitmentSchemeParams =
// ::testing::Types<fake::Params<bb::g1>, fake::Params<grumpkin::g1>, kzg::Params>;

} // namespace bb::honk::pcs
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* The verifier is able to computed the simulated commitments to A₀₊(X) and A₀₋(X)
* since they are linear-combinations of the commitments [fⱼ] and [gⱼ].
*/
namespace bb::honk::pcs::gemini {
namespace bb {

/**
* @brief Computes d-1 fold polynomials Fold_i, i = 1, ..., d-1
Expand Down Expand Up @@ -141,7 +141,7 @@ std::vector<typename bb::Polynomial<typename Curve::ScalarField>> GeminiProver_<
* @param r_challenge univariate opening challenge
*/
template <typename Curve>
ProverOutput<Curve> GeminiProver_<Curve>::compute_fold_polynomial_evaluations(
GeminiProverOutput<Curve> GeminiProver_<Curve>::compute_fold_polynomial_evaluations(
std::span<const Fr> mle_opening_point, std::vector<Polynomial>&& gemini_polynomials, const Fr& r_challenge)
{
const size_t num_variables = mle_opening_point.size(); // m
Expand All @@ -150,7 +150,7 @@ ProverOutput<Curve> GeminiProver_<Curve>::compute_fold_polynomial_evaluations(
Polynomial& batched_G = gemini_polynomials[1]; // G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X)

// Compute univariate opening queries rₗ = r^{2ˡ} for l = 0, 1, ..., m-1
std::vector<Fr> r_squares = squares_of_r(r_challenge, num_variables);
std::vector<Fr> r_squares = gemini::squares_of_r(r_challenge, num_variables);

// Compute G/r
Fr r_inv = r_challenge.invert();
Expand Down Expand Up @@ -188,4 +188,4 @@ ProverOutput<Curve> GeminiProver_<Curve>::compute_fold_polynomial_evaluations(

template class GeminiProver_<curve::BN254>;
template class GeminiProver_<curve::Grumpkin>;
}; // namespace bb::honk::pcs::gemini
}; // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* The verifier is able to computed the simulated commitments to A₀₊(X) and A₀₋(X)
* since they are linear-combinations of the commitments [fⱼ] and [gⱼ].
*/
namespace bb::honk::pcs::gemini {
namespace bb {

/**
* @brief Prover output (evalutation pair, witness) that can be passed on to Shplonk batch opening.
Expand All @@ -57,11 +57,12 @@ namespace bb::honk::pcs::gemini {
* ]
* @tparam Curve CommitmentScheme parameters
*/
template <typename Curve> struct ProverOutput {
template <typename Curve> struct GeminiProverOutput {
std::vector<OpeningPair<Curve>> opening_pairs;
std::vector<bb::Polynomial<typename Curve::ScalarField>> witnesses;
};

namespace gemini {
/**
* @brief Compute powers of challenge ρ
*
Expand Down Expand Up @@ -96,6 +97,7 @@ template <class Fr> inline std::vector<Fr> squares_of_r(const Fr r, const size_t
}
return squares;
};
} // namespace gemini

template <typename Curve> class GeminiProver_ {
using Fr = typename Curve::ScalarField;
Expand All @@ -106,10 +108,10 @@ template <typename Curve> class GeminiProver_ {
Polynomial&& batched_unshifted,
Polynomial&& batched_to_be_shifted);

static ProverOutput<Curve> compute_fold_polynomial_evaluations(std::span<const Fr> mle_opening_point,
std::vector<Polynomial>&& gemini_polynomials,
const Fr& r_challenge);
}; // namespace bb::honk::pcs::gemini
static GeminiProverOutput<Curve> compute_fold_polynomial_evaluations(std::span<const Fr> mle_opening_point,
std::vector<Polynomial>&& gemini_polynomials,
const Fr& r_challenge);
}; // namespace bb

template <typename Curve> class GeminiVerifier_ {
using Fr = typename Curve::ScalarField;
Expand Down Expand Up @@ -148,7 +150,7 @@ template <typename Curve> class GeminiVerifier_ {

// compute vector of powers of random evaluation point r
const Fr r = transcript->get_challenge("Gemini:r");
std::vector<Fr> r_squares = squares_of_r(r, num_variables);
std::vector<Fr> r_squares = gemini::squares_of_r(r, num_variables);

// Get evaluations a_i, i = 0,...,m-1 from transcript
std::vector<Fr> evaluations;
Expand Down Expand Up @@ -261,7 +263,6 @@ template <typename Curve> class GeminiVerifier_ {

return { C0_r_pos, C0_r_neg };
}
};

}; // namespace bb::honk::pcs::gemini

} // namespace bb::honk::pcs::gemini
} // namespace bb
Loading

0 comments on commit 5853af4

Please sign in to comment.