3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
14using ::testing::Return;
15using ::testing::StrictMock;
21const IndexedTreeSiloingParameters SLOT_SILOING_PARAMS = {
27TEST(AvmSimulationWrittenPublicDataSlotsTreeCheck, ContainsNotExists)
29 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
36 auto snapshot = tree.get_snapshot();
37 auto [
exists, low_leaf_index] = tree.get_low_indexed_leaf(leaf_slot);
38 auto low_leaf = tree.get_leaf_preimage(low_leaf_index);
41 IndexedTreeLeafData expected_leaf_data = {
47 EXPECT_CALL(mock_indexed_tree_check,
48 assert_read(
slot, OPT_SLOT_SILOING_PARAMS,
false, expected_leaf_data, low_leaf_index, _, snapshot));
50 WrittenPublicDataSlotsTreeCheck slots_check(mock_indexed_tree_check, tree);
54TEST(AvmSimulationWrittenPublicDataSlotsTreeCheck, ContainsExists)
56 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
62 tree.insert_indexed_leaves({ { WrittenPublicDataSlotLeafValue(leaf_slot) } });
64 auto snapshot = tree.get_snapshot();
65 auto [
exists, low_leaf_index] = tree.get_low_indexed_leaf(leaf_slot);
66 auto low_leaf = tree.get_leaf_preimage(low_leaf_index);
69 IndexedTreeLeafData expected_leaf_data = {
75 EXPECT_CALL(mock_indexed_tree_check,
76 assert_read(
slot, OPT_SLOT_SILOING_PARAMS,
true, expected_leaf_data, low_leaf_index, _, snapshot));
78 WrittenPublicDataSlotsTreeCheck slots_check(mock_indexed_tree_check, tree);
82TEST(AvmSimulationWrittenPublicDataSlotsTreeCheck, InsertExists)
84 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
90 tree.insert_indexed_leaves({ { WrittenPublicDataSlotLeafValue(leaf_slot) } });
92 auto snapshot = tree.get_snapshot();
94 EXPECT_CALL(mock_indexed_tree_check,
96 .WillOnce(Return(snapshot));
98 WrittenPublicDataSlotsTreeCheck slots_check(mock_indexed_tree_check, tree);
100 EXPECT_EQ(slots_check.get_snapshot(), snapshot);
103TEST(AvmSimulationWrittenPublicDataSlotsTreeCheck, InsertAppend)
105 StrictMock<MockIndexedTreeCheck> mock_indexed_tree_check;
111 auto prev_snapshot = tree.get_snapshot();
115 tree_after.insert_indexed_leaves({ { WrittenPublicDataSlotLeafValue(leaf_slot) } });
116 auto next_snapshot = tree_after.get_snapshot();
118 EXPECT_CALL(mock_indexed_tree_check,
120 .WillOnce(Return(next_snapshot));
122 WrittenPublicDataSlotsTreeCheck slots_check(mock_indexed_tree_check, tree);
124 EXPECT_EQ(slots_check.get_snapshot(), next_snapshot);
127TEST(AvmSimulationWrittenPublicDataSlotsTreeCheck, CheckpointBehavior)
131 testing::NiceMock<MockIndexedTreeCheck> mock_indexed_tree_check;
136 ON_CALL(mock_indexed_tree_check,
write)
137 .WillByDefault([¶llel_tree](
const FF&
slot,
140 const IndexedTreeLeafData&,
143 const AppendOnlyTreeSnapshot&,
145 if (insertion_path.has_value()) {
146 FF leaf_slot = unconstrained_compute_leaf_slot(siloing_params.value().address, slot);
147 parallel_tree.insert_indexed_leaves({ { WrittenPublicDataSlotLeafValue(leaf_slot) } });
149 return parallel_tree.get_snapshot();
152 WrittenPublicDataSlotsTreeCheck slots_check(mock_indexed_tree_check, tree);
154 EXPECT_EQ(slots_check.size(), 0);
155 slots_check.create_checkpoint();
158 slots_check.insert(address1, 1);
159 EXPECT_TRUE(slots_check.contains(address1, 1));
160 EXPECT_EQ(slots_check.size(), 1);
163 slots_check.commit_checkpoint();
164 EXPECT_TRUE(slots_check.contains(address1, 1));
165 EXPECT_EQ(slots_check.size(), 1);
168 slots_check.create_checkpoint();
172 slots_check.insert(address2, 2);
173 EXPECT_TRUE(slots_check.contains(address2, 2));
174 EXPECT_EQ(slots_check.size(), 2);
177 slots_check.revert_checkpoint();
178 EXPECT_TRUE(slots_check.contains(address1, 1));
179 EXPECT_EQ(slots_check.size(), 1);
#define DOM_SEP__PUBLIC_LEAF_SLOT
IndexedTreeLeafData low_leaf
AVM range check gadget for witness generation.
const std::optional< uint64_t > NO_PUBLIC_INPUTS_INDEX
WrittenPublicDataSlotsTree build_public_data_slots_tree()
FF unconstrained_compute_leaf_slot(const AztecAddress &contract_address, const FF &slot)
IndexedMemoryTree< WrittenPublicDataSlotLeafValue, Poseidon2HashPolicy > WrittenPublicDataSlotsTree
void write(B &buf, field2< base_field, Params > const &value)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept