Skip to content

Commit

Permalink
refactor(bb): rearrange namespaces (AztecProtocol#4147)
Browse files Browse the repository at this point in the history
Resolves AztecProtocol/barretenberg#794

---------

Co-authored-by: ludamad <[email protected]>
  • Loading branch information
ludamad and ludamad0 authored Jan 23, 2024
1 parent 35e7012 commit 33e0571
Show file tree
Hide file tree
Showing 236 changed files with 1,608 additions and 1,757 deletions.
20 changes: 12 additions & 8 deletions barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "get_bn254_crs.hpp"
#include "barretenberg/bb/file_io.hpp"

namespace {
std::vector<uint8_t> download_bn254_g1_data(size_t num_points)
{
size_t g1_end = num_points * 64 - 1;
Expand All @@ -26,8 +27,10 @@ std::vector<uint8_t> download_bn254_g2_data()
std::string command = "curl -s '" + url + "'";
return exec_pipe(command);
}
} // namespace

std::vector<bb::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points)
namespace bb {
std::vector<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 +40,9 @@ std::vector<bb::g1::affine_element> get_bn254_g1_data(const std::filesystem::pat
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<bb::g1::affine_element>(num_points);
auto points = std::vector<g1::affine_element>(num_points);
for (size_t i = 0; i < num_points; ++i) {
points[i] = from_buffer<bb::g1::affine_element>(data, i * 64);
points[i] = from_buffer<g1::affine_element>(data, i * 64);
}
return points;
}
Expand All @@ -48,14 +51,14 @@ std::vector<bb::g1::affine_element> get_bn254_g1_data(const std::filesystem::pat
auto data = download_bn254_g1_data(num_points);
write_file(g1_path, data);

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

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

Expand All @@ -64,10 +67,11 @@ bb::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path)

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

auto data = download_bn254_g2_data();
write_file(g2_path, data);
return from_buffer<bb::g2::affine_element>(data.data());
return from_buffer<g2::affine_element>(data.data());
}
} // namespace bb
6 changes: 4 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,7 @@
#include <fstream>
#include <ios>

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);
namespace bb {
std::vector<g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points);
g2::affine_element get_bn254_g2_data(const std::filesystem::path& path);
} // namespace bb
8 changes: 6 additions & 2 deletions barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "get_grumpkin_crs.hpp"

namespace {
std::vector<uint8_t> download_grumpkin_g1_data(size_t num_points)
{
size_t g1_start = 28;
Expand All @@ -19,7 +20,9 @@ std::vector<uint8_t> download_grumpkin_g1_data(size_t num_points)

return data;
}
} // namespace

namespace bb {
std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points)
{
std::filesystem::create_directories(path);
Expand All @@ -35,7 +38,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;
bb::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
points.data(), (char*)data.data(), size_of_points_in_bytes);
return points;
}
Expand All @@ -52,6 +55,7 @@ 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);
bb::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(points.data(), (char*)data.data(), data.size());
srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(points.data(), (char*)data.data(), data.size());
return points;
}
} // namespace bb
6 changes: 5 additions & 1 deletion barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
#include <fstream>
#include <ios>

std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points);
namespace bb {

std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_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 @@ -72,7 +72,7 @@ acir_format::WitnessVector get_witness(std::string const& witness_path)
return acir_format::witness_buf_to_witness_data(witness_data);
}

acir_format::acir_format get_constraint_system(std::string const& bytecode_path)
acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path)
{
auto bytecode = get_bytecode(bytecode_path);
return acir_format::circuit_buf_to_acir_format(bytecode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using Fr = Curve::ScalarField;
*/
void parallel_for_field_element_addition(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
size_t num_cpus = get_num_cpus();
std::vector<std::vector<Fr>> copy_vector(num_cpus);
for (size_t i = 0; i < num_cpus; i++) {
Expand Down Expand Up @@ -72,7 +72,7 @@ void parallel_for_field_element_addition(State& state)
*/
void ff_addition(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
std::vector<Fr> copy_vector(2);
for (size_t j = 0; j < 2; j++) {
copy_vector.emplace_back(Fr::random_element(&engine));
Expand All @@ -97,7 +97,7 @@ void ff_addition(State& state)
*/
void ff_multiplication(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
std::vector<Fr> copy_vector(2);
for (size_t j = 0; j < 2; j++) {
copy_vector.emplace_back(Fr::random_element(&engine));
Expand All @@ -122,7 +122,7 @@ void ff_multiplication(State& state)
*/
void ff_sqr(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
std::vector<Fr> copy_vector(2);
for (size_t j = 0; j < 2; j++) {
copy_vector.emplace_back(Fr::random_element(&engine));
Expand All @@ -147,7 +147,7 @@ void ff_sqr(State& state)
*/
void ff_invert(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
auto element = Fr::random_element(&engine);

for (auto _ : state) {
Expand All @@ -168,7 +168,7 @@ void ff_invert(State& state)
*/
void ff_to_montgomery(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
auto element = Fr::random_element(&engine);

for (auto _ : state) {
Expand All @@ -188,7 +188,7 @@ void ff_to_montgomery(State& state)
*/
void ff_from_montgomery(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
auto element = Fr::random_element(&engine);

for (auto _ : state) {
Expand All @@ -209,7 +209,7 @@ void ff_from_montgomery(State& state)
*/
void ff_reduce(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
auto element = Fr::random_element(&engine);

for (auto _ : state) {
Expand All @@ -230,7 +230,7 @@ void ff_reduce(State& state)
*/
void projective_point_addition(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
std::vector<Curve::Element> copy_vector(2);
for (size_t j = 0; j < 2; j++) {
copy_vector.emplace_back(Curve::Element::random_element(&engine));
Expand All @@ -255,7 +255,7 @@ void projective_point_addition(State& state)
*/
void projective_point_accidental_doubling(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
std::vector<Curve::Element> copy_vector(2);
for (size_t j = 0; j < 2; j++) {
copy_vector.emplace_back(Curve::Element::random_element(&engine));
Expand All @@ -280,7 +280,7 @@ void projective_point_accidental_doubling(State& state)
*/
void projective_point_doubling(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
std::vector<Curve::Element> copy_vector(2);
for (size_t j = 0; j < 2; j++) {
copy_vector.emplace_back(Curve::Element::random_element(&engine));
Expand All @@ -305,7 +305,7 @@ void projective_point_doubling(State& state)
*/
void scalar_multiplication(State& state)
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
Curve::Element element = Curve::Element::random_element(&engine);
Fr scalar = Fr::random_element(&engine);

Expand Down Expand Up @@ -347,7 +347,7 @@ void cycle_waste(State& state)
void sequential_copy(State& state)
{

numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
for (auto _ : state) {
state.PauseTiming();
size_t num_cycles = 1 << static_cast<size_t>(state.range(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/eccvm/eccvm_composer.hpp"
#include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/goblin/goblin.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::vector<OpeningClaim> opening_claims(MAX_POLYNOMIAL_DEGREE_LOG2 - MIN_POLYNO

void ipa_open(State& state) noexcept
{
numeric::random::Engine& engine = numeric::random::get_debug_engine();
numeric::RNG& engine = numeric::get_debug_randomness();
for (auto _ : state) {
state.PauseTiming();
size_t n = 1 << static_cast<size_t>(state.range(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/plonk/composer/standard_composer.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"

Expand All @@ -13,8 +13,8 @@ using StandardPlonk = bb::plonk::StandardComposer;
static void construct_proof_standard_power_of_2(State& state) noexcept
{
auto log2_of_gates = static_cast<size_t>(state.range(0));
bench_utils::construct_proof_with_specified_num_iterations<bb::plonk::StandardComposer>(
state, &bench_utils::generate_basic_arithmetic_circuit<bb::StandardCircuitBuilder>, log2_of_gates);
bb::mock_proofs::construct_proof_with_specified_num_iterations<bb::plonk::StandardComposer>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<bb::StandardCircuitBuilder>, log2_of_gates);
}

BENCHMARK(construct_proof_standard_power_of_2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

Expand All @@ -23,7 +23,7 @@ void fold_one(State& state) noexcept

const auto construct_instance = [&]() {
Builder builder;
bench_utils::generate_basic_arithmetic_circuit(builder, log2_num_gates);
bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates);
return composer.create_instance(builder);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace benchmark;

namespace {
auto& engine = numeric::random::get_debug_engine();
auto& engine = bb::numeric::get_debug_randomness();
}

using FF = bb::fr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <benchmark/benchmark.h>

namespace {
auto& engine = numeric::random::get_debug_engine();
auto& engine = bb::numeric::get_debug_randomness();
}

using namespace bb::honk::sumcheck;
Expand Down
Loading

0 comments on commit 33e0571

Please sign in to comment.