Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
test_tree.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace bb::avm2::testing {
8
9// This is a memory tree that can generate sibling paths of any size.
10// The standard memory tree only supports up to 20 layers
11// However in VM2 testing we sometimes need to generate sibling paths with real lengths.
12template <typename HashingPolicy> class TestMemoryTree {
13 public:
19
21
22 FF update_element(size_t index, FF const& value);
23
24 FF root() const;
25
26 private:
29 size_t depth;
30};
31
32template <typename HashingPolicy> FF TestMemoryTree<HashingPolicy>::update_element(size_t index, FF const& value)
33{
34 if (index > (1ULL << depth)) {
35 throw std::invalid_argument("Index outside real tree");
36 }
37 return real_tree.update_element(index, value);
38}
39
40template <typename HashingPolicy> fr_sibling_path TestMemoryTree<HashingPolicy>::get_sibling_path(size_t index)
41{
42 std::vector<FF> real_path = real_tree.get_sibling_path(index);
43 for (size_t i = 0; i < total_depth - depth; i++) {
44 real_path.emplace_back(0);
45 }
46 return real_path;
47}
48
49template <typename HashingPolicy> FF TestMemoryTree<HashingPolicy>::root() const
50{
51 FF root = real_tree.root();
52 for (size_t i = 0; i < total_depth - depth; i++) {
53 root = HashingPolicy::hash_pair(root, 0);
54 }
55 return root;
56}
57
58} // namespace bb::avm2::testing
TestMemoryTree(size_t depth, size_t total_depth)
Definition test_tree.hpp:14
FF update_element(size_t index, FF const &value)
Definition test_tree.hpp:32
fr_sibling_path get_sibling_path(size_t index)
Definition test_tree.hpp:40
MemoryTree< HashingPolicy > real_tree
Definition test_tree.hpp:27
AvmFlavorSettings::FF FF
Definition field.hpp:10
std::vector< fr > fr_sibling_path
Definition hash_path.hpp:16