Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
fixtures.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
13#include <cstdint>
14#include <ostream>
15#include <sstream>
16#include <string>
17#include <vector>
18
20
21const uint32_t NUM_VALUES = 1024;
24
25static auto create_values = [](uint32_t num_values = NUM_VALUES) {
26 std::vector<fr> values(num_values);
27 for (uint32_t i = 0; i < num_values; ++i) {
28 values[i] = fr(random_engine.get_random_uint256());
29 }
30 return values;
31};
32
33static std::vector<fr> VALUES = create_values();
34
35inline std::string random_string()
36{
37 std::stringstream ss;
38 ss << random_engine.get_random_uint32();
39 return ss.str();
40}
41
42inline std::string random_temp_directory()
43{
44 std::stringstream ss;
45 ss << "/tmp/lmdb/" << random_string();
46 return ss.str();
47}
48
49inline void print_tree(const uint32_t depth, std::vector<fr> hashes, std::string const& msg)
50{
51 info("\n", msg);
52 uint32_t offset = 0;
53 for (uint32_t i = 0; i < depth; i++) {
54 info("i = ", i);
55 uint32_t layer_size = (1U << (depth - i));
56 for (uint32_t j = 0; j < layer_size; j++) {
57 info("j = ", j, ": ", hashes[offset + j]);
58 }
59 offset += layer_size;
60 }
61}
62
64
65inline ThreadPoolPtr make_thread_pool(uint64_t numThreads)
66{
67 return std::make_shared<ThreadPool>(numThreads);
68}
69
70void inline print_store_data(LMDBTreeStore::SharedPtr db, std::ostream& os)
71{
72 LMDBTreeStore::ReadTransaction::Ptr tx = db->create_read_transaction();
73 TreeDBStats stats;
74 db->get_stats(stats, *tx);
75
76 os << stats;
77}
78} // namespace bb::crypto::merkle_tree
std::shared_ptr< LMDBTreeStore > SharedPtr
std::unique_ptr< LMDBReadTransaction > Ptr
void info(Args... args)
Definition log.hpp:70
ssize_t offset
Definition engine.cpp:36
ThreadPoolPtr make_thread_pool(uint64_t numThreads)
Definition fixtures.hpp:65
const uint32_t NUM_VALUES
Definition fixtures.hpp:21
std::string random_temp_directory()
Definition fixtures.hpp:42
std::string random_string()
Definition fixtures.hpp:35
void print_tree(const uint32_t depth, std::vector< fr > hashes, std::string const &msg)
Definition fixtures.hpp:49
std::shared_ptr< ThreadPool > ThreadPoolPtr
Definition fixtures.hpp:63
void print_store_data(LMDBTreeStore::SharedPtr db, std::ostream &os)
Definition fixtures.hpp:70
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
RNG & get_randomness()
Definition engine.cpp:203
field< Bn254FrParams > fr
Definition fr.hpp:174
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13