From 449a7ac488aa892725d8fed62536f22a51efe214 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 2 May 2023 15:43:42 -0400 Subject: [PATCH 1/2] hack: introduce BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK --- .../crypto/generators/generator_data.cpp | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/cpp/src/barretenberg/crypto/generators/generator_data.cpp b/cpp/src/barretenberg/crypto/generators/generator_data.cpp index 982003c682..ce1c484669 100644 --- a/cpp/src/barretenberg/crypto/generators/generator_data.cpp +++ b/cpp/src/barretenberg/crypto/generators/generator_data.cpp @@ -4,22 +4,31 @@ 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. The custom values should be set considering the specific requirements and constraints +// of the aztec circuits to avoid problematic values. +#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; @@ -216,11 +225,11 @@ std::vector> 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]); } @@ -264,12 +273,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]; } From ff5bb9f4d81ee962a38bcdea825dbd1d4013a641 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 2 May 2023 15:46:25 -0400 Subject: [PATCH 2/2] doc: concise --- cpp/src/barretenberg/crypto/generators/generator_data.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/barretenberg/crypto/generators/generator_data.cpp b/cpp/src/barretenberg/crypto/generators/generator_data.cpp index ce1c484669..a0c4e522fa 100644 --- a/cpp/src/barretenberg/crypto/generators/generator_data.cpp +++ b/cpp/src/barretenberg/crypto/generators/generator_data.cpp @@ -14,8 +14,7 @@ struct GeneratorParameters { // 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. The custom values should be set considering the specific requirements and constraints -// of the aztec circuits to avoid problematic values. +// with the barretenberg master. #ifdef BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK constexpr GeneratorParameters GEN_PARAMS = {BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK}; #else