|
37 | 37 | #include <nil/blueprint/component.hpp> |
38 | 38 | #include <nil/blueprint/manifest.hpp> |
39 | 39 | #include <nil/blueprint/components/hashes/sha2/plonk/detail/split_functions.hpp> |
40 | | -#include <nil/blueprint/components/hashes/sha2/plonk/detail/sha_table_generators.hpp> |
41 | 40 |
|
42 | 41 | namespace nil { |
43 | 42 | namespace blueprint { |
@@ -158,185 +157,6 @@ namespace nil { |
158 | 157 | component_type(witnesses, constants, public_inputs, get_manifest()) {}; |
159 | 158 |
|
160 | 159 |
|
161 | | - using lookup_table_definition = typename nil::crypto3::zk::snark::detail::lookup_table_definition<BlueprintFieldType>; |
162 | | - |
163 | | - class sparse_values_base4_table: public lookup_table_definition{ |
164 | | - public: |
165 | | - sparse_values_base4_table(): lookup_table_definition("sha256_sparse_base4"){ |
166 | | - this->subtables["full"] = {{0,1}, 0, 16383}; |
167 | | - this->subtables["first_column"] = {{0}, 0, 16383}; |
168 | | - }; |
169 | | - virtual void generate(){ |
170 | | - this->_table.resize(2); |
171 | | - std::vector<std::size_t> value_sizes = {14}; |
172 | | - |
173 | | - // lookup table for sparse values with base = 4 |
174 | | - for (typename BlueprintFieldType::integral_type i = 0; |
175 | | - i < typename BlueprintFieldType::integral_type(16384); |
176 | | - i++ |
177 | | - ) { |
178 | | - std::vector<bool> value(14); |
179 | | - for (std::size_t j = 0; j < 14; j++) { |
180 | | - value[14 - j - 1] = crypto3::multiprecision::bit_test(i, j); |
181 | | - } |
182 | | - std::array<std::vector<typename BlueprintFieldType::integral_type>, 2> value_chunks = |
183 | | - detail::split_and_sparse<BlueprintFieldType>(value, value_sizes, base4 ); |
184 | | - this->_table[0].push_back(value_chunks[0][0]); |
185 | | - this->_table[1].push_back(value_chunks[1][0]); |
186 | | - } |
187 | | - } |
188 | | - |
189 | | - virtual std::size_t get_columns_number(){return 2;} |
190 | | - virtual std::size_t get_rows_number(){return 16384;} |
191 | | - }; |
192 | | - |
193 | | - class reverse_sparse_sigmas_base4_table : public lookup_table_definition { |
194 | | - public: |
195 | | - reverse_sparse_sigmas_base4_table(): lookup_table_definition("sha256_reverse_sparse_base4"){ |
196 | | - this->subtables["full"] = {{0,1}, 0, 65535}; |
197 | | - }; |
198 | | - |
199 | | - virtual void generate() { |
200 | | - this->_table = detail::load_sha_table<BlueprintFieldType>( |
201 | | - {"8_split_4.txt", |
202 | | - "./../libs/crypto3/libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/detail/8_split_4.txt", |
203 | | - "./../libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/detail/8_split_4.txt", |
204 | | - "./../../../../libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/detail/8_split_4.txt"}); |
205 | | - if (this->_table.size() == 0 || this->_table[0].size() == 0) { |
206 | | - std::cerr << "Failed to load table 8_split_4.txt!" |
207 | | - " Please check the paths and generate the table." |
208 | | - << std::endl; |
209 | | - BLUEPRINT_RELEASE_ASSERT(0); |
210 | | - } |
211 | | - } |
212 | | - |
213 | | - virtual std::size_t get_columns_number(){return 2;} |
214 | | - virtual std::size_t get_rows_number(){return 65536;} |
215 | | - }; |
216 | | - |
217 | | - class sparse_values_base7_table: public lookup_table_definition{ |
218 | | - public: |
219 | | - sparse_values_base7_table(): lookup_table_definition("sha256_sparse_base7"){ |
220 | | - this->subtables["full"] = {{0,1}, 0, 16383}; |
221 | | - this->subtables["first_column"] = {{0}, 0, 16383}; |
222 | | - this->subtables["second_column"] = {{1}, 0, 16383}; |
223 | | - }; |
224 | | - virtual void generate(){ |
225 | | - this->_table.resize(2); |
226 | | - std::vector<std::size_t> value_sizes = {14}; |
227 | | - for (typename BlueprintFieldType::integral_type i = 0; |
228 | | - i < typename BlueprintFieldType::integral_type(16384); |
229 | | - i++) { |
230 | | - std::vector<bool> value(14); |
231 | | - for (std::size_t j = 0; j < 14; j++) { |
232 | | - value[14 - j - 1] = crypto3::multiprecision::bit_test(i, j); |
233 | | - } |
234 | | - std::array<std::vector<typename BlueprintFieldType::integral_type>, 2> value_chunks = |
235 | | - detail::split_and_sparse<BlueprintFieldType>(value, value_sizes, base7); |
236 | | - this->_table[0].push_back(value_chunks[0][0]); |
237 | | - this->_table[1].push_back(value_chunks[1][0]); |
238 | | - } |
239 | | - } |
240 | | - |
241 | | - virtual std::size_t get_columns_number(){return 2;} |
242 | | - virtual std::size_t get_rows_number(){return 16384;} |
243 | | - }; |
244 | | - |
245 | | - class reverse_sparse_sigmas_base7_table: public lookup_table_definition{ |
246 | | - public: |
247 | | - reverse_sparse_sigmas_base7_table(): lookup_table_definition("sha256_reverse_sparse_base7"){ |
248 | | - this->subtables["full"] = {{0,1}, 0, 43903}; |
249 | | - }; |
250 | | - virtual void generate() { |
251 | | - this->_table = detail::load_sha_table<BlueprintFieldType>( |
252 | | - {"8_split_7.txt", |
253 | | - "./../libs/crypto3/libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/detail/8_split_7.txt", |
254 | | - "./../libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/detail/8_split_7.txt", |
255 | | - "./../../../../libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/detail/8_split_7.txt"}); |
256 | | - if (this->_table.size() == 0 || this->_table[0].size() == 0) { |
257 | | - std::cerr << "Failed to load table 8_split_7.txt!" |
258 | | - " Please check the paths and generate the table." |
259 | | - << std::endl; |
260 | | - BLUEPRINT_RELEASE_ASSERT(0); |
261 | | - } |
262 | | - } |
263 | | - |
264 | | - virtual std::size_t get_columns_number(){return 2;} |
265 | | - virtual std::size_t get_rows_number(){return 43904;} |
266 | | - }; |
267 | | - |
268 | | - class maj_function_table: public lookup_table_definition{ |
269 | | - public: |
270 | | - maj_function_table(): lookup_table_definition("sha256_maj"){ |
271 | | - this->subtables["full"] = {{0,1}, 0, 65534}; |
272 | | - this->subtables["first_column"] = {{0}, 0, 65534}; |
273 | | - }; |
274 | | - virtual void generate(){ |
275 | | - this->_table.resize(2); |
276 | | - std::vector<std::size_t> value_sizes = {8}; |
277 | | - for (typename BlueprintFieldType::integral_type i = 0; |
278 | | - i < typename BlueprintFieldType::integral_type(65535); |
279 | | - i++ |
280 | | - ) { |
281 | | - std::array<std::vector<typename BlueprintFieldType::integral_type>, 2> |
282 | | - value = detail::reversed_sparse_and_split_maj<BlueprintFieldType>(i, value_sizes, base4); |
283 | | - this->_table[0].push_back(value[0][0]); |
284 | | - this->_table[1].push_back(value[1][0]); |
285 | | - } |
286 | | - } |
287 | | - |
288 | | - virtual std::size_t get_columns_number(){return 2;} |
289 | | - virtual std::size_t get_rows_number(){return 65535;} |
290 | | - }; |
291 | | - |
292 | | - class ch_function_table: public lookup_table_definition{ |
293 | | - public: |
294 | | - ch_function_table(): lookup_table_definition("sha256_ch"){ |
295 | | - this->subtables["full"] = {{0,1}, 0, 5765040}; |
296 | | - this->subtables["first_column"] = {{0}, 0, 5765040}; |
297 | | - }; |
298 | | - virtual void generate(){ |
299 | | - this->_table.resize(2); |
300 | | - std::vector<std::size_t> value_sizes = {8}; |
301 | | - for (typename BlueprintFieldType::integral_type i = 0; |
302 | | - i < typename BlueprintFieldType::integral_type(5765041); |
303 | | - i++ |
304 | | - ) { |
305 | | - std::array<std::vector<typename BlueprintFieldType::integral_type>, 2> |
306 | | - value = detail::reversed_sparse_and_split_ch<BlueprintFieldType>(i, value_sizes, base7); |
307 | | - this->_table[0].push_back(value[0][0]); |
308 | | - this->_table[1].push_back(value[1][0]); |
309 | | - } |
310 | | - } |
311 | | - |
312 | | - virtual std::size_t get_columns_number(){return 2;} |
313 | | - virtual std::size_t get_rows_number(){return 5765041;} |
314 | | - }; |
315 | | - |
316 | | - std::vector<std::shared_ptr<lookup_table_definition>> component_custom_lookup_tables(){ |
317 | | - std::vector<std::shared_ptr<lookup_table_definition>> result = {}; |
318 | | - |
319 | | - auto sparse_values_base4 = std::shared_ptr<lookup_table_definition>(new sparse_values_base4_table()); |
320 | | - result.push_back(sparse_values_base4); |
321 | | - |
322 | | - auto sparse_values_base7 = std::shared_ptr<lookup_table_definition>(new sparse_values_base7_table()); |
323 | | - result.push_back(sparse_values_base7); |
324 | | - |
325 | | - auto maj = std::shared_ptr<lookup_table_definition>(new maj_function_table()); |
326 | | - result.push_back(maj); |
327 | | - |
328 | | - auto reverse_sparse_values_base4 = std::shared_ptr<lookup_table_definition>(new reverse_sparse_sigmas_base4_table()); |
329 | | - result.push_back(reverse_sparse_values_base4); |
330 | | - |
331 | | - auto reverse_sparse_values_base7 = std::shared_ptr<lookup_table_definition>(new reverse_sparse_sigmas_base7_table()); |
332 | | - result.push_back(reverse_sparse_values_base7); |
333 | | - |
334 | | - auto ch = std::shared_ptr<lookup_table_definition>(new ch_function_table()); |
335 | | - result.push_back(ch); |
336 | | - |
337 | | - return result; |
338 | | - } |
339 | | - |
340 | 160 | std::map<std::string, std::size_t> component_lookup_tables(){ |
341 | 161 | std::map<std::string, std::size_t> lookup_tables; |
342 | 162 | lookup_tables["sha256_sparse_base4/full"] = 0; // REQUIRED_TABLE |
|
0 commit comments