Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
keccak_input.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 "../types.hpp"
13
15
32
33 public:
34 static constexpr uint64_t BASE = 11;
35 static constexpr size_t TABLE_BITS = 8;
36
46 {
47 const uint256_t t0 = numeric::map_into_sparse_form<BASE>(key[0]);
48
49 constexpr size_t msb_shift = (64 % TABLE_BITS == 0) ? TABLE_BITS - 1 : (64 % TABLE_BITS) - 1;
50 const uint256_t t1 = key[0] >> msb_shift;
51 return { bb::fr(t0), bb::fr(t1) };
52 }
53
61 static BasicTable generate_keccak_input_table(BasicTableId id, const size_t table_index)
62 {
63 BasicTable table;
64 table.id = id;
65 table.table_index = table_index;
66 auto table_size = (1U << TABLE_BITS);
67 table.use_twin_keys = false;
68 constexpr size_t msb_shift = (64 % TABLE_BITS == 0) ? TABLE_BITS - 1 : (64 % TABLE_BITS) - 1;
69
70 for (uint64_t i = 0; i < table_size; ++i) {
71 const uint64_t source = i;
72 const auto target = numeric::map_into_sparse_form<BASE>(source);
73 table.column_1.emplace_back(bb::fr(source));
74 table.column_2.emplace_back(bb::fr(target));
75 table.column_3.emplace_back(bb::fr(source >> msb_shift));
76 }
77
79
80 uint256_t sparse_step_size = 1;
81 for (size_t i = 0; i < TABLE_BITS; ++i) {
82 sparse_step_size *= BASE;
83 }
84 table.column_1_step_size = bb::fr((1 << TABLE_BITS));
85 table.column_2_step_size = bb::fr(sparse_step_size);
86 table.column_3_step_size = bb::fr(sparse_step_size);
87
88 return table;
89 }
90
133 {
134 const size_t num_entries = 8;
135
136 MultiTable table(1 << 8, uint256_t(11).pow(8), 0, num_entries);
137
138 table.id = id;
139 for (size_t i = 0; i < num_entries; ++i) {
140 table.slice_sizes.emplace_back(1 << 8);
141 table.basic_table_ids.emplace_back(KECCAK_INPUT);
142 table.get_table_values.emplace_back(&get_keccak_input_values);
143 }
144 return table;
145 }
146};
147
148} // namespace bb::plookup::keccak_tables
Generates plookup tables used convert 64-bit integers into a sparse representation used for Keccak ha...
static std::array< bb::fr, 2 > get_keccak_input_values(const std::array< uint64_t, 2 > key)
Given a table input value, return the table output value.
static MultiTable get_keccak_input_table(const MultiTableId id=KECCAK_FORMAT_INPUT)
Create the KeccakInput MultiTable used by plookup to generate a sequence of lookups.
static BasicTable generate_keccak_input_table(BasicTableId id, const size_t table_index)
Generate plookup table that maps a TABLE_BITS-slice of a base-2 integer into a base-11 representation...
@ KECCAK_INPUT
Definition types.hpp:74
@ KECCAK_FORMAT_INPUT
Definition types.hpp:135
field< Bn254FrParams > fr
Definition fr.hpp:174
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:348
std::vector< bb::fr > column_3
Definition types.hpp:383
std::vector< bb::fr > column_2
Definition types.hpp:382
std::array< bb::fr, 2 >(* get_values_from_key)(const std::array< uint64_t, 2 >)
Definition types.hpp:391
std::vector< bb::fr > column_1
Definition types.hpp:381
Container for managing multiple BasicTables plus the data needed to combine basic table outputs (e....
Definition types.hpp:154
std::vector< BasicTableId > basic_table_ids
Definition types.hpp:160
std::vector< uint64_t > slice_sizes
Definition types.hpp:161
std::vector< table_out(*)(table_in)> get_table_values
Definition types.hpp:168