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 = {
34 .leaf_value = leaf_value,
35 .leaf_index = leaf_index,
36 .sibling_path = sibling_path,
41 uint64_t leaf_index2 = 31;
42 std::vector<FF> sibling_path2 = { 10, 2, 30, 4, 50, 7 };
45 MerkleCheckEvent expect_event2 = {
47 .leaf_value = leaf_value2,
48 .leaf_index = leaf_index2,
49 .sibling_path = sibling_path2,
53 EXPECT_THAT(emitter.dump_events(), ElementsAre(expect_event, expect_event2));
56TEST(MerkleCheckSimulationTest, Write)
59 PurePoseidon2
poseidon2 = PurePoseidon2();
61 EventEmitter<MerkleCheckEvent> emitter;
64 FF current_value = 333;
66 uint64_t leaf_index = 30;
67 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
71 MerkleCheckEvent expect_event = {
73 .leaf_value = current_value,
74 .new_leaf_value = new_value,
75 .leaf_index = leaf_index,
76 .sibling_path = sibling_path,
78 .new_root = expected_new_root,
84 EXPECT_EQ(new_root, expected_new_root);
85 EXPECT_THAT(emitter.dump_events(), ElementsAre(expect_event));
88TEST(MerkleCheckSimulationTest, NegativeBadFinalIndex)
91 PurePoseidon2
poseidon2 = PurePoseidon2();
93 EventEmitter<MerkleCheckEvent> emitter;
97 uint64_t leaf_index = 64;
98 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
103 "Merkle check's final node index must be 0");
105 "Merkle check's final node index must be 0");
108TEST(MerkleCheckSimulationTest, NegativeWrongRoot)
111 PurePoseidon2
poseidon2 = PurePoseidon2();
113 EventEmitter<MerkleCheckEvent> emitter;
117 uint64_t leaf_index = 30;
118 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
119 FF incorrect_root = 66;
123 "Merkle read check failed");
126 "Merkle read check failed");
129TEST(MerkleCheckSimulationTest, NegativeWrongLeafIndex)
132 PurePoseidon2
poseidon2 = PurePoseidon2();
134 EventEmitter<MerkleCheckEvent> emitter;
138 uint64_t leaf_index = 30;
139 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
141 uint64_t incorrect_leaf_index = 31;
144 "Merkle read check failed");
147 "Merkle read check failed");
150TEST(MerkleCheckSimulationTest, NegativeWrongSiblingPath)
153 PurePoseidon2
poseidon2 = PurePoseidon2();
155 EventEmitter<MerkleCheckEvent> emitter;
159 uint64_t leaf_index = 30;
160 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
163 sibling_path[2] = 11;
167 "Merkle read check failed");
169 "Merkle read check failed");
172TEST(MerkleCheckSimulationTest, NegativeWrongLeafValue)
175 PurePoseidon2
poseidon2 = PurePoseidon2();
177 EventEmitter<MerkleCheckEvent> emitter;
181 uint64_t leaf_index = 30;
182 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
184 FF incorrect_leaf_value = 334;
188 "Merkle read check failed");
191 "Merkle read check failed");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define DOM_SEP__MERKLE_HASH
FF write(uint64_t domain_separator, const FF ¤t_value, const FF &new_value, 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(uint64_t domain_separator, const FF &leaf_value, 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(uint64_t domain_separator, const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > path)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)