11//! Errors related to proving and verifying proofs. 
22
3+ extern  crate  alloc; 
4+ use  alloc:: vec:: Vec ; 
5+ 
6+ #[ cfg( feature = "std" ) ]  
7+ use  thiserror:: Error ; 
8+ 
39/// Represents an error in proof creation, verification, or parsing. 
4- #[ derive( Fail ,  Clone ,  Debug ,  Eq ,  PartialEq ) ]  
10+ #[ derive( Clone ,  Debug ,  Eq ,  PartialEq ) ]  
11+ #[ cfg_attr( feature = "std" ,  derive( Error ) ) ]  
512pub  enum  ProofError  { 
613    /// This error occurs when a proof failed to verify. 
7-      #[ fail ( display  = "Proof verification failed." ) ]  
14+      #[ cfg_attr ( feature  = "std"  ,  error ( " Proof verification failed.") ) ]  
815    VerificationError , 
916    /// This error occurs when the proof encoding is malformed. 
10-      #[ fail ( display  = "Proof data could not be parsed." ) ]  
17+      #[ cfg_attr ( feature  = "std"  ,  error ( " Proof data could not be parsed.") ) ]  
1118    FormatError , 
1219    /// This error occurs during proving if the number of blinding 
1320     /// factors does not match the number of values. 
14-      #[ fail ( display  = "Wrong number of blinding factors supplied." ) ]  
21+      #[ cfg_attr ( feature  = "std"  ,  error ( " Wrong number of blinding factors supplied.") ) ]  
1522    WrongNumBlindingFactors , 
1623    /// This error occurs when attempting to create a proof with 
1724     /// bitsize other than \\(8\\), \\(16\\), \\(32\\), or \\(64\\). 
18-      #[ fail ( display  = "Invalid bitsize, must have n = 8,16,32,64." ) ]  
25+      #[ cfg_attr ( feature  = "std"  ,  error ( " Invalid bitsize, must have n = 8,16,32,64.") ) ]  
1926    InvalidBitsize , 
2027    /// This error occurs when attempting to create an aggregated 
2128     /// proof with non-power-of-two aggregation size. 
22-      #[ fail( display = "Invalid aggregation size, m must be a power of 2." ) ]  
29+      #[ cfg_attr(  
30+         feature = "std" ,  
31+         error( "Invalid aggregation size, m must be a power of 2." )  
32+     ) ]  
2333    InvalidAggregation , 
2434    /// This error occurs when there are insufficient generators for the proof. 
25-      #[ fail( display = "Invalid generators size, too few generators for proof" ) ]  
35+      #[ cfg_attr(  
36+         feature = "std" ,  
37+         error( "Invalid generators size, too few generators for proof" )  
38+     ) ]  
2639    InvalidGeneratorsLength , 
2740    /// This error results from an internal error during proving. 
2841     /// 
2942     /// The single-party prover is implemented by performing 
3043     /// multiparty computation with ourselves.  However, because the 
3144     /// MPC protocol is not exposed by the single-party API, we 
3245     /// consider its errors to be internal errors. 
33-      #[ fail ( display  = "Internal error during proof creation: {}"  ,  _0 ) ]  
46+      #[ cfg_attr ( feature  = "std"  ,  error ( " Internal error during proof creation: {0}" ) ) ]  
3447    ProvingError ( MPCError ) , 
3548} 
3649
@@ -52,38 +65,48 @@ impl From<MPCError> for ProofError {
5265/// API: although the MPC protocol is used internally for single-party 
5366/// proving, its API should not expose the complexity of the MPC 
5467/// protocol. 
55- #[ derive( Fail ,  Clone ,  Debug ,  Eq ,  PartialEq ) ]  
68+ #[ derive( Clone ,  Debug ,  Eq ,  PartialEq ) ]  
69+ #[ cfg_attr( feature = "std" ,  derive( Error ) ) ]  
5670pub  enum  MPCError  { 
5771    /// This error occurs when the dealer gives a zero challenge, 
5872     /// which would annihilate the blinding factors. 
59-      #[ fail ( display  = "Dealer gave a malicious challenge value." ) ]  
73+      #[ cfg_attr ( feature  = "std"  ,  error ( " Dealer gave a malicious challenge value.") ) ]  
6074    MaliciousDealer , 
6175    /// This error occurs when attempting to create a proof with 
6276     /// bitsize other than \\(8\\), \\(16\\), \\(32\\), or \\(64\\). 
63-      #[ fail ( display  = "Invalid bitsize, must have n = 8,16,32,64" ) ]  
77+      #[ cfg_attr ( feature  = "std"  ,  error ( " Invalid bitsize, must have n = 8,16,32,64") ) ]  
6478    InvalidBitsize , 
6579    /// This error occurs when attempting to create an aggregated 
6680     /// proof with non-power-of-two aggregation size. 
67-      #[ fail( display = "Invalid aggregation size, m must be a power of 2" ) ]  
81+      #[ cfg_attr(  
82+         feature = "std" ,  
83+         error( "Invalid aggregation size, m must be a power of 2" )  
84+     ) ]  
6885    InvalidAggregation , 
6986    /// This error occurs when there are insufficient generators for the proof. 
70-      #[ fail( display = "Invalid generators size, too few generators for proof" ) ]  
87+      #[ cfg_attr(  
88+         feature = "std" ,  
89+         error( "Invalid generators size, too few generators for proof" )  
90+     ) ]  
7191    InvalidGeneratorsLength , 
7292    /// This error occurs when the dealer is given the wrong number of 
7393     /// value commitments. 
74-      #[ fail ( display  = "Wrong number of value commitments" ) ]  
94+      #[ cfg_attr ( feature  = "std"  ,  error ( " Wrong number of value commitments") ) ]  
7595    WrongNumBitCommitments , 
7696    /// This error occurs when the dealer is given the wrong number of 
7797     /// polynomial commitments. 
78-      #[ fail ( display  = "Wrong number of value commitments" ) ]  
98+      #[ cfg_attr ( feature  = "std"  ,  error ( " Wrong number of value commitments") ) ]  
7999    WrongNumPolyCommitments , 
80100    /// This error occurs when the dealer is given the wrong number of 
81101     /// proof shares. 
82-      #[ fail ( display  = "Wrong number of proof shares" ) ]  
102+      #[ cfg_attr ( feature  = "std"  ,  error ( " Wrong number of proof shares") ) ]  
83103    WrongNumProofShares , 
84104    /// This error occurs when one or more parties submit malformed 
85105     /// proof shares. 
86-      #[ fail( display = "Malformed proof shares from parties {:?}" ,  bad_shares) ]  
106+      #[ cfg_attr(  
107+         feature = "std" ,  
108+         error( "Malformed proof shares from parties {bad_shares:?}" )  
109+     ) ]  
87110    MalformedProofShares  { 
88111        /// A vector with the indexes of the parties whose shares were malformed. 
89112         bad_shares :  Vec < usize > , 
@@ -94,27 +117,31 @@ pub enum MPCError {
94117/// 
95118/// XXX: should this be separate from a `ProofError`? 
96119#[ cfg( feature = "yoloproofs" ) ]  
97- #[ derive( Fail ,  Clone ,  Debug ,  Eq ,  PartialEq ) ]  
120+ #[ derive( Clone ,  Debug ,  Eq ,  PartialEq ) ]  
121+ #[ cfg_attr( feature = "std" ,  derive( Error ) ) ]  
98122pub  enum  R1CSError  { 
99123    /// Occurs when there are insufficient generators for the proof. 
100-      #[ fail( display = "Invalid generators size, too few generators for proof" ) ]  
124+      #[ cfg_attr(  
125+         feature = "std" ,  
126+         error( "Invalid generators size, too few generators for proof" )  
127+     ) ]  
101128    InvalidGeneratorsLength , 
102129    /// This error occurs when the proof encoding is malformed. 
103-      #[ fail ( display  = "Proof data could not be parsed." ) ]  
130+      #[ cfg_attr ( feature  = "std"  ,  error ( " Proof data could not be parsed.") ) ]  
104131    FormatError , 
105132    /// Occurs when verification of an 
106133     /// [`R1CSProof`](::r1cs::R1CSProof) fails. 
107-      #[ fail ( display  = "R1CSProof did not verify correctly." ) ]  
134+      #[ cfg_attr ( feature  = "std"  ,  error ( " R1CSProof did not verify correctly.") ) ]  
108135    VerificationError , 
109136
110137    /// Occurs when trying to use a missing variable assignment. 
111138     /// Used by gadgets that build the constraint system to signal that 
112139     /// a variable assignment is not provided when the prover needs it. 
113-      #[ fail ( display  = "Variable does not have a value assignment." ) ]  
140+      #[ cfg_attr ( feature  = "std"  ,  error ( " Variable does not have a value assignment.") ) ]  
114141    MissingAssignment , 
115142
116143    /// Occurs when a gadget receives an inconsistent input. 
117-      #[ fail ( display  = "Gadget error: {:?}" ,  description ) ]  
144+      #[ cfg_attr ( feature  = "std"  ,  error ( " Gadget error: {description :?}") ) ]  
118145    GadgetError  { 
119146        /// The description of the reasons for the error. 
120147         description :  String , 
0 commit comments