-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
error.rs
79 lines (70 loc) · 2.91 KB
/
error.rs
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
// Copyright (C) 2019-2021 Aleo Systems Inc.
// This file is part of the snarkVM library.
// The snarkVM library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The snarkVM library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the snarkVM library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ahp::AHPError, marlin::MarlinError, String, ToString};
use core::fmt::{Debug, Display, Formatter};
/// Error handling for Marlin constraints.
pub struct MarlinConstraintsError {
/// Error message.
pub error_msg: String,
}
impl From<MarlinError> for MarlinConstraintsError {
fn from(e: MarlinError) -> Self {
match e {
MarlinError::IndexTooLarge(u, v) => Self {
error_msg: format!("index of {} is too large, maximum degree of {}", v, u),
},
MarlinError::AHPError(err) => match err {
AHPError::ConstraintSystemError(error) => Self {
error_msg: error.to_string(),
},
AHPError::FiatShamirError(error) => Self {
error_msg: error.to_string(),
},
AHPError::InvalidPublicInputLength => Self {
error_msg: String::from("invalid public input length"),
},
AHPError::InstanceDoesNotMatchIndex => Self {
error_msg: String::from("instance does not match index"),
},
AHPError::MissingEval(str) => Self {
error_msg: String::from("missing eval: ") + &*str,
},
AHPError::NonSquareMatrix => Self {
error_msg: String::from("non-sqaure matrix"),
},
},
MarlinError::R1CSError(err) => Self {
error_msg: err.to_string(),
},
MarlinError::FiatShamirError(err) => Self {
error_msg: err.to_string(),
},
MarlinError::PolynomialCommitmentError(err) => Self {
error_msg: err.to_string(),
},
MarlinError::Terminated => Self {
error_msg: "terminated".to_string(),
},
}
}
}
impl Debug for MarlinConstraintsError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.error_msg)
}
}
impl Display for MarlinConstraintsError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.error_msg)
}
}