Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
array_store.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#include "./tree_meta.hpp"
11#include <memory>
12
14
16 public:
18 bool get_node(uint32_t, index_t, std::vector<uint8_t>&) const { return false; }
19
20 template <typename T> void get_value_by_integer(T&, std::vector<uint8_t>&) {};
21
22 void get_value(std::vector<uint8_t>&, std::vector<uint8_t>&) {};
23
24 void put_node(uint32_t, index_t, const std::vector<uint8_t>&) {}
25
26 template <typename T> void put_value_by_integer(T&, std::vector<uint8_t>&) {};
27
28 void put_value(std::vector<uint8_t>&, std::vector<uint8_t>&) {};
29};
30
38
43template <typename PersistedStore> class ArrayStore {
44
45 public:
46 using ReadTransaction = typename PersistedStore::ReadTransaction;
47 using WriteTransaction = typename PersistedStore::WriteTransaction;
49 ArrayStore(const std::string& name, uint32_t depth, index_t indices = 1024)
50 : map(std::vector<std::vector<std::pair<bool, std::vector<uint8_t>>>>(
51 depth + 1,
52 std::vector<std::pair<bool, std::vector<uint8_t>>>(
53 indices, std::pair<bool, std::vector<uint8_t>>(false, std::vector<uint8_t>()))))
54 {
55 meta.depth = depth;
56 meta.name = name;
57 meta.size = 0;
58 }
59 ~ArrayStore() = default;
60
61 ArrayStore() = delete;
62 ArrayStore(ArrayStore const& other) = delete;
63 ArrayStore(ArrayStore const&& other) = delete;
64 ArrayStore& operator=(ArrayStore const& other) = delete;
65 ArrayStore& operator=(ArrayStore const&& other) = delete;
66
67 void put_node(uint32_t level, index_t index, const std::vector<uint8_t>& data)
68 {
69 map[level][index] = std::make_pair(true, data);
70 }
71 bool get_node(uint32_t level, index_t index, std::vector<uint8_t>& data, ReadTransaction&, bool) const
72 {
73 const std::pair<bool, std::vector<uint8_t>>& slot = map[level][index];
74 if (slot.first) {
75 data = slot.second;
76 }
77 return slot.first;
78 }
79 void put_meta(const index_t& size, const bb::fr& root)
80 {
81 meta.root = root;
82 meta.size = size;
83 }
84
85 void get_meta(index_t& size, bb::fr& root, ReadTransaction&, bool) const
86 {
87 size = meta.size;
88 root = meta.root;
89 }
90
91 void commit() {};
92 void rollback() {};
93
95
96 private:
99};
100} // namespace bb::crypto::merkle_tree
A very basic 2-d array for use as a backing store for merkle trees. Can store up to 'indices' nodes p...
ArrayStore(ArrayStore const &other)=delete
ReadTransactionPtr create_read_transactiono()
void put_meta(const index_t &size, const bb::fr &root)
void put_node(uint32_t level, index_t index, const std::vector< uint8_t > &data)
ArrayStore(ArrayStore const &&other)=delete
ArrayStore & operator=(ArrayStore const &&other)=delete
ArrayStore & operator=(ArrayStore const &other)=delete
ArrayStore(const std::string &name, uint32_t depth, index_t indices=1024)
void get_meta(index_t &size, bb::fr &root, ReadTransaction &, bool) const
typename PersistedStore::WriteTransaction WriteTransaction
std::vector< std::vector< std::pair< bool, std::vector< uint8_t > > > > map
typename PersistedStore::ReadTransaction ReadTransaction
bool get_node(uint32_t level, index_t index, std::vector< uint8_t > &data, ReadTransaction &, bool) const
std::unique_ptr< ReadTransaction > ReadTransactionPtr
static MockTransaction::Ptr create_write_transaction()
static MockTransaction::Ptr create_read_transaction()
std::unique_ptr< MockTransaction > Ptr
void get_value(std::vector< uint8_t > &, std::vector< uint8_t > &)
void put_value_by_integer(T &, std::vector< uint8_t > &)
bool get_node(uint32_t, index_t, std::vector< uint8_t > &) const
void put_value(std::vector< uint8_t > &, std::vector< uint8_t > &)
void put_node(uint32_t, index_t, const std::vector< uint8_t > &)
void get_value_by_integer(T &, std::vector< uint8_t > &)
const std::vector< FF > data
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13