Barretenberg
The ZK-SNARK library at the core of Aztec
|
Generates plookup tables required to perform fixed-base scalar multiplication over a fixed number of points. More...
#include <fixed_base.hpp>
Public Types | |
using | affine_element = grumpkin::g1::affine_element |
using | element = grumpkin::g1::element |
using | single_lookup_table = std::vector< affine_element > |
using | fixed_base_scalar_mul_tables = std::vector< single_lookup_table > |
using | all_multi_tables = std::array< fixed_base_scalar_mul_tables, NUM_FIXED_BASE_MULTI_TABLES > |
Public Member Functions | |
template<size_t num_table_bits> | |
grumpkin::g1::affine_element | generate_generator_offset (const grumpkin::g1::affine_element &input) |
For a fixed-base lookup of size num_table_bits and an input base point input , return the total contrbution in the scalar multiplication output from the offset generators in the lookup tables. | |
Static Public Member Functions | |
static constexpr affine_element | lhs_generator_point () |
static constexpr affine_element | rhs_generator_point () |
static single_lookup_table | generate_single_lookup_table (const affine_element &base_point, const affine_element &offset_generator) |
Given a base_point [P] and an offset_generator [G], compute a lookup table of MAX_TABLE_SIZE that contains the following terms: | |
template<size_t num_bits> | |
static fixed_base_scalar_mul_tables | generate_tables (const affine_element &input) |
For a given base point [P], compute the lookup tables required to traverse a num_bits sized lookup. | |
template<size_t num_table_bits> | |
static affine_element | generate_generator_offset (const affine_element &input) |
static affine_element | lhs_base_point_lo () |
static affine_element | lhs_base_point_hi () |
static affine_element | rhs_base_point_lo () |
static affine_element | rhs_base_point_hi () |
static const all_multi_tables & | fixed_base_tables () |
static const std::array< affine_element, table::NUM_FIXED_BASE_MULTI_TABLES > & | fixed_base_table_offset_generators () |
offset generators! | |
static bool | lookup_table_exists_for_point (const affine_element &input) |
Given a point, do we have a precomputed lookup table for this point? | |
static std::optional< std::array< MultiTableId, 2 > > | get_lookup_table_ids_for_point (const affine_element &input) |
Given a point, return (if it exists) the 2 MultiTableId's that correspond to the LO_SCALAR, HI_SCALAR MultiTables. | |
static std::optional< affine_element > | get_generator_offset_for_table_id (MultiTableId table_id) |
Given a table id, return the offset generator term that will be present in the final scalar mul output. | |
template<size_t multitable_index> | |
static BasicTable | generate_basic_fixed_base_table (BasicTableId id, size_t basic_table_index, size_t table_index) |
Generate a single fixed-base-scalar-mul plookup table. | |
template<size_t multitable_index, size_t num_bits> | |
static MultiTable | get_fixed_base_table (MultiTableId id) |
Generate a multi-table that describes the lookups required to cover a fixed-base-scalar-mul of num_bits | |
template<size_t multitable_index, size_t table_index> | |
static std::array< bb::fr, 2 > | get_basic_fixed_base_table_values (const std::array< uint64_t, 2 > key) |
![]() | |
template<size_t num_bits> | |
static constexpr size_t | get_num_tables_per_multi_table () noexcept |
For a scalar multiplication table that covers input scalars up to (1 << num_bits) - 1 , how many individual lookup tables of max size BITS_PER_TABLE do we need? (e.g. if BITS_PER_TABLE = 9, for num_bits = 126 it's 14. For num_bits = 128 it's 15) | |
template<size_t multitable_index> | |
static constexpr size_t | get_num_bits_of_multi_table () |
For a given multitable index, how many scalar mul bits are we traversing with our multitable? | |
Static Public Attributes | |
static constexpr uint256_t | MAX_LO_SCALAR = uint256_t(1) << BITS_PER_LO_SCALAR |
![]() | |
static constexpr size_t | BITS_PER_TABLE = 9 |
static constexpr size_t | BITS_ON_CURVE = 254 |
static constexpr size_t | BITS_PER_LO_SCALAR = 128 |
static constexpr size_t | BITS_PER_HI_SCALAR = BITS_ON_CURVE - BITS_PER_LO_SCALAR |
static constexpr size_t | MAX_TABLE_SIZE = (1UL) << BITS_PER_TABLE |
static constexpr size_t | MAX_NUM_TABLES_IN_MULTITABLE |
static constexpr size_t | NUM_POINTS = 2 |
static constexpr size_t | NUM_FIXED_BASE_MULTI_TABLES = NUM_POINTS * 2 |
static constexpr size_t | NUM_TABLES_PER_LO_MULTITABLE |
static constexpr size_t | NUM_TABLES_PER_HI_MULTITABLE |
static constexpr size_t | NUM_BASIC_TABLES_PER_BASE_POINT |
static constexpr size_t | NUM_FIXED_BASE_BASIC_TABLES = NUM_BASIC_TABLES_PER_BASE_POINT * NUM_POINTS |
Generates plookup tables required to perform fixed-base scalar multiplication over a fixed number of points.
Definition at line 22 of file fixed_base.hpp.
Definition at line 24 of file fixed_base.hpp.
using bb::plookup::fixed_base::table::all_multi_tables = std::array<fixed_base_scalar_mul_tables, NUM_FIXED_BASE_MULTI_TABLES> |
Definition at line 28 of file fixed_base.hpp.
Definition at line 25 of file fixed_base.hpp.
using bb::plookup::fixed_base::table::fixed_base_scalar_mul_tables = std::vector<single_lookup_table> |
Definition at line 27 of file fixed_base.hpp.
using bb::plookup::fixed_base::table::single_lookup_table = std::vector<affine_element> |
Definition at line 26 of file fixed_base.hpp.
|
static |
offset generators!
We add a unique "offset generator" into each lookup table to ensure that we never trigger incomplete addition formulae for short Weierstrass curves. The offset generators are linearly independent from the fixed-base points we're multiplying, ensuring that a collision is as likely as solving the discrete logarithm problem. For example, imagine a 2-bit lookup table of a point [P]. The table would normally contain { 0.[P], 1.[P], 2.[P], 3.[P]}. But, we dont want to have to handle points at infinity and we also don't want to deal with windowed-non-adjacent-form complexities. Instead, we derive offset generator [G] and make the table equal to { [G] + 0.[P], [G] + 1.[P], [G] + 2.[P], [G] + 3.[P]}. Each table uses a unique offset generator to prevent collisions. The final scalar multiplication output will have a precisely-known contribution from the offset generators, which can then be subtracted off with a single point subtraction.
NOTE: Without putting these computed lookup tables behind statics there is a timing issue when compiling for the WASM target. hypothesis: because it's 32-bit it has different static init order and this helps?
Definition at line 301 of file fixed_base.cpp.
|
static |
NOTE: Without putting these computed lookup tables behind statics there is a timing issue when compiling for the WASM target. hypothesis: because it's 32-bit it has different static init order and this helps?
Definition at line 285 of file fixed_base.cpp.
|
static |
Generate a single fixed-base-scalar-mul plookup table.
multitable_index,which | of our 4 multitables is this basic table a part of? |
id | the BasicTableId |
basic_table_index | plookup table index |
table_index | This index describes which bit-slice the basic table corresponds to. i.e. table_index = 0 maps to the least significant bit slice |
Definition at line 192 of file fixed_base.cpp.
|
static |
grumpkin::g1::affine_element bb::plookup::fixed_base::table::generate_generator_offset | ( | const grumpkin::g1::affine_element & | input | ) |
For a fixed-base lookup of size num_table_bits
and an input base point input
, return the total contrbution in the scalar multiplication output from the offset generators in the lookup tables.
num_table_bits |
input |
Definition at line 91 of file fixed_base.cpp.
|
inlinestatic |
Given a base_point [P] and an offset_generator [G], compute a lookup table of MAX_TABLE_SIZE that contains the following terms:
{ [G] + 0.[P] , [G] + 1.[P], ..., [G] + (MAX_TABLE_SIZE - 1).[P] }
base_point | |
offset_generator |
Definition at line 27 of file fixed_base.cpp.
|
static |
For a given base point [P], compute the lookup tables required to traverse a num_bits
sized lookup.
i.e. call generate_single_lookup_table
for the following base points:
{ [P], [P] * (1 << BITS_PER_TABLE), [P] * (1 << BITS_PER_TABLE * 2), ..., [P] * (1 << BITS_PER_TABLE * (NUM_TABLES - 1)) }
num_bits |
input |
Definition at line 57 of file fixed_base.cpp.
|
inlinestatic |
Definition at line 95 of file fixed_base.hpp.
|
static |
Generate a multi-table that describes the lookups required to cover a fixed-base-scalar-mul of num_bits
multitable_index,which | one of our 4 multitables are we generating? |
num_bits,this | will be either BITS_PER_LO_SCALAR or BITS_PER_HI_SCALAR |
id |
Definition at line 236 of file fixed_base.cpp.
|
static |
Given a table id, return the offset generator term that will be present in the final scalar mul output.
Return value is std::optional in case the table_id is not a fixed-base table.
table_id |
Definition at line 144 of file fixed_base.cpp.
|
static |
Given a point, return (if it exists) the 2 MultiTableId's that correspond to the LO_SCALAR, HI_SCALAR MultiTables.
input |
Definition at line 124 of file fixed_base.cpp.
|
inlinestatic |
Definition at line 52 of file fixed_base.hpp.
|
inlinestatic |
Definition at line 51 of file fixed_base.hpp.
|
inlinestaticconstexpr |
Definition at line 30 of file fixed_base.hpp.
|
static |
Given a point, do we have a precomputed lookup table for this point?
input |
Definition at line 112 of file fixed_base.cpp.
|
inlinestatic |
Definition at line 58 of file fixed_base.hpp.
|
inlinestatic |
Definition at line 57 of file fixed_base.hpp.
|
inlinestaticconstexpr |
Definition at line 34 of file fixed_base.hpp.
|
staticconstexpr |
Definition at line 45 of file fixed_base.hpp.