Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::plookup::sparse_tables Namespace Reference

Functions

template<uint64_t base, uint64_t num_rotated_bits>
std::array< bb::fr, 2 > get_sparse_table_with_rotation_values (const std::array< uint64_t, 2 > key)
 Computes the C2 and C3 column values for a sparse lookup table with optional rotation.
 
template<uint64_t base, uint64_t bits_per_slice, uint64_t num_rotated_bits>
BasicTable generate_sparse_table_with_rotation (BasicTableId id, const size_t table_index)
 Generates a BasicTable for converting values to sparse form with optional rotation.
 
template<size_t base, const uint64_t * base_table>
std::array< bb::fr, 2 > get_sparse_normalization_values (const std::array< uint64_t, 2 > key)
 Computes the normalized output for a sparse value based on a provided normalization table.
 
template<size_t base, uint64_t num_bits, const uint64_t * base_table>
BasicTable generate_sparse_normalization_table (BasicTableId id, const size_t table_index)
 Generates a BasicTable for normalizing sparse form values back to normal form.
 

Function Documentation

◆ generate_sparse_normalization_table()

template<size_t base, uint64_t num_bits, const uint64_t * base_table>
BasicTable bb::plookup::sparse_tables::generate_sparse_normalization_table ( BasicTableId  id,
const size_t  table_index 
)
inline

Generates a BasicTable for normalizing sparse form values back to normal form.

This table converts sparse arithmetic results into actual bit values. Each sparse digit encodes a sum of bits; the normalization table extracts the XOR result (and optionally other Boolean function results like Ch or Maj).

Table structure (base^num_bits many entries):

  • C1 (input): All possible sparse values with num_bits digits
  • C2 (output): Normalized result where each sparse digit is mapped through base_table
  • C3: Unused (always 0)

The num_bits parameter controls how many bits are normalized per lookup. Larger num_bits = fewer lookups needed, but larger table.

Template Parameters
baseThe sparse form base
num_bitsNumber of sparse digits (= original bits) processed per lookup
base_tableThe per-digit normalization table (e.g., choose_normalization_table)

Definition at line 144 of file sparse.hpp.

◆ generate_sparse_table_with_rotation()

template<uint64_t base, uint64_t bits_per_slice, uint64_t num_rotated_bits>
BasicTable bb::plookup::sparse_tables::generate_sparse_table_with_rotation ( BasicTableId  id,
const size_t  table_index 
)
inline

Generates a BasicTable for converting values to sparse form with optional rotation.

Creates a lookup table with three columns:

  • C1: Input value in normal form (the lookup key)
  • C2: Input converted to sparse base form
  • C3: Input rotated by num_rotated_bits, then converted to sparse form (equals C2 if num_rotated_bits == 0)

Step sizes are configured for accumulator building:

  • C1 step: 2^11 (SHA-256 decomposes 32-bit words into three limbs of sizes {11, 11, 10} bits)
  • C2/C3 step: base^bits_per_slice (for sparse form accumulation)

Also sets get_values_from_key to enable on-the-fly value computation during lookups.

Template Parameters
baseThe sparse form base
bits_per_sliceNumber of bits in each table entry (determines table size = 2^bits_per_slice)
num_rotated_bitsThe number of bits to rotate for C3 values (0 = no rotation)

Definition at line 62 of file sparse.hpp.

◆ get_sparse_normalization_values()

template<size_t base, const uint64_t * base_table>
std::array< bb::fr, 2 > bb::plookup::sparse_tables::get_sparse_normalization_values ( const std::array< uint64_t, 2 >  key)
inline

Computes the normalized output for a sparse value based on a provided normalization table.

Template Parameters
baseThe sparse form base
base_tableThe normalization lookup table (maps sparse digit → normalized bit(s))
Parameters
keyThe lookup key; key[0] is the sparse input value, key[1] is unused
Returns
{normalized_value, 0} where normalized_value has one output bit per input sparse digit

Definition at line 107 of file sparse.hpp.

◆ get_sparse_table_with_rotation_values()

template<uint64_t base, uint64_t num_rotated_bits>
std::array< bb::fr, 2 > bb::plookup::sparse_tables::get_sparse_table_with_rotation_values ( const std::array< uint64_t, 2 >  key)
inline

Computes the C2 and C3 column values for a sparse lookup table with optional rotation.

Template Parameters
baseThe sparse form base
num_rotated_bitsThe number of bits to rotate the input by for the C3 value (0 = no rotation)
Parameters
keyThe lookup key; key[0] is the input value (a limb), key[1] is unused
Returns
{C2, C3} where:
  • C2 = sparse(input): the input converted to sparse base form
  • C3 = sparse(rotate32(input, num_rotated_bits)): the rotated input in sparse form (equals C2 if num_rotated_bits == 0)

Definition at line 30 of file sparse.hpp.