Skip to content

Commit

Permalink
Added test for compute_tree_native. (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyash67 authored and codygunton committed Apr 6, 2023
1 parent 5cbc33d commit 58d4d72
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "hash.hpp"
#include "memory_tree.hpp"
#include <gtest/gtest.h>
#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp"
#include "barretenberg/stdlib/merkle_tree/membership.hpp"
Expand Down Expand Up @@ -35,3 +36,24 @@ TEST(stdlib_merkle_tree_hash, compute_tree_root_native_vs_circuit)

EXPECT_EQ(z.get_value(), zz);
}

TEST(stdlib_merkle_tree_hash, compute_tree_native)
{
constexpr size_t depth = 2;
stdlib::merkle_tree::MemoryTree mem_tree(depth);

std::vector<fr> leaves;
for (size_t i = 0; i < (size_t(1) << depth); i++) {
auto input = fr::random_element();
leaves.push_back(input);
mem_tree.update_element(i, input);
}

std::vector<fr> tree_vector = plonk::stdlib::merkle_tree::compute_tree_native(leaves);

// Check if the tree vector matches the memory tree hashes
for (size_t i = 0; i < tree_vector.size() - 1; i++) {
EXPECT_EQ(tree_vector[i], mem_tree.hashes_[i]);
}
EXPECT_EQ(tree_vector.back(), mem_tree.root());
}

0 comments on commit 58d4d72

Please sign in to comment.