30 BB_ASSERT_LTE(sibling_path.size(),
static_cast<size_t>(64),
"Merkle path length must be less than or equal to 64");
32 FF curr_value = leaf_value;
33 uint64_t curr_index = leaf_index;
34 for (
const auto& sibling : sibling_path) {
35 bool index_is_even = (curr_index % 2 == 0);
37 curr_value = index_is_even ?
poseidon2.
hash({
FF(domain_separator), curr_value, sibling })
44 if (curr_index != 0) {
45 throw std::runtime_error(
"Merkle check's final node index must be 0");
47 if (curr_value != root) {
48 throw std::runtime_error(
"Merkle read check failed");
51 std::vector<FF> sibling_vec(sibling_path.begin(), sibling_path.end());
53 .merkle_hash_domain_separator = domain_separator,
54 .leaf_value = leaf_value,
55 .leaf_index = leaf_index,
79 const FF& current_value,
83 const FF& current_root)
86 BB_ASSERT_LTE(sibling_path.size(),
static_cast<size_t>(64),
"Merkle path length must be less than or equal to 64");
88 FF read_value = current_value;
89 FF write_value = new_value;
90 uint64_t curr_index = leaf_index;
92 for (
const auto& sibling : sibling_path) {
93 bool index_is_even = (curr_index % 2 == 0);
95 read_value = index_is_even ?
poseidon2.
hash({
FF(domain_separator), read_value, sibling })
97 write_value = index_is_even ?
poseidon2.
hash({
FF(domain_separator), write_value, sibling })
104 if (curr_index != 0) {
105 throw std::runtime_error(
"Merkle check's final node index must be 0");
107 if (read_value != current_root) {
108 throw std::runtime_error(
"Merkle read check failed");
111 std::vector<FF> sibling_vec(sibling_path.begin(), sibling_path.end());
113 .merkle_hash_domain_separator = domain_separator,
114 .leaf_value = current_value,
115 .new_leaf_value = new_value,
116 .leaf_index = leaf_index,
118 .root = current_root,
119 .new_root = write_value,
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,...