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
3
#include "
barretenberg/crypto/merkle_tree/memory_tree.hpp
"
4
#include "
barretenberg/vm2/common/field.hpp
"
5
#include "
barretenberg/vm2/simulation/lib/db_interfaces.hpp
"
6
7
namespace
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.
12
template
<
typename
HashingPolicy>
class
TestMemoryTree
{
13
public
:
14
TestMemoryTree
(
size_t
depth
,
size_t
total_depth
)
15
:
real_tree
(
depth
)
16
,
total_depth
(
total_depth
)
17
,
depth
(
depth
)
18
{}
19
20
fr_sibling_path
get_sibling_path
(
size_t
index);
21
22
FF
update_element
(
size_t
index,
FF
const
&
value
);
23
24
FF
root
()
const
;
25
26
private
:
27
MemoryTree<HashingPolicy>
real_tree
;
28
size_t
total_depth
;
29
size_t
depth
;
30
};
31
32
template
<
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
40
template
<
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
49
template
<
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
bb::avm2::testing::TestMemoryTree
Definition
test_tree.hpp:12
bb::avm2::testing::TestMemoryTree::TestMemoryTree
TestMemoryTree(size_t depth, size_t total_depth)
Definition
test_tree.hpp:14
bb::avm2::testing::TestMemoryTree::update_element
FF update_element(size_t index, FF const &value)
Definition
test_tree.hpp:32
bb::avm2::testing::TestMemoryTree::depth
size_t depth
Definition
test_tree.hpp:29
bb::avm2::testing::TestMemoryTree::get_sibling_path
fr_sibling_path get_sibling_path(size_t index)
Definition
test_tree.hpp:40
bb::avm2::testing::TestMemoryTree::real_tree
MemoryTree< HashingPolicy > real_tree
Definition
test_tree.hpp:27
bb::avm2::testing::TestMemoryTree::root
FF root() const
Definition
test_tree.hpp:49
bb::avm2::testing::TestMemoryTree::total_depth
size_t total_depth
Definition
test_tree.hpp:28
bb::crypto::merkle_tree::MemoryTree
Definition
memory_tree.hpp:30
db_interfaces.hpp
memory_tree.hpp
bb::avm2::testing
Definition
fixtures.cpp:17
bb::avm2::FF
AvmFlavorSettings::FF FF
Definition
field.hpp:10
bb::crypto::merkle_tree::fr_sibling_path
std::vector< fr > fr_sibling_path
Definition
hash_path.hpp:16
value
FF value
Definition
public_data_tree.test.cpp:96
field.hpp
src
barretenberg
vm2
testing
test_tree.hpp
Generated by
1.9.8