2#include <gtest/gtest.h>
10void print_tree(
const size_t depth, std::vector<fr> hashes, std::string
const& msg)
14 for (
size_t i = 0; i < depth; i++) {
16 size_t layer_size = (1UL << (depth - i));
17 for (
size_t j = 0; j < layer_size; j++) {
30 size_t depth_ = path.size();
32 for (
size_t i = 0; i < depth_; ++i) {
33 fr left = (index & 1) ? path[i].first : current;
34 fr right = (index & 1) ? current : path[i].second;
38 return current == root;
41TEST(crypto_nullifier_tree, test_nullifier_memory)
44 constexpr size_t depth = 3;
58 EXPECT_EQ(tree.
get_leaves()[0].unwrap(), first_leaf);
163 EXPECT_EQ(tree.
root(), root);
175TEST(crypto_nullifier_tree, test_nullifier_memory_appending_zero)
178 constexpr size_t depth = 3;
310 auto e000 = tree.
get_leaf(0).hash();
311 auto e001 = tree.
get_leaf(1).hash();
312 auto e010 = tree.
get_leaf(2).hash();
313 auto e011 = tree.
get_leaf(3).hash();
314 auto e100 = tree.
get_leaf(4).hash();
315 auto e101 = tree.
get_leaf(5).hash();
316 auto e110 = tree.
get_leaf(6).hash();
317 auto e111 = tree.
get_leaf(7).hash();
345 EXPECT_EQ(tree.
root(), root);
356TEST(crypto_nullifier_tree, test_nullifier_tree)
359 constexpr size_t depth = 8;
366 for (
size_t i = 0; i < 20; i++) {
383 for (
size_t i = 0; i < leaves.size(); i++) {
387 abs_diff(
uint256_t(new_member),
uint256_t(leaves[i].has_value() ? leaves[i].unwrap().nextValue : 0));
388 differences.push_back(diff_hi + diff_lo);
391 auto index =
static_cast<size_t>(it - differences.begin());
fr_hash_path get_hash_path(size_t index) const
const WrappedNullifierLeaf< HashingPolicy > get_leaf(size_t index)
const std::vector< WrappedNullifierLeaf< HashingPolicy > > & get_leaves()
fr_sibling_path update_element(fr const &value)
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::vector< std::pair< bb::stdlib::field_t< Ctx >, bb::stdlib::field_t< Ctx > > > hash_path
void print_tree(const uint32_t depth, std::vector< fr > hashes, std::string const &msg)
std::vector< std::pair< fr, fr > > fr_hash_path
bb::fr hash_pair_native(bb::fr const &lhs, bb::fr const &rhs)
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
bool check_hash_path(const fr &root, const fr_hash_path &path, const indexed_nullifier_leaf &leaf_value, const size_t idx)
WrappedNullifierLeaf< HashPolicy > WrappedLeaf
static fr hash_pair(const fr &lhs, const fr &rhs)
static field random_element(numeric::RNG *engine=nullptr) noexcept
static constexpr field zero()