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
9#include <cstdint>
10#include <ostream>
11#include <sstream>
12#include <string>
13#include <vector>
14
19
21
22const uint32_t NUM_VALUES = 1024;
25
26static auto create_values = [](uint32_t num_values = NUM_VALUES) {
27 std::vector<fr> values(num_values);
28 for (uint32_t i = 0; i < num_values; ++i) {
29 values[i] = fr(random_engine.get_random_uint256());
30 }
31 return values;
32};
33
34const fr& get_value(size_t index);
35
36inline std::string random_string()
37{
38 std::stringstream ss;
39 ss << random_engine.get_random_uint32();
40 return ss.str();
41}
42
43inline std::string random_temp_directory()
44{
45 std::stringstream ss;
46 ss << "/tmp/lmdb/" << random_string();
47 return ss.str();
48}
49
50inline void print_tree(const uint32_t depth, std::vector<fr> hashes, std::string const& msg)
51{
52 info("\n", msg);
53 uint32_t offset = 0;
54 for (uint32_t i = 0; i < depth; i++) {
55 info("i = ", i);
56 uint32_t layer_size = (1U << (depth - i));
57 for (uint32_t j = 0; j < layer_size; j++) {
58 info("j = ", j, ": ", hashes[offset + j]);
59 }
60 offset += layer_size;
61 }
62}
63
65
66inline ThreadPoolPtr make_thread_pool(uint64_t numThreads)
67{
68 return std::make_shared<ThreadPool>(numThreads);
69}
70
71void inline print_store_data(LMDBTreeStore::SharedPtr db, std::ostream& os)
72{
73 LMDBTreeStore::ReadTransaction::Ptr tx = db->create_read_transaction();
74 TreeDBStats stats;
75 db->get_stats(stats, *tx);
76
77 os << stats;
78}
79
80} // namespace bb::crypto::merkle_tree
std::shared_ptr< LMDBTreeStore > SharedPtr
std::unique_ptr< LMDBReadTransaction > Ptr
void info(Args... args)
Definition log.hpp:75
ssize_t offset
Definition engine.cpp:36
ThreadPoolPtr make_thread_pool(uint64_t numThreads)
Definition fixtures.hpp:66
const fr & get_value(size_t index)
const uint32_t NUM_VALUES
Definition fixtures.hpp:22
std::string random_temp_directory()
Definition fixtures.hpp:43
std::string random_string()
Definition fixtures.hpp:36
void print_tree(const uint32_t depth, std::vector< fr > hashes, std::string const &msg)
Definition fixtures.hpp:50
std::shared_ptr< ThreadPool > ThreadPoolPtr
Definition fixtures.hpp:64
void print_store_data(LMDBTreeStore::SharedPtr db, std::ostream &os)
Definition fixtures.hpp:71
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