Skip to content

Commit f9025ee

Browse files
committed
fix(errors): remove useless not implemented error.
1 parent 64fdba8 commit f9025ee

File tree

5 files changed

+30
-52
lines changed

5 files changed

+30
-52
lines changed

src/errors.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ pub enum ProofError {
1818
/// Indicates a mismatch in parameter sizes during batch verification.
1919
#[error("Mismatched parameter sizes for batch verification.")]
2020
ProofSizeMismatch,
21-
/// Occurs when a feature has not been implemented yet.
22-
#[error("The method is not yet implemented for this struct.")]
23-
NotImplemented(&'static str),
2421
/// Serialization of a group element/scalar has failed.
2522
#[error("Serialization of a group element/scalar failed.")]
2623
GroupSerializationFailure,
27-
/// Other error.
28-
#[error("Other")]
29-
Other,
3024
}

src/proof_composition.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for AndProtocol<G> {
4141
) -> Result<(Self::Commitment, Self::ProverState), ProofError> {
4242
let expected_w_len: usize = self.0.iter().map(|p| p.scalars_nb()).sum();
4343
if expected_w_len != witness.len() || self.is_empty() {
44-
return Err(ProofError::Other);
44+
return Err(ProofError::ProofSizeMismatch);
4545
}
4646

4747
let mut cursor = 0;
@@ -65,7 +65,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for AndProtocol<G> {
6565
challenge: &Self::Challenge,
6666
) -> Result<Self::Response, ProofError> {
6767
if state.len() != self.len() {
68-
return Err(ProofError::Other);
68+
return Err(ProofError::ProofSizeMismatch);
6969
}
7070

7171
let mut response = Vec::with_capacity(self.0.iter().map(|p| p.scalars_nb()).sum());
@@ -85,7 +85,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for AndProtocol<G> {
8585
let expected_c_len: usize = self.0.iter().map(|p| p.statements_nb()).sum();
8686
let expected_r_len: usize = self.0.iter().map(|p| p.scalars_nb()).sum();
8787
if commitment.len() != expected_c_len || response.len() != expected_r_len {
88-
return Err(ProofError::Other);
88+
return Err(ProofError::ProofSizeMismatch);
8989
}
9090

9191
let mut c_cursor = 0;
@@ -114,7 +114,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for AndProtocol<G> {
114114
let expected_c_len: usize = self.0.iter().map(|p| p.statements_nb()).sum();
115115
let expected_r_len: usize = self.0.iter().map(|p| p.scalars_nb()).sum();
116116
if commitment.len() != expected_c_len || response.len() != expected_r_len {
117-
return Err(ProofError::Other);
117+
return Err(ProofError::ProofSizeMismatch);
118118
}
119119

120120
let mut bytes = Vec::new();
@@ -179,7 +179,7 @@ impl<G: Group + GroupEncoding> CompactProtocol for AndProtocol<G> {
179179
) -> Result<Self::Commitment, ProofError> {
180180
let expected_r_len: usize = self.0.iter().map(|p| p.scalars_nb()).sum();
181181
if response.len() != expected_r_len {
182-
return Err(ProofError::Other);
182+
return Err(ProofError::ProofSizeMismatch);
183183
}
184184

185185
let mut commitment = Vec::with_capacity(self.0.iter().map(|p| p.statements_nb()).sum());
@@ -203,7 +203,7 @@ impl<G: Group + GroupEncoding> CompactProtocol for AndProtocol<G> {
203203
let expected_c_len: usize = self.0.iter().map(|p| p.statements_nb()).sum();
204204
let expected_r_len: usize = self.0.iter().map(|p| p.scalars_nb()).sum();
205205
if commitment.len() != expected_c_len || response.len() != expected_r_len {
206-
return Err(ProofError::Other);
206+
return Err(ProofError::ProofSizeMismatch);
207207
}
208208

209209
let mut bytes = Vec::new();
@@ -289,7 +289,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for OrProtocol<G> {
289289
let real_index = witness.0;
290290
let expected_w_len = self.0[real_index].scalars_nb();
291291
if real_index >= self.len() || witness.1.len() != expected_w_len {
292-
return Err(ProofError::Other);
292+
return Err(ProofError::ProofSizeMismatch);
293293
}
294294

295295
let mut fake_transcripts = Vec::with_capacity(self.len() - 1);
@@ -354,7 +354,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for OrProtocol<G> {
354354
|| response.0.len() != expected_ch_nb
355355
|| response.1.len() != expected_r_len
356356
{
357-
return Err(ProofError::Other);
357+
return Err(ProofError::ProofSizeMismatch);
358358
}
359359

360360
let mut expected_difference = *challenge;
@@ -390,7 +390,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for OrProtocol<G> {
390390
|| response.0.len() != expected_ch_nb
391391
|| response.1.len() != expected_r_len
392392
{
393-
return Err(ProofError::Other);
393+
return Err(ProofError::ProofSizeMismatch);
394394
}
395395

396396
let mut bytes = Vec::new();
@@ -465,7 +465,7 @@ impl<G: Group + GroupEncoding> CompactProtocol for OrProtocol<G> {
465465
let expected_ch_nb = self.len();
466466
let expected_r_len: usize = self.0.iter().map(|p| p.scalars_nb()).sum();
467467
if response.0.len() != expected_ch_nb || response.1.len() != expected_r_len {
468-
return Err(ProofError::Other);
468+
return Err(ProofError::ProofSizeMismatch);
469469
}
470470

471471
let mut commitment = Vec::with_capacity(self.0.iter().map(|p| p.statements_nb()).sum());
@@ -493,7 +493,7 @@ impl<G: Group + GroupEncoding> CompactProtocol for OrProtocol<G> {
493493
|| response.0.len() != expected_ch_nb
494494
|| response.1.len() != expected_r_len
495495
{
496-
return Err(ProofError::Other);
496+
return Err(ProofError::ProofSizeMismatch);
497497
}
498498

499499
let mut bytes = Vec::new();

src/schnorr_protocol.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ where
8989
/// - The prover state (random nonces and witness) used to compute the response.
9090
///
9191
/// # Errors
92-
/// -`ProofError::Other` if the witness vector length is incorrect.
92+
/// -`ProofError::ProofSizeMismatch` if the witness vector length is incorrect.
9393
fn prover_commit(
9494
&self,
9595
witness: &Self::Witness,
9696
mut rng: &mut (impl RngCore + CryptoRng),
9797
) -> Result<(Self::Commitment, Self::ProverState), ProofError> {
9898
if witness.len() != self.scalars_nb() {
99-
return Err(ProofError::Other);
99+
return Err(ProofError::ProofSizeMismatch);
100100
}
101101

102102
let nonces: Vec<G::Scalar> = (0..self.scalars_nb())
@@ -117,14 +117,14 @@ where
117117
/// - A vector of scalars forming the prover's response.
118118
///
119119
/// # Errors
120-
/// - Returns `ProofError::Other` if the prover state vectors have incorrect lengths.
120+
/// - Returns `ProofError::ProofSizeMismatch` if the prover state vectors have incorrect lengths.
121121
fn prover_response(
122122
&self,
123123
state: Self::ProverState,
124124
challenge: &Self::Challenge,
125125
) -> Result<Self::Response, ProofError> {
126126
if state.0.len() != self.scalars_nb() || state.1.len() != self.scalars_nb() {
127-
return Err(ProofError::Other);
127+
return Err(ProofError::ProofSizeMismatch);
128128
}
129129

130130
let mut responses = Vec::new();
@@ -143,20 +143,20 @@ where
143143
/// # Returns
144144
/// - `Ok(())` if the proof is valid.
145145
/// - `Err(ProofError::VerificationFailure)` if the proof is invalid.
146-
/// - `Err(ProofError::Other)` if the lengths of commitment or response do not match the expected counts.
146+
/// - `Err(ProofError::ProofSizeMismatch)` if the lengths of commitment or response do not match the expected counts.
147147
///
148148
/// # Errors
149149
/// -`Err(ProofError::VerificationFailure)` if the computed relation
150150
/// does not hold for the provided challenge and response, indicating proof invalidity.
151-
/// -`Err(ProofError::Other)` if the commitment or response length is incorrect.
151+
/// -`Err(ProofError::ProofSizeMismatch)` if the commitment or response length is incorrect.
152152
fn verifier(
153153
&self,
154154
commitment: &Self::Commitment,
155155
challenge: &Self::Challenge,
156156
response: &Self::Response,
157157
) -> Result<(), ProofError> {
158158
if commitment.len() != self.statements_nb() || response.len() != self.scalars_nb() {
159-
return Err(ProofError::Other);
159+
return Err(ProofError::ProofSizeMismatch);
160160
}
161161

162162
let lhs = self.evaluate(response);
@@ -181,7 +181,7 @@ where
181181
/// - A byte vector representing the serialized batchable proof.
182182
///
183183
/// # Errors
184-
/// - `ProofError::Other` if the commitment or response length is incorrect.
184+
/// - `ProofError::ProofSizeMismatch` if the commitment or response length is incorrect.
185185
fn serialize_batchable(
186186
&self,
187187
commitment: &Self::Commitment,
@@ -191,7 +191,7 @@ where
191191
let commit_nb = self.statements_nb();
192192
let response_nb = self.scalars_nb();
193193
if commitment.len() != commit_nb || response.len() != response_nb {
194-
return Err(ProofError::Other);
194+
return Err(ProofError::ProofSizeMismatch);
195195
}
196196

197197
let mut bytes = Vec::new();
@@ -278,14 +278,14 @@ where
278278
/// - A vector of group elements representing the recomputed commitment (one per linear constraint).
279279
///
280280
/// # Errors
281-
/// - `ProofError::Other` if the response length does not match the expected number of scalars.
281+
/// - `ProofError::ProofSizeMismatch` if the response length does not match the expected number of scalars.
282282
fn get_commitment(
283283
&self,
284284
challenge: &Self::Challenge,
285285
response: &Self::Response,
286286
) -> Result<Self::Commitment, ProofError> {
287287
if response.len() != self.scalars_nb() {
288-
return Err(ProofError::Other);
288+
return Err(ProofError::ProofSizeMismatch);
289289
}
290290

291291
let response_image = self.evaluate(response);
@@ -308,7 +308,7 @@ where
308308
/// - A byte vector representing the compact proof.
309309
///
310310
/// # Errors
311-
/// - `ProofError::Other` if the response length does not match the expected number of scalars.
311+
/// - `ProofError::ProofSizeMismatch` if the response length does not match the expected number of scalars.
312312
fn serialize_compact(
313313
&self,
314314
_commitment: &Self::Commitment,
@@ -318,7 +318,7 @@ where
318318
let mut bytes = Vec::new();
319319
let response_nb = self.scalars_nb();
320320
if response.len() != response_nb {
321-
return Err(ProofError::Other);
321+
return Err(ProofError::ProofSizeMismatch);
322322
}
323323

324324
// Serialize challenge

src/traits.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,15 @@ pub trait SigmaProtocol {
6666
_commitment: &Self::Commitment,
6767
_challenge: &Self::Challenge,
6868
_response: &Self::Response,
69-
) -> Result<Vec<u8>, ProofError> {
70-
Err(ProofError::NotImplemented(
71-
"serialize_batchable not implemented for this protocol",
72-
))
73-
}
69+
) -> Result<Vec<u8>, ProofError>;
7470

7571
/// Deserializes a batchable proof from bytes.
7672
///
7773
/// Returns `Some((commitment, response))` if parsing is successful, otherwise `None`.
7874
fn deserialize_batchable(
7975
&self,
8076
_data: &[u8],
81-
) -> Result<(Self::Commitment, Self::Response), ProofError> {
82-
Err(ProofError::NotImplemented(
83-
"deserialize_batchable not implemented for this protocol",
84-
))
85-
}
77+
) -> Result<(Self::Commitment, Self::Response), ProofError>;
8678
}
8779

8880
/// A feature defining the behavior of a protocol for which it is possible to compact the proofs by omitting the commitments.
@@ -109,23 +101,15 @@ pub trait CompactProtocol: SigmaProtocol {
109101
_commitment: &Self::Commitment,
110102
_challenge: &Self::Challenge,
111103
_response: &Self::Response,
112-
) -> Result<Vec<u8>, ProofError> {
113-
Err(ProofError::NotImplemented(
114-
"serialize_compact not implemented for this protocol",
115-
))
116-
}
104+
) -> Result<Vec<u8>, ProofError>;
117105

118106
/// Deserializes a compact proof from bytes.
119107
///
120108
/// Returns `Some((challenge, response))` if parsing is successful, otherwise `None`.
121109
fn deserialize_compact(
122110
&self,
123111
_data: &[u8],
124-
) -> Result<(Self::Challenge, Self::Response), ProofError> {
125-
Err(ProofError::NotImplemented(
126-
"deserialize_compact not implemented for this protocol",
127-
))
128-
}
112+
) -> Result<(Self::Challenge, Self::Response), ProofError>;
129113
}
130114

131115
/// A trait defining the behavior of a Sigma protocol for which simulation of transcripts is necessary.

tests/spec/custom_schnorr_protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
rng: &mut (impl Rng + CryptoRng),
3333
) -> Result<(Self::Commitment, Self::ProverState), ProofError> {
3434
if witness.len() != self.witness_len() {
35-
return Err(ProofError::Other);
35+
return Err(ProofError::ProofSizeMismatch);
3636
}
3737

3838
let mut nonces: Vec<G::Scalar> = Vec::new();
@@ -50,7 +50,7 @@ where
5050
challenge: &Self::Challenge,
5151
) -> Result<Self::Response, ProofError> {
5252
if state.0.len() != self.witness_len() || state.1.len() != self.witness_len() {
53-
return Err(ProofError::Other);
53+
return Err(ProofError::ProofSizeMismatch);
5454
}
5555

5656
let mut responses = Vec::new();

0 commit comments

Comments
 (0)