barretenberg
Loading...
Searching...
No Matches
merkle_tree.hpp
1#pragma once
2#include "barretenberg/stdlib/primitives/field/field.hpp"
3#include "hash_path.hpp"
4
5namespace proof_system::plonk {
6namespace stdlib {
7namespace merkle_tree {
8
9using namespace barretenberg;
10
11class MemoryStore;
12
13template <typename Store> class MerkleTree {
14 public:
15 typedef uint256_t index_t;
16
17 MerkleTree(Store& store, size_t depth, uint8_t tree_id = 0);
18 MerkleTree(MerkleTree const& other) = delete;
19 MerkleTree(MerkleTree&& other);
21
22 fr_hash_path get_hash_path(index_t index);
23
24 fr_sibling_path get_sibling_path(index_t index);
25
26 fr update_element(index_t index, fr const& value);
27
28 fr root() const;
29
30 size_t depth() const { return depth_; }
31
32 index_t size() const;
33
34 protected:
35 void load_metadata();
36
46 fr update_element(fr const& root, fr const& value, index_t index, size_t height);
47
48 fr get_element(fr const& root, index_t index, size_t height);
49
57 fr compute_zero_path_hash(size_t height, index_t index, fr const& value);
58
67 fr binary_put(index_t a_index, fr const& a, fr const& b, size_t height);
68
69 fr fork_stump(
70 fr const& value1, index_t index1, fr const& value2, index_t index2, size_t height, size_t stump_height);
71
79 void put(fr const& key, fr const& left, fr const& right);
80
89 void put_stump(fr const& key, index_t index, fr const& value);
90
91 void remove(fr const& key);
92
93 protected:
94 Store& store_;
95 std::vector<fr> zero_hashes_;
96 size_t depth_;
97 uint8_t tree_id_;
98};
99
100extern template class MerkleTree<MemoryStore>;
101
102} // namespace merkle_tree
103} // namespace stdlib
104} // namespace proof_system::plonk
Definition: uint256.hpp:25
fr compute_zero_path_hash(size_t height, index_t index, fr const &value)
Definition: merkle_tree.cpp:313
void put(fr const &key, fr const &left, fr const &right)
Definition: merkle_tree.cpp:331
void put_stump(fr const &key, index_t index, fr const &value)
Definition: merkle_tree.cpp:339
fr binary_put(index_t a_index, fr const &a, fr const &b, size_t height)
Definition: merkle_tree.cpp:219
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16
Definition: widget.bench.cpp:13