9#include "../memory_tree.hpp"
102template <
typename HashingPolicy>
117 for (
size_t i = 0; i < layer_size; ++i) {
120 current = HashingPolicy::hash_pair(current, current);
124 for (
size_t i = 0; i < initial_size; i++) {
127 leaves_.push_back(initial_leaf);
133 for (
size_t i = 0; i < initial_size; ++i) {
147 leaves_.push_back(zero_leaf);
148 update_element(leaves_.size() - 1, zero_leaf.hash());
153 bool is_already_present;
161 if (!is_already_present) {
166 leaves_[current].set(current_leaf);
169 leaves_.push_back(new_leaf);
174 auto old_leaf_hash = HashingPolicy::hash(current_leaf.
get_hash_inputs());
175 size_t old_leaf_index = current;
176 auto root = update_element(old_leaf_index, old_leaf_hash);
180 size_t new_leaf_index = is_already_present ? old_leaf_index : leaves_.size() - 1;
181 root = update_element(new_leaf_index, new_leaf_hash);
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_GT(left, right,...)
#define BB_ASSERT_LTE(left, right,...)
fr_hash_path get_hash_path(size_t index) const
fr_sibling_path get_sibling_path(size_t index) const
std::vector< bb::fr > hashes_
const std::vector< bb::fr > & get_hashes()
std::vector< WrappedNullifierLeaf< HashingPolicy > > leaves_
const WrappedNullifierLeaf< HashingPolicy > get_leaf(size_t index)
const std::vector< WrappedNullifierLeaf< HashingPolicy > > & get_leaves()
fr_sibling_path update_element(fr const &value)
NullifierMemoryTree(size_t depth, size_t initial_size=2)
Wrapper for the Nullifier leaf class that allows for 0 values.
static WrappedNullifierLeaf< HashingPolicy > zero()
Generate a zero leaf (call the constructor with no arguments)
void hash(State &state) noexcept
std::pair< size_t, bool > find_closest_leaf(std::vector< WrappedNullifierLeaf< HashingPolicy > > const &leaves_, fr const &new_value)
std::vector< std::pair< bb::stdlib::field_t< Ctx >, bb::stdlib::field_t< Ctx > > > hash_path
std::vector< fr > fr_sibling_path
fr_sibling_path get_sibling_path(TypeOfTree &tree, index_t index, bool includeUncommitted=true, bool expected_success=true)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< fr > get_hash_inputs() const
static indexed_nullifier_leaf zero()
static constexpr field zero()