Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
fixed_base_params.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
9#include <array>
11#include <cstddef>
12#include <cstdint>
13
14namespace bb::plookup {
20 static constexpr size_t BITS_PER_TABLE = 9;
21 static constexpr size_t BITS_ON_CURVE = 254;
22
23 // We split 1 254-bit scalar mul into two scalar muls of size BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR.
24 // This enables us to efficiently decompose our input scalar multiplier into two chunks of a known size.
25 // (i.e. we get free BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR range checks as part of the lookup table subroutine)
26 // This in turn allows us to perform a primality test more efficiently.
27 // i.e. check that input scalar < prime modulus when evaluated over the integers
28 // (the primality check requires us to split the input into high / low bit chunks so getting this for free as part
29 // of the lookup algorithm is nice!)
30 static constexpr size_t BITS_PER_LO_SCALAR = 128;
32 // max table size because the last lookup table might be smaller (BITS_PER_TABLE does not neatly divide
33 // BITS_PER_LO_SCALAR)
34 static constexpr size_t MAX_TABLE_SIZE = (1UL) << BITS_PER_TABLE;
35 // how many BITS_PER_TABLE lookup tables do we need to traverse BITS_PER_LO_SCALAR-amount of bits?
36 // (we implicitly assume BITS_PER_LO_SCALAR > BITS_PER_HI_SCALAR)
37 static constexpr size_t MAX_NUM_TABLES_IN_MULTITABLE =
39 static constexpr size_t NUM_POINTS = 2;
40 // how many multitables are we creating? It's 4 because we want enough lookup tables to cover two field elements,
41 // two field elements = 2 scalar muls = 4 scalar mul hi/lo slices = 4 multitables
42 static constexpr size_t NUM_FIXED_BASE_MULTI_TABLES = NUM_POINTS * 2;
43 static constexpr size_t NUM_TABLES_PER_LO_MULTITABLE =
45 static constexpr size_t NUM_TABLES_PER_HI_MULTITABLE =
47 // how many lookups are required to perform a scalar mul of a field element with a base point?
48 static constexpr size_t NUM_BASIC_TABLES_PER_BASE_POINT =
50 // how many basic lookup tables are we creating in total to support fixed-base-scalar-muls over two precomputed base
51 // points.
53
61 template <size_t num_bits> inline static constexpr size_t get_num_tables_per_multi_table() noexcept
62 {
63 return (num_bits / BITS_PER_TABLE) + ((num_bits % BITS_PER_TABLE == 0) ? 0 : 1);
64 }
65
72 template <size_t multitable_index> static constexpr size_t get_num_bits_of_multi_table()
73 {
74 static_assert(multitable_index < NUM_FIXED_BASE_MULTI_TABLES);
75 constexpr std::array<size_t, 4> MULTI_TABLE_BIT_LENGTHS{
77 };
78 return MULTI_TABLE_BIT_LENGTHS[multitable_index];
79 }
80};
81} // namespace bb::plookup
Parameters definitions for our fixed-base-scalar-multiplication lookup tables.
static constexpr size_t NUM_POINTS
static constexpr size_t NUM_FIXED_BASE_MULTI_TABLES
static constexpr size_t MAX_TABLE_SIZE
static constexpr size_t NUM_BASIC_TABLES_PER_BASE_POINT
static constexpr size_t BITS_PER_TABLE
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 constexpr size_t NUM_FIXED_BASE_BASIC_TABLES
static constexpr size_t NUM_TABLES_PER_HI_MULTITABLE
static constexpr size_t BITS_PER_HI_SCALAR
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,...
static constexpr size_t MAX_NUM_TABLES_IN_MULTITABLE
static constexpr size_t BITS_ON_CURVE
static constexpr size_t BITS_PER_LO_SCALAR
static constexpr size_t NUM_TABLES_PER_LO_MULTITABLE