Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
fixtures.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <ostream>
5#include <sstream>
6#include <string>
7#include <vector>
8
13
15
16const uint32_t NUM_VALUES = 1024;
19
20static auto create_values = [](uint32_t num_values = NUM_VALUES) {
21 std::vector<fr> values(num_values);
22 for (uint32_t i = 0; i < num_values; ++i) {
23 values[i] = fr(random_engine.get_random_uint256());
24 }
25 return values;
26};
27
28const fr& get_value(size_t index);
29
30inline std::string random_string()
31{
32 std::stringstream ss;
33 ss << random_engine.get_random_uint32();
34 return ss.str();
35}
36
37inline std::string random_temp_directory()
38{
39 std::stringstream ss;
40 ss << "/tmp/lmdb/" << random_string();
41 return ss.str();
42}
43
44inline void print_tree(const uint32_t depth, std::vector<fr> hashes, std::string const& msg)
45{
46 info("\n", msg);
47 uint32_t offset = 0;
48 for (uint32_t i = 0; i < depth; i++) {
49 info("i = ", i);
50 uint32_t layer_size = (1U << (depth - i));
51 for (uint32_t j = 0; j < layer_size; j++) {
52 info("j = ", j, ": ", hashes[offset + j]);
53 }
54 offset += layer_size;
55 }
56}
57
59
60inline ThreadPoolPtr make_thread_pool(uint64_t numThreads)
61{
62 return std::make_shared<ThreadPool>(numThreads);
63}
64
65void inline print_store_data(LMDBTreeStore::SharedPtr db, std::ostream& os)
66{
67 LMDBTreeStore::ReadTransaction::Ptr tx = db->create_read_transaction();
68 TreeDBStats stats;
69 db->get_stats(stats, *tx);
70
71 os << stats;
72}
73
74} // namespace bb::crypto::merkle_tree
std::shared_ptr< LMDBTreeStore > SharedPtr
std::unique_ptr< LMDBReadTransaction > Ptr
void info(Args... args)
Definition log.hpp:89
ssize_t offset
Definition engine.cpp:36
ThreadPoolPtr make_thread_pool(uint64_t numThreads)
Definition fixtures.hpp:60
const fr & get_value(size_t index)
const uint32_t NUM_VALUES
Definition fixtures.hpp:16
std::string random_temp_directory()
Definition fixtures.hpp:37
std::string random_string()
Definition fixtures.hpp:30
void print_tree(const uint32_t depth, std::vector< fr > hashes, std::string const &msg)
Definition fixtures.hpp:44
std::shared_ptr< ThreadPool > ThreadPoolPtr
Definition fixtures.hpp:58
void print_store_data(LMDBTreeStore::SharedPtr db, std::ostream &os)
Definition fixtures.hpp:65
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