barretenberg
Loading...
Searching...
No Matches
keccak_input.hpp
1#pragma once
2
3#include "../types.hpp"
4#include "barretenberg/common/constexpr_utils.hpp"
5#include "barretenberg/numeric/bitop/pow.hpp"
6#include "barretenberg/numeric/bitop/sparse_form.hpp"
7
8namespace plookup {
9namespace keccak_tables {
10
27
28 public:
29 static constexpr uint64_t BASE = 11;
30 static constexpr size_t TABLE_BITS = 8;
31
40 static std::array<barretenberg::fr, 2> get_keccak_input_values(const std::array<uint64_t, 2> key)
41 {
42 const uint256_t t0 = numeric::map_into_sparse_form<BASE>(key[0]);
43
44 constexpr size_t msb_shift = (64 % TABLE_BITS == 0) ? TABLE_BITS - 1 : (64 % TABLE_BITS) - 1;
45 const uint256_t t1 = key[0] >> msb_shift;
46 return { barretenberg::fr(t0), barretenberg::fr(t1) };
47 }
48
56 static BasicTable generate_keccak_input_table(BasicTableId id, const size_t table_index)
57 {
58 BasicTable table;
59 table.id = id;
60 table.table_index = table_index;
61 table.size = (1U << TABLE_BITS);
62 table.use_twin_keys = false;
63 constexpr size_t msb_shift = (64 % TABLE_BITS == 0) ? TABLE_BITS - 1 : (64 % TABLE_BITS) - 1;
64
65 for (uint64_t i = 0; i < table.size; ++i) {
66 const uint64_t source = i;
67 const auto target = numeric::map_into_sparse_form<BASE>(source);
68 table.column_1.emplace_back(barretenberg::fr(source));
69 table.column_2.emplace_back(barretenberg::fr(target));
70 table.column_3.emplace_back(barretenberg::fr(source >> msb_shift));
71 }
72
73 table.get_values_from_key = &get_keccak_input_values;
74
75 uint256_t sparse_step_size = 1;
76 for (size_t i = 0; i < TABLE_BITS; ++i) {
77 sparse_step_size *= BASE;
78 }
79 table.column_1_step_size = barretenberg::fr((1 << TABLE_BITS));
80 table.column_2_step_size = barretenberg::fr(sparse_step_size);
81 table.column_3_step_size = barretenberg::fr(sparse_step_size);
82
83 return table;
84 }
85
127 static MultiTable get_keccak_input_table(const MultiTableId id = KECCAK_FORMAT_INPUT)
128 {
129 const size_t num_entries = 8;
130
131 MultiTable table(1 << 8, uint256_t(11).pow(8), 0, num_entries);
132
133 table.id = id;
134 for (size_t i = 0; i < num_entries; ++i) {
135 table.slice_sizes.emplace_back(1 << 8);
136 table.lookup_ids.emplace_back(KECCAK_INPUT);
137 table.get_table_values.emplace_back(&get_keccak_input_values);
138 }
139 return table;
140 }
141};
142
143} // namespace keccak_tables
144} // namespace plookup
Definition: uint256.hpp:25
Generates plookup tables used convert 64-bit integers into a sparse representation used for Keccak ha...
Definition: keccak_input.hpp:26
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...
Definition: keccak_input.hpp:56
static std::array< barretenberg::fr, 2 > get_keccak_input_values(const std::array< uint64_t, 2 > key)
Given a table input value, return the table output value.
Definition: keccak_input.hpp:40
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.
Definition: keccak_input.hpp:127
The structure contains the most basic table serving one function (for, example an xor table)
Definition: types.hpp:263
Definition: types.hpp:124