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

hack: (aztec3) introduce barretenberg crypto generator parameters hack #408

Merged
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
42 changes: 25 additions & 17 deletions cpp/src/barretenberg/crypto/generators/generator_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ namespace crypto {
namespace generators {
namespace {

// The number of unique base points with default main index with precomputed ladders
// Parameters for generator table construction
struct GeneratorParameters {
size_t num_default_generators; // Number of unique base points with default main index
size_t num_hash_indices; // Number of unique hash indices
size_t num_generators_per_hash_index; // Number of generators per hash index
size_t hash_indices_generator_offset; // Offset for hash index generators
};

// Define BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK to use custom values for generator parameters
// This hack is to avoid breakage due to generators in aztec circuits while maintaining compatibility
// with the barretenberg master.
#ifdef BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK
constexpr GeneratorParameters GEN_PARAMS = {BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK};
#else
#ifdef __wasm__
constexpr size_t num_default_generators = 64;
constexpr size_t num_generators_per_hash_index = 16;
constexpr size_t num_hash_indices = 32;
constexpr size_t hash_indices_generator_offset = 64;
constexpr GeneratorParameters GEN_PARAMS = {64, 16, 32, 64};
// TODO need to resolve memory out of bounds when these are too high
#else
constexpr size_t num_default_generators = 2048;
constexpr size_t num_hash_indices = 32;
constexpr size_t num_generators_per_hash_index = 128;
constexpr size_t hash_indices_generator_offset = 2048;
constexpr GeneratorParameters GEN_PARAMS = {2048, 32, 128, 2048};
#endif
#endif

constexpr size_t num_indexed_generators = num_hash_indices * num_generators_per_hash_index;
constexpr size_t size_of_generator_data_array = hash_indices_generator_offset + num_indexed_generators;
constexpr size_t num_indexed_generators = GEN_PARAMS.num_hash_indices * GEN_PARAMS.num_generators_per_hash_index;
constexpr size_t size_of_generator_data_array = GEN_PARAMS.hash_indices_generator_offset + num_indexed_generators;
constexpr size_t num_generator_types = 3;

ladder_t g1_ladder;
Expand Down Expand Up @@ -216,11 +224,11 @@ std::vector<std::unique_ptr<generator_data>> const& init_generator_data()

global_generator_data.resize(size_of_generator_data_array);

for (size_t i = 0; i < num_default_generators; i++) {
for (size_t i = 0; i < GEN_PARAMS.num_default_generators; i++) {
global_generator_data[i] = compute_generator_data(generators[i], aux_generators[i], skew_generators[i]);
}

for (size_t i = hash_indices_generator_offset; i < size_of_generator_data_array; i++) {
for (size_t i = GEN_PARAMS.hash_indices_generator_offset; i < size_of_generator_data_array; i++) {
global_generator_data[i] = compute_generator_data(generators[i], aux_generators[i], skew_generators[i]);
}

Expand Down Expand Up @@ -264,12 +272,12 @@ generator_data const& get_generator_data(generator_index_t index)
{
auto& global_generator_data = init_generator_data();
if (index.index == 0) {
ASSERT(index.sub_index < num_default_generators);
ASSERT(index.sub_index < GEN_PARAMS.num_default_generators);
return *global_generator_data[index.sub_index];
}
ASSERT(index.index <= num_hash_indices);
ASSERT(index.sub_index < num_generators_per_hash_index);
return *global_generator_data[hash_indices_generator_offset + ((index.index - 1) * num_generators_per_hash_index) +
ASSERT(index.index <= GEN_PARAMS.num_hash_indices);
ASSERT(index.sub_index < GEN_PARAMS.num_generators_per_hash_index);
return *global_generator_data[GEN_PARAMS.hash_indices_generator_offset + ((index.index - 1) * GEN_PARAMS.num_generators_per_hash_index) +
index.sub_index];
}

Expand Down