1use ark_serialize::SerializationError;
4use ark_std::{
5 fmt,
6 string::{String, ToString},
7 vec::Vec,
8};
9
10#[derive(Clone, Eq, PartialEq)]
12pub enum ProofError {
13 VerificationError,
15 FormatError,
17 WrongNumBlindingFactors,
20 InvalidBitsize,
23 InvalidAggregation,
26 InvalidGeneratorsLength,
28 ProvingError(MPCError),
35 SerializationError(String),
37}
38
39impl fmt::Debug for ProofError {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 ProofError::VerificationError => write!(f, "Proof verification failed."),
43 ProofError::FormatError => write!(f, "Proof data could not be parsed."),
44 ProofError::WrongNumBlindingFactors => {
45 write!(f, "Wrong number of blinding factors supplied.")
46 }
47 ProofError::InvalidBitsize => write!(f, "Invalid bitsize, must have n = 8,16,32,64."),
48 ProofError::InvalidAggregation => {
49 write!(f, "Invalid aggregation size, m must be a power of 2.")
50 }
51 ProofError::InvalidGeneratorsLength => {
52 write!(f, "Invalid generators size, too few generators for proof")
53 }
54 ProofError::ProvingError(e) => {
55 write!(f, "Internal error during proof creation: {:?}", e)
56 }
57 ProofError::SerializationError(e) => {
58 write!(f, "Serialization error: {}", e)
59 }
60 }
61 }
62}
63
64impl fmt::Display for ProofError {
65 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66 write!(f, "{:?}", self)
67 }
68}
69
70impl From<MPCError> for ProofError {
71 fn from(e: MPCError) -> ProofError {
72 match e {
73 MPCError::InvalidBitsize => ProofError::InvalidBitsize,
74 MPCError::InvalidAggregation => ProofError::InvalidAggregation,
75 MPCError::InvalidGeneratorsLength => ProofError::InvalidGeneratorsLength,
76 _ => ProofError::ProvingError(e),
77 }
78 }
79}
80
81#[derive(Clone, Eq, PartialEq)]
89pub enum MPCError {
90 MaliciousDealer,
93 InvalidBitsize,
96 InvalidAggregation,
99 InvalidGeneratorsLength,
101 WrongNumBitCommitments,
104 WrongNumPolyCommitments,
107 WrongNumProofShares,
110 MalformedProofShares {
113 bad_shares: Vec<usize>,
115 },
116}
117
118impl fmt::Debug for MPCError {
119 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120 match self {
121 MPCError::MaliciousDealer => write!(f, "Dealer gave a malicious challenge value."),
122 MPCError::InvalidBitsize => write!(f, "Invalid bitsize, must have n = 8,16,32,64"),
123 MPCError::InvalidAggregation => {
124 write!(f, "Invalid aggregation size, m must be a power of 2")
125 }
126 MPCError::InvalidGeneratorsLength => {
127 write!(f, "Invalid generators size, too few generators for proof")
128 }
129 MPCError::WrongNumBitCommitments => write!(f, "Wrong number of value commitments"),
130 MPCError::WrongNumPolyCommitments => write!(f, "Wrong number of value commitments"),
131 MPCError::WrongNumProofShares => write!(f, "Wrong number of proof shares"),
132 MPCError::MalformedProofShares { bad_shares } => {
133 write!(f, "Malformed proof shares from parties {:?}", bad_shares)
134 }
135 }
136 }
137}
138
139impl fmt::Display for MPCError {
140 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
141 write!(f, "{:?}", self)
142 }
143}
144
145#[cfg(feature = "yoloproofs")]
149#[derive(Clone, Eq, PartialEq)]
150pub enum R1CSError {
151 InvalidGeneratorsLength,
153 FormatError,
155 VerificationError,
158 MissingAssignment,
162 GadgetError {
164 description: String,
166 },
167}
168
169impl fmt::Debug for R1CSError {
170 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
171 match self {
172 R1CSError::InvalidGeneratorsLength => {
173 write!(f, "Invalid generators size, too few generators for proof")
174 }
175 R1CSError::FormatError => write!(f, "Proof data could not be parsed."),
176 R1CSError::VerificationError => write!(f, "R1CSProof did not verify correctly."),
177 R1CSError::MissingAssignment => write!(f, "Variable does not have a value assignment."),
178 R1CSError::GadgetError { description } => write!(f, "Gadget error: {}", description),
179 }
180 }
181}
182
183impl fmt::Display for R1CSError {
184 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
185 write!(f, "{:?}", self)
186 }
187}
188
189#[cfg(feature = "yoloproofs")]
190impl From<ProofError> for R1CSError {
191 fn from(e: ProofError) -> R1CSError {
192 match e {
193 ProofError::InvalidGeneratorsLength => R1CSError::InvalidGeneratorsLength,
194 ProofError::FormatError => R1CSError::FormatError,
195 ProofError::VerificationError => R1CSError::VerificationError,
196 _ => panic!("unexpected error type in conversion"),
197 }
198 }
199}
200
201impl From<ark_std::io::Error> for ProofError {
202 fn from(e: ark_std::io::Error) -> ProofError {
203 ProofError::SerializationError(e.to_string())
204 }
205}
206
207impl From<SerializationError> for ProofError {
208 fn from(_: ark_serialize::SerializationError) -> ProofError {
209 ProofError::FormatError
210 }
211}