barretenberg
Loading...
Searching...
No Matches
fixed_base_params.hpp
1#pragma once
2
3#include "barretenberg/plonk/proof_system/constants.hpp"
4#include <array>
5#include <barretenberg/common/assert.hpp>
6#include <cstddef>
7#include <cstdint>
8
9namespace plookup {
15 static constexpr size_t BITS_PER_TABLE = 9;
16 static constexpr size_t BITS_ON_CURVE = 254;
17
18 // We split 1 254-bit scalar mul into two scalar muls of size BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR.
19 // This enables us to efficiently decompose our input scalar multiplier into two chunks of a known size.
20 // (i.e. we get free BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR range checks as part of the lookup table subroutine)
21 // This in turn allows us to perform a primality test more efficiently.
22 // i.e. check that input scalar < prime modulus when evaluated over the integers
23 // (the primality check requires us to split the input into high / low bit chunks so getting this for free as part
24 // of the lookup algorithm is nice!)
25 static constexpr size_t BITS_PER_LO_SCALAR = 128;
26 static constexpr size_t BITS_PER_HI_SCALAR = BITS_ON_CURVE - BITS_PER_LO_SCALAR;
27 // max table size because the last lookup table might be smaller (BITS_PER_TABLE does not neatly divide
28 // BITS_PER_LO_SCALAR)
29 static constexpr size_t MAX_TABLE_SIZE = (1UL) << BITS_PER_TABLE;
30 // how many BITS_PER_TABLE lookup tables do we need to traverse BITS_PER_LO_SCALAR-amount of bits?
31 // (we implicitly assume BITS_PER_LO_SCALAR > BITS_PER_HI_SCALAR)
32 static constexpr size_t MAX_NUM_TABLES_IN_MULTITABLE =
33 (BITS_PER_LO_SCALAR / BITS_PER_TABLE) + (BITS_PER_LO_SCALAR % BITS_PER_TABLE == 0 ? 0 : 1);
34 static constexpr size_t NUM_POINTS = 2;
35 // how many multitables are we creating? It's 4 because we want enough lookup tables to cover two field elements,
36 // two field elements = 2 scalar muls = 4 scalar mul hi/lo slices = 4 multitables
37 static constexpr size_t NUM_FIXED_BASE_MULTI_TABLES = NUM_POINTS * 2;
38 static constexpr size_t NUM_TABLES_PER_LO_MULTITABLE =
39 (BITS_PER_LO_SCALAR / BITS_PER_TABLE) + ((BITS_PER_LO_SCALAR % BITS_PER_TABLE == 0) ? 0 : 1);
40 static constexpr size_t NUM_TABLES_PER_HI_MULTITABLE =
41 (BITS_PER_HI_SCALAR / BITS_PER_TABLE) + ((BITS_PER_HI_SCALAR % BITS_PER_TABLE == 0) ? 0 : 1);
42 // how many lookups are required to perform a scalar mul of a field element with a base point?
43 static constexpr size_t NUM_BASIC_TABLES_PER_BASE_POINT =
44 (NUM_TABLES_PER_LO_MULTITABLE + NUM_TABLES_PER_HI_MULTITABLE);
45 // how many basic lookup tables are we creating in total to support fixed-base-scalar-muls over two precomputed base
46 // points.
47 static constexpr size_t NUM_FIXED_BASE_BASIC_TABLES = NUM_BASIC_TABLES_PER_BASE_POINT * NUM_POINTS;
48
56 template <size_t num_bits> inline static constexpr size_t get_num_tables_per_multi_table() noexcept
57 {
58 return (num_bits / BITS_PER_TABLE) + ((num_bits % BITS_PER_TABLE == 0) ? 0 : 1);
59 }
60
67 static constexpr size_t get_num_bits_of_multi_table(const size_t multitable_index)
68 {
69 ASSERT(multitable_index < NUM_FIXED_BASE_MULTI_TABLES);
70 constexpr std::array<size_t, 4> MULTI_TABLE_BIT_LENGTHS{
71 BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR, BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR
72 };
73 return MULTI_TABLE_BIT_LENGTHS[multitable_index];
74 }
75};
76} // namespace plookup
Parameters definitions for our fixed-base-scalar-multiplication lookup tables.
Definition: fixed_base_params.hpp:14
static constexpr size_t get_num_bits_of_multi_table(const size_t multitable_index)
For a given multitable index, how many scalar mul bits are we traversing with our multitable?
Definition: fixed_base_params.hpp:67
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,...
Definition: fixed_base_params.hpp:56