3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
16using testing::ElementsAre;
18TEST(MerkleCheckSimulationTest, AssertMembership)
21 PurePoseidon2
poseidon2 = PurePoseidon2();
23 EventEmitter<MerkleCheckEvent> emitter;
27 uint64_t leaf_index = 30;
28 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
32 MerkleCheckEvent expect_event = {
33 .leaf_value = leaf_value,
34 .leaf_index = leaf_index,
35 .sibling_path = sibling_path,
40 uint64_t leaf_index2 = 31;
41 std::vector<FF> sibling_path2 = { 10, 2, 30, 4, 50, 7 };
44 MerkleCheckEvent expect_event2 = {
45 .leaf_value = leaf_value2,
46 .leaf_index = leaf_index2,
47 .sibling_path = sibling_path2,
51 EXPECT_THAT(emitter.dump_events(), ElementsAre(expect_event, expect_event2));
54TEST(MerkleCheckSimulationTest, Write)
57 PurePoseidon2
poseidon2 = PurePoseidon2();
59 EventEmitter<MerkleCheckEvent> emitter;
62 FF current_value = 333;
64 uint64_t leaf_index = 30;
65 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
69 MerkleCheckEvent expect_event = {
70 .leaf_value = current_value,
71 .new_leaf_value = new_value,
72 .leaf_index = leaf_index,
73 .sibling_path = sibling_path,
75 .new_root = expected_new_root,
78 FF new_root =
merkle_check.
write(current_value, new_value, leaf_index, sibling_path, current_root);
80 EXPECT_EQ(new_root, expected_new_root);
81 EXPECT_THAT(emitter.dump_events(), ElementsAre(expect_event));
84TEST(MerkleCheckSimulationTest, NegativeBadFinalIndex)
87 PurePoseidon2
poseidon2 = PurePoseidon2();
89 EventEmitter<MerkleCheckEvent> emitter;
93 uint64_t leaf_index = 64;
94 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
98 "Merkle check's final node index must be 0");
100 "Merkle check's final node index must be 0");
103TEST(MerkleCheckSimulationTest, NegativeWrongRoot)
106 PurePoseidon2
poseidon2 = PurePoseidon2();
108 EventEmitter<MerkleCheckEvent> emitter;
112 uint64_t leaf_index = 30;
113 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
114 FF incorrect_root = 66;
117 "Merkle read check failed");
119 "Merkle read check failed");
122TEST(MerkleCheckSimulationTest, NegativeWrongLeafIndex)
125 PurePoseidon2
poseidon2 = PurePoseidon2();
127 EventEmitter<MerkleCheckEvent> emitter;
131 uint64_t leaf_index = 30;
132 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
134 uint64_t incorrect_leaf_index = 31;
136 "Merkle read check failed");
138 "Merkle read check failed");
141TEST(MerkleCheckSimulationTest, NegativeWrongSiblingPath)
144 PurePoseidon2
poseidon2 = PurePoseidon2();
146 EventEmitter<MerkleCheckEvent> emitter;
150 uint64_t leaf_index = 30;
151 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
154 sibling_path[2] = 11;
157 "Merkle read check failed");
159 "Merkle read check failed");
162TEST(MerkleCheckSimulationTest, NegativeWrongLeafValue)
165 PurePoseidon2
poseidon2 = PurePoseidon2();
167 EventEmitter<MerkleCheckEvent> emitter;
171 uint64_t leaf_index = 30;
172 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
174 FF incorrect_leaf_value = 334;
177 "Merkle read check failed");
179 "Merkle read check failed");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
FF write(const FF ¤t_value, const FF &new_value, const uint64_t leaf_index, std::span< const FF > sibling_path, const FF ¤t_root) override
Assert the membership of the current leaf value (same logic as assert_membership())....
void assert_membership(const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > sibling_path, const FF &root) override
Assert membership of a leaf in a Merkle tree, i.e., verify that the leaf value, leaf index,...
Native Poseidon2 hash function implementation.
AVM range check gadget for witness generation.
FF unconstrained_root_from_path(const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > path)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)