11 const uint64_t leaf_index,
16 assert(sibling_path.size() <= 254 &&
"Merkle path length must be less than 254");
18 FF curr_value = leaf_value;
19 uint64_t curr_index = leaf_index;
21 for (
size_t i = 0; i < sibling_path.size(); ++i) {
22 const FF sibling = sibling_path[i];
23 bool index_is_even = (curr_index % 2 == 0);
30 if (i < sibling_path.size() - 1) {
35 if (curr_index != 0 && curr_index != 1) {
36 throw std::runtime_error(
"Merkle check's final node index must be 0 or 1");
38 if (curr_value != root) {
39 throw std::runtime_error(
"Merkle read check failed");
42 std::vector<FF> sibling_vec(sibling_path.begin(), sibling_path.end());
44 { .leaf_value = leaf_value, .leaf_index = leaf_index, .sibling_path =
std::move(sibling_vec), .root = root });
49 const uint64_t leaf_index,
51 const FF& current_root)
54 assert(sibling_path.size() <= 254 &&
"Merkle path length must be less than 254");
56 FF read_value = current_value;
57 FF write_value = new_value;
58 uint64_t curr_index = leaf_index;
60 for (
size_t i = 0; i < sibling_path.size(); ++i) {
61 const FF sibling = sibling_path[i];
62 bool index_is_even = (curr_index % 2 == 0);
71 if (i < sibling_path.size() - 1) {
76 if (curr_index != 0 && curr_index != 1) {
77 throw std::runtime_error(
"Merkle check's final node index must be 0 or 1");
79 if (read_value != current_root) {
80 throw std::runtime_error(
"Merkle read check failed");
83 std::vector<FF> sibling_vec(sibling_path.begin(), sibling_path.end());
84 events.emit({ .leaf_value = current_value,
85 .new_leaf_value = new_value,
86 .leaf_index = leaf_index,
89 .new_root = write_value });