Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hash_path.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Planned, auditors: [Raju], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
9#include "hash.hpp"
10#include <algorithm>
11#include <vector>
12
14
16using fr_sibling_path = std::vector<fr>;
18
19inline fr_hash_path get_random_hash_path(size_t const& tree_depth)
20{
21 fr_hash_path path;
22 for (size_t i = 0; i < tree_depth; ++i) {
24 }
25 return path;
26}
27
28template <typename Ctx> inline hash_path<Ctx> create_witness_hash_path(Ctx& ctx, fr_hash_path const& input)
29{
30 hash_path<Ctx> result;
31 std::transform(input.begin(), input.end(), std::back_inserter(result), [&](auto const& v) {
32 return std::make_pair(bb::stdlib::field_t(bb::stdlib::witness_t(&ctx, v.first)),
33 bb::stdlib::field_t(bb::stdlib::witness_t(&ctx, v.second)));
34 });
35 return result;
36}
37
38} // namespace bb::crypto::merkle_tree
39
40// We add to std namespace as fr_hash_path is actually a std::vector, and this is the only way
41// to achieve effective ADL.
42namespace std {
43template <typename Ctx>
44inline std::ostream& operator<<(std::ostream& os, bb::crypto::merkle_tree::hash_path<Ctx> const& path)
45{
46 os << "[\n";
47 for (size_t i = 0; i < path.size(); ++i) {
48 os << " (" << i << ": " << path[i].first << ", " << path[i].second << ")\n";
49 }
50 os << "]\n";
51 return os;
52}
53
54inline std::ostream& operator<<(std::ostream& os, bb::crypto::merkle_tree::fr_hash_path const& path)
55{
56 os << "[\n";
57 for (size_t i = 0; i < path.size(); ++i) {
58 os << " (" << i << ": " << path[i].first << ", " << path[i].second << ")\n";
59 }
60 os << "]\n";
61 return os;
62}
63} // namespace std
std::vector< std::pair< bb::stdlib::field_t< Ctx >, bb::stdlib::field_t< Ctx > > > hash_path
Definition hash_path.hpp:17
hash_path< Ctx > create_witness_hash_path(Ctx &ctx, fr_hash_path const &input)
Definition hash_path.hpp:28
fr_hash_path get_random_hash_path(size_t const &tree_depth)
Definition hash_path.hpp:19
std::vector< std::pair< fr, fr > > fr_hash_path
Definition hash_path.hpp:15
std::vector< fr > fr_sibling_path
Definition hash_path.hpp:16
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::ostream & operator<<(std::ostream &os, const T &obj)
Automatically derived stream operator for any object that defines .msgpack() (implicitly defined by M...
Definition streams.hpp:79
static field random_element(numeric::RNG *engine=nullptr) noexcept