Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
retrieved_bytecodes_tree_check.test.cpp
Go to the documentation of this file.
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
8
9namespace bb::avm2::simulation {
10
11using ::testing::_;
12using ::testing::Return;
13using ::testing::StrictMock;
14
17
18namespace {
19
20TEST(AvmSimulationRetrievedBytecodesTreeCheck, ContainsNotExists)
21{
22 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
24
25 FF class_id = 42;
26 auto snapshot = tree.get_snapshot();
27 auto [exists, low_leaf_index] = tree.get_low_indexed_leaf(class_id);
28 auto low_leaf = tree.get_leaf_preimage(low_leaf_index);
29 ASSERT_FALSE(exists);
30
31 IndexedTreeLeafData expected_leaf_data = {
32 .value = low_leaf.leaf.class_id,
33 .next_value = low_leaf.nextKey,
34 .next_index = low_leaf.nextIndex,
35 };
36
37 EXPECT_CALL(mock_indexed_tree_check,
38 assert_read(class_id, NO_SILOING, false, expected_leaf_data, low_leaf_index, _, snapshot));
39
40 RetrievedBytecodesTreeCheck bytecodes_check(mock_indexed_tree_check, tree);
41 EXPECT_FALSE(bytecodes_check.contains(class_id));
42}
43
44TEST(AvmSimulationRetrievedBytecodesTreeCheck, ContainsExists)
45{
46 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
49
50 FF class_id = 42;
51 auto snapshot = tree.get_snapshot();
52 auto [exists, low_leaf_index] = tree.get_low_indexed_leaf(class_id);
53 auto low_leaf = tree.get_leaf_preimage(low_leaf_index);
54 ASSERT_TRUE(exists);
55
56 IndexedTreeLeafData expected_leaf_data = {
57 .value = low_leaf.leaf.class_id,
58 .next_value = low_leaf.nextKey,
59 .next_index = low_leaf.nextIndex,
60 };
61
62 EXPECT_CALL(mock_indexed_tree_check,
63 assert_read(class_id, NO_SILOING, true, expected_leaf_data, low_leaf_index, _, snapshot));
64
65 RetrievedBytecodesTreeCheck bytecodes_check(mock_indexed_tree_check, tree);
66 EXPECT_TRUE(bytecodes_check.contains(class_id));
67}
68
69TEST(AvmSimulationRetrievedBytecodesTreeCheck, InsertExists)
70{
71 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
74
75 FF class_id = 42;
76 auto snapshot = tree.get_snapshot();
77
78 EXPECT_CALL(mock_indexed_tree_check, write(class_id, NO_SILOING, NO_PUBLIC_INPUTS_INDEX, _, _, _, snapshot, _))
79 .WillOnce(Return(snapshot));
80
81 RetrievedBytecodesTreeCheck bytecodes_check(mock_indexed_tree_check, tree);
82 bytecodes_check.insert(class_id);
83 EXPECT_EQ(bytecodes_check.get_snapshot(), snapshot);
84}
85
86TEST(AvmSimulationRetrievedBytecodesTreeCheck, InsertAppend)
87{
88 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
90
91 FF class_id = 100;
92 auto prev_snapshot = tree.get_snapshot();
93
94 // Compute expected post-insert state.
95 RetrievedBytecodesTree tree_after = tree;
96 tree_after.insert_indexed_leaves({ { ClassIdLeafValue(class_id) } });
97 auto next_snapshot = tree_after.get_snapshot();
98
99 EXPECT_CALL(mock_indexed_tree_check, write(class_id, NO_SILOING, NO_PUBLIC_INPUTS_INDEX, _, _, _, prev_snapshot, _))
100 .WillOnce(Return(next_snapshot));
101
102 RetrievedBytecodesTreeCheck bytecodes_check(mock_indexed_tree_check, tree);
103 bytecodes_check.insert(class_id);
104 EXPECT_EQ(bytecodes_check.get_snapshot(), next_snapshot);
105}
106
107} // namespace
108
109} // namespace bb::avm2::simulation
AppendOnlyTreeSnapshot get_snapshot() const
SequentialInsertionResult< LeafType > insert_indexed_leaves(std::span< const LeafType > leaves)
GetLowIndexedLeafResponse get_low_indexed_leaf(const FF &key) const
IndexedLeaf< LeafType > get_leaf_preimage(size_t leaf_index) const
bool contains(const FF &class_id) override
Checks whether a contract class ID exists in the retrieved bytecodes tree.
void insert(const FF &class_id) override
Inserts a contract class ID into the retrieved bytecodes tree.
AppendOnlyTreeSnapshot get_snapshot() const override
Returns the current tree snapshot.
IndexedTreeLeafData low_leaf
AVM range check gadget for witness generation.
const std::optional< uint64_t > NO_PUBLIC_INPUTS_INDEX
RetrievedBytecodesTree build_retrieved_bytecodes_tree()
const std::optional< IndexedTreeSiloingParameters > NO_SILOING
AvmFlavorSettings::FF FF
Definition field.hpp:10
void write(B &buf, field2< base_field, Params > const &value)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13