11 const uint64_t leaf_index,
16 assert(sibling_path.size() <= 64 &&
"Merkle path length must be less than or equal to 64");
18 FF curr_value = leaf_value;
19 uint64_t curr_index = leaf_index;
20 for (
const auto& sibling : sibling_path) {
21 bool index_is_even = (curr_index % 2 == 0);
29 if (curr_index != 0) {
30 throw std::runtime_error(
"Merkle check's final node index must be 0");
32 if (curr_value != root) {
33 throw std::runtime_error(
"Merkle read check failed");
36 std::vector<FF> sibling_vec(sibling_path.begin(), sibling_path.end());
38 { .leaf_value = leaf_value, .leaf_index = leaf_index, .sibling_path =
std::move(sibling_vec), .root = root });
43 const uint64_t leaf_index,
45 const FF& current_root)
48 assert(sibling_path.size() <= 64 &&
"Merkle path length must be less than or equal to 64");
50 FF read_value = current_value;
51 FF write_value = new_value;
52 uint64_t curr_index = leaf_index;
54 for (
const auto& sibling : sibling_path) {
55 bool index_is_even = (curr_index % 2 == 0);
65 if (curr_index != 0) {
66 throw std::runtime_error(
"Merkle check's final node index must be 0");
68 if (read_value != current_root) {
69 throw std::runtime_error(
"Merkle read check failed");
72 std::vector<FF> sibling_vec(sibling_path.begin(), sibling_path.end());
73 events.emit({ .leaf_value = current_value,
74 .new_leaf_value = new_value,
75 .leaf_index = leaf_index,
78 .new_root = write_value });