32 element accumulator = offset_generator;
34 table_raw[i] = accumulator;
35 accumulator += base_point;
39 for (
size_t i = 0; i < table_raw.size(); ++i) {
59 constexpr size_t NUM_TABLES = get_num_tables_per_multi_table<num_bits>();
62 result.reserve(NUM_TABLES);
64 std::vector<uint8_t> input_buf;
65 write(input_buf, input);
69 for (
size_t i = 0; i < NUM_TABLES; ++i) {
72 accumulator = accumulator.
dbl();
90template <
size_t num_table_bits>
93 constexpr size_t NUM_TABLES = get_num_tables_per_multi_table<num_table_bits>();
95 std::vector<uint8_t> input_buf;
96 write(input_buf, input);
99 for (
const auto& gen : offset_generators) {
174 bb::constexpr_for<0, table::NUM_FIXED_BASE_MULTI_TABLES, 1>([&]<
size_t i>() {
175 bb::constexpr_for<0, table::MAX_NUM_TABLES_IN_MULTITABLE, 1>(
176 [&]<
size_t j>() {
table[i][j] = &table::get_basic_fixed_base_table_values<i, j>; });
191template <
size_t multitable_index>
197 const size_t multitable_bits = get_num_bits_of_multi_table<multitable_index>();
198 const size_t bits_covered_by_previous_tables_in_multitable =
BITS_PER_TABLE * table_index;
199 const bool is_small_table = (multitable_bits - bits_covered_by_previous_tables_in_multitable) <
BITS_PER_TABLE;
200 const size_t table_bits =
201 is_small_table ? multitable_bits - bits_covered_by_previous_tables_in_multitable :
BITS_PER_TABLE;
202 const auto table_size =
static_cast<size_t>(1ULL << table_bits);
205 table.table_index = basic_table_index;
206 table.use_twin_keys =
false;
210 for (
size_t i = 0; i < table_size; ++i) {
211 table.column_1.emplace_back(i);
212 table.column_2.emplace_back(basic_table[i].x);
213 table.column_3.emplace_back(basic_table[i].y);
215 table.get_values_from_key =
nullptr;
218 table.get_values_from_key = get_values_from_key_table[multitable_index][table_index];
221 table.column_1_step_size = table_size;
222 table.column_2_step_size = 0;
223 table.column_3_step_size = 0;
239 constexpr size_t NUM_TABLES = get_num_tables_per_multi_table<num_bits>();
250 table.get_table_values.resize(NUM_TABLES);
251 table.basic_table_ids.resize(NUM_TABLES);
252 for (
size_t i = 0; i < NUM_TABLES; ++i) {
254 table.get_table_values[i] = get_values_from_key_table[multitable_index][i];
256 size_t idx = i +
static_cast<size_t>(basic_table_ids[multitable_index]);
#define BB_ASSERT_LT(left, right,...)
#define ASSERT(expression,...)
element class. Implements ecc group arithmetic using Jacobian coordinates See https://hyperelliptic....
constexpr element dbl() const noexcept
static void batch_normalize(element *elements, size_t num_elements) noexcept
static constexpr element point_at_infinity
static std::vector< affine_element > derive_generators(const std::vector< uint8_t > &domain_separator_bytes, const size_t num_generators, const size_t starting_index=0)
Derives generator points via hash-to-curve.
Generates plookup tables required to perform fixed-base scalar multiplication over a fixed number of ...
std::vector< affine_element > single_lookup_table
static affine_element generate_generator_offset(const affine_element &input)
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,...
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_bi...
std::array< fixed_base_scalar_mul_tables, NUM_FIXED_BASE_MULTI_TABLES > all_multi_tables
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 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 con...
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.
static const all_multi_tables & fixed_base_tables()
static affine_element lhs_base_point_lo()
static affine_element rhs_base_point_lo()
static const std::array< affine_element, table::NUM_FIXED_BASE_MULTI_TABLES > & fixed_base_table_offset_generators()
offset generators!
static affine_element lhs_base_point_hi()
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 outpu...
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.
static constexpr affine_element lhs_generator_point()
std::vector< single_lookup_table > fixed_base_scalar_mul_tables
static affine_element rhs_base_point_hi()
std::array< bb::fr, 2 >(*)(const std::array< uint64_t, 2 >) function_ptr
std::array< std::array< function_ptr, table::MAX_NUM_TABLES_IN_MULTITABLE >, table::NUM_FIXED_BASE_MULTI_TABLES > function_ptr_table
constexpr function_ptr_table make_function_pointer_table()
create a compile-time static 2D array of all our required get_basic_fixed_base_table_values function ...
void write(B &buf, field2< base_field, Params > const &value)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
A basic table from which we can perform lookups (for example, an xor table)
static constexpr size_t NUM_FIXED_BASE_MULTI_TABLES
static constexpr size_t MAX_TABLE_SIZE
static constexpr size_t BITS_PER_TABLE
static constexpr size_t BITS_PER_HI_SCALAR
static constexpr size_t MAX_NUM_TABLES_IN_MULTITABLE
static constexpr size_t BITS_PER_LO_SCALAR
Container for managing multiple BasicTables plus the data needed to combine basic table outputs (e....