Skip to content

Commit

Permalink
refactor: barretenberg => bb namespace shortening (AztecProtocol#4066)
Browse files Browse the repository at this point in the history
This is the first phase of namespace refactors planned. Just renames
barretenberg=>bb.

The followups will mostly collapse long namespaces, e.g.
bb::plonk::crypto::aes128 => bb::crypto

---------

Co-authored-by: ludamad <[email protected]>
  • Loading branch information
ludamad and ludamad0 authored Jan 16, 2024
1 parent ed369dc commit 2ee0ac7
Show file tree
Hide file tree
Showing 455 changed files with 2,243 additions and 2,412 deletions.
2 changes: 1 addition & 1 deletion barretenberg/cpp/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
"source": [
"# Convert a 256-bit hex string. Outputs four 64-bit limbs that can be used to construct a native field element.\n",
"# Idea: s == barretenberg::fr(hex_to_field(s)).to_montgomery_form() is true as hex strings if s was in Montgomery form.\n",
"# Idea: s == bb::fr(hex_to_field(s)).to_montgomery_form() is true as hex strings if s was in Montgomery form.\n",
"def hex_to_field(s):\n",
" s = s[2:] # slice off leading 0x\n",
" data = [s[48:64], s[32:48], s[16:32], s[0:16]]\n",
Expand Down
16 changes: 8 additions & 8 deletions barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::vector<uint8_t> download_bn254_g2_data()
return exec_pipe(command);
}

std::vector<barretenberg::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points)
std::vector<bb::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points)
{
std::filesystem::create_directories(path);

Expand All @@ -37,9 +37,9 @@ std::vector<barretenberg::g1::affine_element> get_bn254_g1_data(const std::files
if (g1_file_size >= num_points * 64 && g1_file_size % 64 == 0) {
vinfo("using cached crs of size ", std::to_string(g1_file_size / 64), " at ", g1_path);
auto data = read_file(g1_path, g1_file_size);
auto points = std::vector<barretenberg::g1::affine_element>(num_points);
auto points = std::vector<bb::g1::affine_element>(num_points);
for (size_t i = 0; i < num_points; ++i) {
points[i] = from_buffer<barretenberg::g1::affine_element>(data, i * 64);
points[i] = from_buffer<bb::g1::affine_element>(data, i * 64);
}
return points;
}
Expand All @@ -48,14 +48,14 @@ std::vector<barretenberg::g1::affine_element> get_bn254_g1_data(const std::files
auto data = download_bn254_g1_data(num_points);
write_file(g1_path, data);

auto points = std::vector<barretenberg::g1::affine_element>(num_points);
auto points = std::vector<bb::g1::affine_element>(num_points);
for (size_t i = 0; i < num_points; ++i) {
points[i] = from_buffer<barretenberg::g1::affine_element>(data, i * 64);
points[i] = from_buffer<bb::g1::affine_element>(data, i * 64);
}
return points;
}

barretenberg::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path)
bb::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path)
{
std::filesystem::create_directories(path);

Expand All @@ -64,10 +64,10 @@ barretenberg::g2::affine_element get_bn254_g2_data(const std::filesystem::path&

if (g2_file_size == 128) {
auto data = read_file(g2_path);
return from_buffer<barretenberg::g2::affine_element>(data.data());
return from_buffer<bb::g2::affine_element>(data.data());
}

auto data = download_bn254_g2_data();
write_file(g2_path, data);
return from_buffer<barretenberg::g2::affine_element>(data.data());
return from_buffer<bb::g2::affine_element>(data.data());
}
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
#include <fstream>
#include <ios>

std::vector<barretenberg::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points);
barretenberg::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path);
std::vector<bb::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points);
bb::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path);
5 changes: 2 additions & 3 deletions barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::file
auto data = read_file(file, 28 + num_points * 64);
auto points = std::vector<curve::Grumpkin::AffineElement>(num_points);
auto size_of_points_in_bytes = num_points * 64;
barretenberg::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
bb::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
points.data(), (char*)data.data(), size_of_points_in_bytes);
return points;
}
Expand All @@ -52,7 +52,6 @@ std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::file
new_size_file.close();

auto points = std::vector<curve::Grumpkin::AffineElement>(num_points);
barretenberg::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
points.data(), (char*)data.data(), data.size());
bb::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(points.data(), (char*)data.data(), data.size());
return points;
}
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string>
#include <vector>

using namespace barretenberg;
using namespace bb;

std::string getHomeDir()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <benchmark/benchmark.h>

using namespace benchmark;
using namespace barretenberg;
using namespace bb;
namespace {
using Curve = curve::BN254;
using Fr = Curve::ScalarField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Builder generate_trace(size_t target_num_gates)

void eccvm_generate_prover(State& state) noexcept
{
barretenberg::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");

size_t target_num_gates = 1 << static_cast<size_t>(state.range(0));
for (auto _ : state) {
Expand All @@ -57,7 +57,7 @@ void eccvm_generate_prover(State& state) noexcept

void eccvm_prove(State& state) noexcept
{
barretenberg::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");

size_t target_num_gates = 1 << static_cast<size_t>(state.range(0));
Builder builder = generate_trace(target_num_gates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include "barretenberg/ultra_honk/ultra_composer.hpp"

using namespace benchmark;
using namespace barretenberg;
using namespace bb;
using namespace proof_system;

namespace {
void goblin_full(State& state) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
barretenberg::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
bb::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");

Goblin goblin;

Expand Down Expand Up @@ -48,8 +48,8 @@ void goblin_full(State& state) noexcept

void goblin_accumulate(State& state) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
barretenberg::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
bb::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");

Goblin goblin;

Expand All @@ -74,8 +74,8 @@ void goblin_accumulate(State& state) noexcept

void goblin_eccvm_prove(State& state) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
barretenberg::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
bb::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");

Goblin goblin;

Expand All @@ -102,8 +102,8 @@ void goblin_eccvm_prove(State& state) noexcept

void goblin_translator_prove(State& state) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
barretenberg::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
bb::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin");

Goblin goblin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <benchmark/benchmark.h>

using namespace benchmark;
using namespace barretenberg;
using namespace bb;
using namespace proof_system;
using namespace proof_system::honk::pcs::ipa;
namespace {
Expand All @@ -17,8 +17,8 @@ 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<barretenberg::srs::factories::CrsFactory<curve::Grumpkin>> crs_factory(
new barretenberg::srs::factories::FileCrsFactory<curve::Grumpkin>("../srs_db/grumpkin", 1 << 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// CALLGRIND_STOP_INSTRUMENTATION;
// CALLGRIND_DUMP_STATS;

using namespace barretenberg;
using namespace bb;

// constexpr size_t NUM_GATES = 1 << 10;

Expand Down Expand Up @@ -44,12 +44,12 @@ using namespace barretenberg;
// }
constexpr size_t NUM_POINTS = 1 << 16;
std::vector<fr> scalars;
static barretenberg::evaluation_domain small_domain;
static barretenberg::evaluation_domain large_domain;
static bb::evaluation_domain small_domain;
static bb::evaluation_domain large_domain;

const auto init = []() {
small_domain = barretenberg::evaluation_domain(NUM_POINTS);
large_domain = barretenberg::evaluation_domain(NUM_POINTS * 4);
small_domain = bb::evaluation_domain(NUM_POINTS);
large_domain = bb::evaluation_domain(NUM_POINTS * 4);

fr element = fr::random_element();
fr accumulator = element;
Expand All @@ -66,7 +66,7 @@ const auto init = []() {
// constexpr double add_to_mixed_add_complexity = 1.36;

auto reference_string =
std::make_shared<barretenberg::srs::factories::FileProverCrs<curve::BN254>>(NUM_POINTS, "../srs_db/ignition");
std::make_shared<bb::srs::factories::FileProverCrs<curve::BN254>>(NUM_POINTS, "../srs_db/ignition");

int pippenger()
{
Expand All @@ -84,7 +84,7 @@ int pippenger()
int coset_fft_split()
{
std::chrono::steady_clock::time_point time_start = std::chrono::steady_clock::now();
barretenberg::polynomial_arithmetic::coset_fft(&scalars[0], small_domain, small_domain, 4);
bb::polynomial_arithmetic::coset_fft(&scalars[0], small_domain, small_domain, 4);
std::chrono::steady_clock::time_point time_end = std::chrono::steady_clock::now();
std::chrono::microseconds diff = std::chrono::duration_cast<std::chrono::microseconds>(time_end - time_start);
std::cout << "run time: " << diff.count() << "us" << std::endl;
Expand All @@ -94,7 +94,7 @@ int coset_fft_split()
int coset_fft_regular()
{
std::chrono::steady_clock::time_point time_start = std::chrono::steady_clock::now();
barretenberg::polynomial_arithmetic::coset_fft(&scalars[0], large_domain);
bb::polynomial_arithmetic::coset_fft(&scalars[0], large_domain);
std::chrono::steady_clock::time_point time_end = std::chrono::steady_clock::now();
std::chrono::microseconds diff = std::chrono::duration_cast<std::chrono::microseconds>(time_end - time_start);
std::cout << "run time: " << diff.count() << "us" << std::endl;
Expand All @@ -103,7 +103,7 @@ int coset_fft_regular()

int main()
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_crs_factory("../srs_db/ignition");
std::cout << "initializing" << std::endl;
init();
std::cout << "executing normal fft" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using Composer = proof_system::plonk::StandardComposer;

void generate_test_plonk_circuit(Builder& builder, size_t num_gates)
{
plonk::stdlib::field_t a(plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element()));
plonk::stdlib::field_t b(plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element()));
plonk::stdlib::field_t a(plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
plonk::stdlib::field_t b(plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
plonk::stdlib::field_t c(&builder);
for (size_t i = 0; i < (num_gates / 4) - 4; ++i) {
c = a + b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using Builder = Flavor::CircuitBuilder;
// Fold one instance into an accumulator.
void fold_one(State& state) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_crs_factory("../srs_db/ignition");

auto log2_num_gates = static_cast<size_t>(state.range(0));
auto composer = UltraComposer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace {
auto& engine = numeric::random::get_debug_engine();
}

using FF = barretenberg::fr;
using barretenberg::BarycentricData;
using barretenberg::Univariate;
using FF = bb::fr;
using bb::BarycentricData;
using bb::Univariate;

namespace proof_system::benchmark {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace proof_system::honk::sumcheck;

namespace proof_system::benchmark::relations {

using Fr = barretenberg::fr;
using Fr = bb::fr;
using Fq = grumpkin::fr;

template <typename Flavor, typename Relation> void execute_relation(::benchmark::State& state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ namespace bench_utils {
*/
template <typename Builder> void generate_basic_arithmetic_circuit(Builder& builder, size_t log2_num_gates)
{
proof_system::plonk::stdlib::field_t a(
proof_system::plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element()));
proof_system::plonk::stdlib::field_t b(
proof_system::plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element()));
proof_system::plonk::stdlib::field_t a(proof_system::plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
proof_system::plonk::stdlib::field_t b(proof_system::plonk::stdlib::witness_t(&builder, bb::fr::random_element()));
proof_system::plonk::stdlib::field_t c(&builder);
size_t passes = (1UL << log2_num_gates) / 4 - 4;
if (static_cast<int>(passes) <= 0) {
Expand Down Expand Up @@ -213,7 +211,7 @@ template <typename Composer>
void construct_proof_with_specified_num_iterations(
State& state, void (*test_circuit_function)(typename Composer::CircuitBuilder&, size_t), size_t num_iterations)
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_crs_factory("../srs_db/ignition");

Composer composer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ BBERG_PROFILE static void test_round_inner(State& state, honk::UltraProver& prov
}
BBERG_PROFILE static void test_round(State& state, size_t index) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_crs_factory("../srs_db/ignition");

for (auto _ : state) {
state.PauseTiming();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ BBERG_PROFILE static void test_round_inner(State& state, plonk::UltraProver& pro
}
BBERG_PROFILE static void test_round(State& state, size_t index) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_crs_factory("../srs_db/ignition");
for (auto _ : state) {
state.PauseTiming();
plonk::UltraComposer composer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct BasicPlonkKeyAndTranscript {

BasicPlonkKeyAndTranscript get_plonk_key_and_transcript()
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");
bb::srs::init_crs_factory("../srs_db/ignition");
auto inner_composer = plonk::UltraComposer();
auto builder = typename plonk::UltraComposer::CircuitBuilder();
bench_utils::generate_basic_arithmetic_circuit(builder, 16);
Expand All @@ -55,7 +55,7 @@ template <typename Flavor, typename Widget> void execute_widget(::benchmark::Sta
BasicPlonkKeyAndTranscript data = get_plonk_key_and_transcript();
Widget widget(data.key);
for (auto _ : state) {
widget.compute_quotient_contribution(barretenberg::fr::random_element(), data.transcript);
widget.compute_quotient_contribution(bb::fr::random_element(), data.transcript);
}
}

Expand All @@ -67,7 +67,7 @@ template <typename Widget> void quotient_contribution(::benchmark::State& state)
#ifdef GET_PER_ROW_TIME
auto start = std::chrono::high_resolution_clock::now();
#endif
widget.compute_quotient_contribution(barretenberg::fr::random_element(), data.transcript);
widget.compute_quotient_contribution(bb::fr::random_element(), data.transcript);
#ifdef GET_PER_ROW_TIME
auto end = std::chrono::high_resolution_clock::now();
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
Expand Down Expand Up @@ -100,11 +100,11 @@ template <typename Widget> void accumulate_contribution(::benchmark::State& stat
using FFTKernel = typename Widget::FFTKernel;

auto polynomials = FFTGetter::get_polynomials(data.key.get(), FFTKernel::get_required_polynomial_ids());
auto challenges = FFTGetter::get_challenges(
data.transcript, barretenberg::fr::random_element(), FFTKernel::quotient_required_challenges);
auto challenges =
FFTGetter::get_challenges(data.transcript, bb::fr::random_element(), FFTKernel::quotient_required_challenges);

for (auto _ : state) {
barretenberg::fr result{ 0 };
bb::fr result{ 0 };
FFTKernel::accumulate_contribution(polynomials, challenges, result, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <typename Curve> class OpeningPair {
*/
template <typename Curve> class ProverOpeningClaim {
using Fr = typename Curve::ScalarField;
using Polynomial = barretenberg::Polynomial<Fr>;
using Polynomial = bb::Polynomial<Fr>;

public:
Polynomial polynomial; // p
Expand Down Expand Up @@ -59,7 +59,7 @@ template <typename Curve> class OpeningClaim {
* @param polynomial the claimed witness polynomial p(X)
* @return C = Commit(p(X)) && p(r) = v
*/
bool verify(std::shared_ptr<CK> ck, const barretenberg::Polynomial<Fr>& polynomial) const
bool verify(std::shared_ptr<CK> ck, const bb::Polynomial<Fr>& polynomial) const
{
Fr real_eval = polynomial.evaluate(opening_pair.challenge);
if (real_eval != opening_pair.evaluation) {
Expand Down
Loading

0 comments on commit 2ee0ac7

Please sign in to comment.