Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
indexed_leaf.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
14
16
19
21
22 NullifierLeafValue() = default;
24 : nullifier(n)
25 {}
26 NullifierLeafValue(const NullifierLeafValue& other) = default;
29 {
30 if (this != &other) {
31 nullifier = other.nullifier;
32 }
33 return *this;
34 }
35
37 {
38 if (this != &other) {
39 nullifier = other.nullifier;
40 }
41 return *this;
42 }
44
45 static bool is_updateable() { return false; }
46
47 bool operator==(NullifierLeafValue const& other) const { return nullifier == other.nullifier; }
48
49 friend std::ostream& operator<<(std::ostream& os, const NullifierLeafValue& v)
50 {
51 os << "nullifier = " << v.nullifier;
52 return os;
53 }
54
55 fr get_key() const { return nullifier; }
56
57 bool is_empty() const { return nullifier.is_zero(); }
58
59 std::vector<fr> get_hash_inputs(fr nextKey, fr nextIndex) const
60 {
61 return std::vector<fr>({ nullifier, nextKey, nextIndex });
62 }
63
64 operator uint256_t() const { return get_key(); }
65
66 static NullifierLeafValue empty() { return { fr::zero() }; }
67
68 static NullifierLeafValue padding(index_t i) { return { i }; }
69
70 static std::string name() { return "NullifierLeafValue"; };
71
72 size_t hash() const noexcept { return std::hash<fr>{}(nullifier); }
73};
74
78
80
82 PublicDataLeafValue(const fr& s, const fr& v)
83 : slot(s)
84 , value(v)
85 {}
89 {
90 if (this != &other) {
91 value = other.value;
92 slot = other.slot;
93 }
94 return *this;
95 }
96
98 {
99 if (this != &other) {
100 value = other.value;
101 slot = other.slot;
102 }
103 return *this;
104 }
106
107 static bool is_updateable() { return true; }
108
109 bool operator==(PublicDataLeafValue const& other) const { return value == other.value && slot == other.slot; }
110
111 friend std::ostream& operator<<(std::ostream& os, const PublicDataLeafValue& v)
112 {
113 os << "slot = " << v.slot << " : value = " << v.value;
114 return os;
115 }
116
117 fr get_key() const { return slot; }
118
119 bool is_empty() const { return slot == fr::zero() && value == fr::zero(); }
120
121 std::vector<fr> get_hash_inputs(fr nextValue, fr nextIndex) const
122 {
123 return std::vector<fr>({ slot, value, nextIndex, nextValue });
124 }
125
126 operator uint256_t() const { return get_key(); }
127
128 static PublicDataLeafValue empty() { return { fr::zero(), fr::zero() }; }
129
130 static PublicDataLeafValue padding(index_t i) { return { i, fr::zero() }; }
131
132 static std::string name() { return "PublicDataLeafValue"; };
133
134 size_t hash() const noexcept { return utils::hash_as_tuple(value, slot); }
135};
136
137template <typename LeafType> struct IndexedLeaf {
138 LeafType leaf;
141
143
144 IndexedLeaf() = default;
145
146 IndexedLeaf(const LeafType& leaf, const index_t& nextIdx, const fr& nextKey)
147 : leaf(leaf)
148 , nextIndex(nextIdx)
150 {}
151
152 IndexedLeaf(const IndexedLeaf<LeafType>& other) = default;
153 IndexedLeaf(IndexedLeaf<LeafType>&& other) noexcept = default;
154 ~IndexedLeaf() = default;
155
156 static bool is_updateable() { return LeafType::is_updateable(); }
157
158 static std::string name() { return LeafType::name(); }
159
160 bool operator==(IndexedLeaf<LeafType> const& other) const
161 {
162 return leaf == other.leaf && nextKey == other.nextKey && nextIndex == other.nextIndex;
163 }
164
166 {
167 if (this != &other) {
168 leaf = other.leaf;
169 nextKey = other.nextKey;
170 nextIndex = other.nextIndex;
171 }
172 return *this;
173 }
174
176 {
177 if (this != &other) {
178 leaf = other.leaf;
179 nextKey = other.nextKey;
180 nextIndex = other.nextIndex;
181 }
182 return *this;
183 }
184
185 friend std::ostream& operator<<(std::ostream& os, const IndexedLeaf<LeafType>& leaf)
186 {
187 os << leaf.leaf << "\nnextIdx = " << leaf.nextIndex << "\nnextKey = " << leaf.nextKey;
188 return os;
189 }
190
191 std::vector<fr> get_hash_inputs() const { return leaf.get_hash_inputs(nextKey, nextIndex); }
192
193 bool is_empty() { return leaf.is_empty(); }
194
195 static IndexedLeaf<LeafType> empty() { return { LeafType::empty(), 0, 0 }; }
196
197 static IndexedLeaf<LeafType> padding(index_t i) { return { LeafType::padding(i), 0, 0 }; }
198};
199
200} // namespace bb::crypto::merkle_tree
#define MSGPACK_FIELDS(...)
Definition msgpack.hpp:118
size_t hash_as_tuple(const Ts &... ts)
Definition utils.hpp:22
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
IndexedLeaf(const IndexedLeaf< LeafType > &other)=default
bool operator==(IndexedLeaf< LeafType > const &other) const
static IndexedLeaf< LeafType > padding(index_t i)
IndexedLeaf< LeafType > & operator=(IndexedLeaf< LeafType > const &other)
static IndexedLeaf< LeafType > empty()
std::vector< fr > get_hash_inputs() const
IndexedLeaf< LeafType > & operator=(IndexedLeaf< LeafType > &&other) noexcept
friend std::ostream & operator<<(std::ostream &os, const IndexedLeaf< LeafType > &leaf)
IndexedLeaf(IndexedLeaf< LeafType > &&other) noexcept=default
std::vector< fr > get_hash_inputs(fr nextKey, fr nextIndex) const
friend std::ostream & operator<<(std::ostream &os, const NullifierLeafValue &v)
NullifierLeafValue & operator=(NullifierLeafValue &&other) noexcept
bool operator==(NullifierLeafValue const &other) const
NullifierLeafValue & operator=(const NullifierLeafValue &other)
NullifierLeafValue(const NullifierLeafValue &other)=default
NullifierLeafValue(NullifierLeafValue &&other)=default
static NullifierLeafValue padding(index_t i)
bool operator==(PublicDataLeafValue const &other) const
PublicDataLeafValue(PublicDataLeafValue &&other)=default
static PublicDataLeafValue padding(index_t i)
friend std::ostream & operator<<(std::ostream &os, const PublicDataLeafValue &v)
PublicDataLeafValue(const PublicDataLeafValue &other)=default
PublicDataLeafValue & operator=(const PublicDataLeafValue &other)
std::vector< fr > get_hash_inputs(fr nextValue, fr nextIndex) const
PublicDataLeafValue & operator=(PublicDataLeafValue &&other) noexcept
BB_INLINE constexpr bool is_zero() const noexcept
static constexpr field zero()