diff --git a/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp b/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp index 4dffee6023..4efdb0a881 100644 --- a/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp +++ b/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp @@ -1,4 +1,5 @@ #include "hash.hpp" +#include "memory_tree.hpp" #include #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "barretenberg/stdlib/merkle_tree/membership.hpp" @@ -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 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 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()); +}