Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
secp256r1_fixed_base.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "./types.hpp"
6#include <array>
7#include <mutex>
8#include <utility>
9
11
56// Inherits all layout numerics (NUM_WINDOWS*, WINDOW_BITS_*, TABLE_SIZE_*, NUM_AXES, LO_TAIL_WINDOW,
57// HI_TAIL_WINDOW, and the `window_bits` / `table_size` helpers) from Secp256r1FixedBaseParams. They live
58// in `secp256r1_fixed_base_params.hpp` so the enum in `types.hpp` can reach them without a cycle.
60 public:
64
65 enum AxisIndex : size_t {
70 };
71
75 static constexpr BasicTableId axis_start_id(AxisIndex axis)
76 {
77 switch (axis) {
78 case AXIS_XLO:
80 case AXIS_XHI:
82 case AXIS_YLO:
84 case AXIS_YHI:
86 }
87 return SECP256R1_FIXED_BASE_XLO_0; // unreachable
88 }
89
94 static void init_tables();
95
101
108 template <AxisIndex axis, size_t window_idx> static std::array<bb::fr, 2> get_values(std::array<uint64_t, 2> key);
109
115 template <AxisIndex axis, size_t window_idx>
116 static BasicTable generate_basic_table(BasicTableId id, size_t table_index);
117
122 template <AxisIndex axis>
123 static BasicTable generate_basic_table_runtime(BasicTableId id, size_t window_idx, size_t table_index);
124
130 static MultiTable get_multitable(MultiTableId id, AxisIndex axis, bool is_lo);
131
136 static const AffineElement& get_entry(size_t window_idx, size_t k)
137 {
138 init_tables();
139 BB_ASSERT_LT(window_idx, NUM_WINDOWS);
140 BB_ASSERT_LT(k, table_size(window_idx));
141 return native_table[window_idx][k];
142 }
143
149
150 private:
151 // Precomputed entries: native_table[w][k] = k · 2^(bit_offset(w)) · G + 2^w · H. The array is sized
152 // to the big-window table size (128); tail windows only populate the first table_size(w) entries
153 // (8 for the lo tail, 2 for the hi tail), and the trailing slots are unused.
157};
158
159} // namespace bb::plookup::secp256r1_fixed_base
#define BB_ASSERT_LT(left, right,...)
Definition assert.hpp:143
element class. Implements ecc group arithmetic using Jacobian coordinates See https://hyperelliptic....
Definition element.hpp:35
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:38
group_elements::affine_element< Fq, Fr, Params > affine_element
Definition group.hpp:44
group_elements::element< Fq, Fr, Params > element
Definition group.hpp:43
Per-window plookup tables for the secp256r1 fixed-base scalar multiplication.
static std::array< bb::fr, 2 > get_values(std::array< uint64_t, 2 > key)
Native lookup callback used by BasicTable::get_values_from_key. axis_window_packed encodes the window...
static std::array< bb::fr, 2 > extract_axis(const AffineElement &point, AxisIndex axis)
Split an affine point into the (limb_a, limb_b) pair for the requested axis. Used by the BasicTable g...
static MultiTable get_multitable(MultiTableId id, AxisIndex axis, bool is_lo)
Construct one of the 10 MultiTables described in the file-header docstring. is_lo = true chains windo...
static void init_tables()
Precompute the 32 × 256 native points (idempotent, thread-safe). The (limb_a, limb_b) pairs for each ...
static AffineElement total_offset()
Sum of all per-window offsets (2^0 + 2^1 + ... + 2^31) · H. Subtracted from the chain-add result of t...
static BasicTable generate_basic_table_runtime(BasicTableId id, size_t window_idx, size_t table_index)
Runtime dispatch helper used by plookup_tables.cpp::create_basic_table. Selects table contents using ...
static const AffineElement & get_entry(size_t window_idx, size_t k)
Access a precomputed entry. The biggroup caller uses this to compute proving-time hint values (val_a,...
static constexpr BasicTableId axis_start_id(AxisIndex axis)
Maps a per-axis BasicTableId range start to its AxisIndex; used by the create_basic_table dispatch.
static BasicTable generate_basic_table(BasicTableId id, size_t table_index)
Construct one BasicTable instance for (axis, window_idx). id is the BasicTableId assigned by the call...
static std::array< std::array< AffineElement, TABLE_SIZE_BIG >, NUM_WINDOWS > native_table
@ SECP256R1_FIXED_BASE_YLO_0
Definition types.hpp:95
@ SECP256R1_FIXED_BASE_XLO_0
Definition types.hpp:93
@ SECP256R1_FIXED_BASE_XHI_0
Definition types.hpp:94
@ SECP256R1_FIXED_BASE_YHI_0
Definition types.hpp:96
group< fq, fr, G1Params > g1
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
A basic table from which we can perform lookups (for example, an xor table)
Definition types.hpp:305
Container for managing multiple BasicTables plus the data needed to combine basic table outputs (e....
Definition types.hpp:167
Layout parameters for the secp256r1 fixed-base plookup decomposition.