Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
retrieved_bytecodes_tree_check.cpp
Go to the documentation of this file.
2
4
5namespace bb::avm2::simulation {
6
17{
18 const auto snapshot = tree.get_snapshot();
19 auto [exists, low_leaf_index] = tree.get_low_indexed_leaf(class_id);
20 auto sibling_path = tree.get_sibling_path(low_leaf_index);
21 auto low_leaf_preimage = tree.get_leaf_preimage(low_leaf_index);
22
23 indexed_tree_check.assert_read(class_id,
24 std::nullopt, // No siloing
25 exists,
27 .value = low_leaf_preimage.leaf.class_id,
28 .next_value = low_leaf_preimage.nextKey,
29 .next_index = low_leaf_preimage.nextIndex,
30 },
31 low_leaf_index,
32 sibling_path,
33 snapshot);
34 return exists;
35}
36
47{
49 auto insertion_result = tree.insert_indexed_leaves({ { ClassIdLeafValue(class_id) } });
50 auto& [low_leaf_preimage, low_leaf_index, low_leaf_sibling_path] = insertion_result.low_leaf_witness_data.at(0);
51 std::span<FF> insertion_sibling_path = insertion_result.insertion_witness_data.at(0).path;
52
53 // If we pass a insertion sibling path, indexed tree check will assert that the leaf doesn't exist,
54 // otherwise, it will assert that the leaf exists.
55 bool exists = class_id == low_leaf_preimage.leaf.class_id;
56
57 AppendOnlyTreeSnapshot next_snapshot =
58 indexed_tree_check.write(class_id,
59 std::nullopt, // No siloing
60 std::nullopt, // No public inputs write
62 .value = low_leaf_preimage.leaf.class_id,
63 .next_value = low_leaf_preimage.nextKey,
64 .next_index = low_leaf_preimage.nextIndex,
65 },
66 low_leaf_index,
67 low_leaf_sibling_path,
68 prev_snapshot,
69 exists ? std::nullopt : std::optional(insertion_sibling_path));
70
71 // This will throw an unexpected exception if it fails.
72 BB_ASSERT_EQ(next_snapshot, tree.get_snapshot(), "Next snapshot mismatch");
73}
74
83
90{
91 // -1 Since the tree has a prefill leaf at index 0.
92 return static_cast<uint32_t>(tree.get_snapshot().next_available_leaf_index) - 1;
93}
94
95} // namespace bb::avm2::simulation
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
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
SiblingPath get_sibling_path(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.
uint32_t size() const override
Returns the number of retrieved bytecode class IDs in the tree.
AppendOnlyTreeSnapshot get_snapshot() const override
Returns the current tree snapshot.
AVM range check gadget for witness generation.
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13