2#include "barretenberg/stdlib/primitives/field/field.hpp"
7namespace proof_system::plonk::stdlib::merkle_tree {
11using fr_hash_path = std::vector<std::pair<fr, fr>>;
12using fr_sibling_path = std::vector<fr>;
13template <
typename Ctx>
using hash_path = std::vector<std::pair<field_t<Ctx>,
field_t<Ctx>>>;
15inline fr_hash_path get_new_hash_path(fr_hash_path
const& old_path, uint128_t index,
fr const& value)
17 fr_hash_path path = old_path;
19 for (
size_t i = 0; i < old_path.size(); ++i) {
20 bool path_bit =
static_cast<bool>(index & 0x1);
22 path[i].second = current;
24 path[i].first = current;
26 current = hash_pair_native(path[i].first, path[i].second);
32inline fr_hash_path get_random_hash_path(
size_t const& tree_depth)
35 for (
size_t i = 0; i < tree_depth; ++i) {
36 path.push_back(std::make_pair(fr::random_element(), fr::random_element()));
41template <
typename Ctx>
inline hash_path<Ctx> create_witness_hash_path(Ctx& ctx, fr_hash_path
const& input)
43 hash_path<Ctx> result;
44 std::transform(input.begin(), input.end(), std::back_inserter(result), [&](
auto const& v) {
45 return std::make_pair(field_t(witness_t(&ctx, v.first)), field_t(witness_t(&ctx, v.second)));
50inline fr get_hash_path_root(fr_hash_path
const& input)
52 return hash_pair_native(input[input.size() - 1].first, input[input.size() - 1].second);
55inline fr zero_hash_at_height(
size_t height)
58 for (
size_t i = 0; i < height; ++i) {
59 current = hash_pair_native(current, current);
69template <
typename Ctx>
70inline std::ostream& operator<<(std::ostream& os, proof_system::plonk::stdlib::merkle_tree::hash_path<Ctx>
const& path)
73 for (
size_t i = 0; i < path.size(); ++i) {
74 os <<
" (" << i <<
": " << path[i].first <<
", " << path[i].second <<
")\n";
80inline std::ostream& operator<<(std::ostream& os, proof_system::plonk::stdlib::merkle_tree::fr_hash_path
const& path)
83 for (
size_t i = 0; i < path.size(); ++i) {
84 os <<
" (" << i <<
": " << path[i].first <<
", " << path[i].second <<
")\n";
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16