1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
use core::fmt;
use crate::node_label::NodeLabel;
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Debug)]
pub enum AkdError {
TreeNode(TreeNodeError),
Directory(DirectoryError),
AzksErr(AzksError),
Vrf(VrfError),
Storage(StorageError),
AuditErr(AuditorError),
TestErr(String),
}
impl std::error::Error for AkdError {}
impl From<TreeNodeError> for AkdError {
fn from(error: TreeNodeError) -> Self {
Self::TreeNode(error)
}
}
impl From<StorageError> for AkdError {
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<DirectoryError> for AkdError {
fn from(error: DirectoryError) -> Self {
Self::Directory(error)
}
}
impl From<VrfError> for AkdError {
fn from(error: VrfError) -> Self {
Self::Vrf(error)
}
}
impl From<AzksError> for AkdError {
fn from(error: AzksError) -> Self {
Self::AzksErr(error)
}
}
impl From<AuditorError> for AkdError {
fn from(error: AuditorError) -> Self {
Self::AuditErr(error)
}
}
impl std::fmt::Display for AkdError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
AkdError::TreeNode(err) => {
writeln!(f, "AKD Tree Node Error: {}", err)
}
AkdError::Directory(err) => {
writeln!(f, "AKD Directory Error: {}", err)
}
AkdError::AzksErr(err) => {
writeln!(f, "AKD AZKS Error: {}", err)
}
AkdError::Vrf(err) => {
writeln!(f, "AKD VRF Error: {}", err)
}
AkdError::Storage(err) => {
writeln!(f, "AKD Storage Error: {}", err)
}
AkdError::AuditErr(err) => {
writeln!(f, "AKD Auditor Error {}", err)
}
AkdError::TestErr(err) => {
writeln!(f, "{}", err)
}
}
}
}
#[derive(Debug, Eq, PartialEq)]
pub enum TreeNodeError {
InvalidDirection(usize),
NoDirection(NodeLabel, Option<NodeLabel>),
NoChildAtEpoch(u64, usize),
ParentNextEpochInvalid(u64),
HashUpdateOrderInconsistent,
NonexistentAtEpoch(NodeLabel, u64),
NoStateAtEpoch(NodeLabel, u64),
DigestDeserializationFailed(String),
}
impl std::error::Error for TreeNodeError {}
impl fmt::Display for TreeNodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidDirection(dir) => {
write!(
f,
"AKD is based on a binary tree. No child with a given index: {}",
dir
)
}
Self::NoDirection(node_label, child_label) => {
let mut to_print = format!("no direction provided for the node {:?}", node_label);
if let Some(child_label) = child_label {
let child_str = format!(" and child {:?}", child_label);
to_print.push_str(&child_str);
}
write!(f, "{}", to_print)
}
Self::NoChildAtEpoch(epoch, direction) => {
write!(f, "no node in direction {} at epoch {}", direction, epoch)
}
Self::ParentNextEpochInvalid(epoch) => {
write!(f, "Next epoch of parent is invalid, epoch = {}", epoch)
}
Self::HashUpdateOrderInconsistent => {
write!(
f,
"Hash update in parent only allowed after node is inserted"
)
}
Self::NonexistentAtEpoch(label, epoch) => {
write!(
f,
"This node, labelled {:?}, did not exist at epoch {:?}.",
label, epoch
)
}
Self::NoStateAtEpoch(label, epoch) => {
write!(
f,
"This node, labelled {:?}, did not exist at epoch {:?}.",
label, epoch
)
}
Self::DigestDeserializationFailed(inner_error) => {
write!(f, "Encountered a serialization error {}", inner_error)
}
}
}
}
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Debug)]
pub enum AzksError {
VerifyMembershipProof(String),
VerifyAppendOnlyProof,
NoEpochGiven,
}
impl std::error::Error for AzksError {}
impl fmt::Display for AzksError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::VerifyMembershipProof(error_string) => {
write!(f, "{}", error_string)
}
Self::VerifyAppendOnlyProof => {
write!(f, "Append only proof did not verify!")
}
Self::NoEpochGiven => {
write!(f, "An epoch was required but not supplied")
}
}
}
}
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Debug)]
pub enum DirectoryError {
VerifyLookupProof(String),
VerifyKeyHistoryProof(String),
InvalidEpoch(String),
ReadOnlyDirectory(String),
}
impl std::error::Error for DirectoryError {}
impl fmt::Display for DirectoryError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::VerifyKeyHistoryProof(err_string) => {
write!(f, "Failed to verify key history {}", err_string)
}
Self::InvalidEpoch(err_string) => {
write!(f, "Invalid epoch {}", err_string)
}
Self::VerifyLookupProof(err_string) => {
write!(f, "Failed to verify lookup proof {}", err_string)
}
Self::ReadOnlyDirectory(inner_message) => {
write!(f, "Directory in read-only mode: {}", inner_message)
}
}
}
}
#[cfg_attr(any(test, feature = "public-tests"), derive(PartialEq, Eq))]
#[derive(Debug)]
pub enum StorageError {
NotFound(String),
Transaction(String),
Connection(String),
Other(String),
}
impl std::error::Error for StorageError {}
impl fmt::Display for StorageError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StorageError::Connection(inner) => {
write!(f, "Storage connection: {}", inner)
}
StorageError::Transaction(inner) => {
write!(f, "Transaction: {}", inner)
}
StorageError::NotFound(inner) => {
write!(f, "Data not found: {}", inner)
}
StorageError::Other(inner) => {
write!(f, "Other storage error: {}", inner)
}
}
}
}
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Debug)]
pub enum VrfError {
PublicKey(String),
SigningKey(String),
Verification(String),
}
impl std::error::Error for VrfError {}
impl fmt::Display for VrfError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::SigningKey(error_string) => {
write!(f, "VRF signing key: {}", error_string)
}
Self::PublicKey(error_string) => {
write!(f, "VRF public key: {}", error_string)
}
Self::Verification(error_string) => {
write!(f, "VRF proving or verifying: {}", error_string)
}
}
}
}
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Debug)]
pub enum AuditorError {
VerifyAuditProof(String),
}
impl std::error::Error for AuditorError {}
impl fmt::Display for AuditorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::VerifyAuditProof(err_string) => {
write!(f, "Failed to verify audit {}", err_string)
}
}
}
}