File tree Expand file tree Collapse file tree 8 files changed +79
-73
lines changed Expand file tree Collapse file tree 8 files changed +79
-73
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ const BATCH_SIZES: [usize; 1] = [2];
2929
3030// Generate a batch of witnesses, statements, and transcripts
3131#[ allow( non_snake_case) ]
32+ #[ allow( clippy:: arithmetic_side_effects) ]
3233fn generate_data < R : CryptoRngCore > (
3334 params : & Arc < Parameters > ,
3435 b : usize ,
@@ -166,7 +167,7 @@ fn verify_proof(c: &mut Criterion) {
166167 || transcripts[ 0 ] . clone ( ) ,
167168 |t| {
168169 // Verify the proof
169- assert ! ( proof. verify( & statements[ 0 ] , t) ) ;
170+ assert ! ( proof. verify( & statements[ 0 ] , t) . is_ok ( ) ) ;
170171 } ,
171172 BatchSize :: SmallInput ,
172173 )
@@ -209,7 +210,7 @@ fn verify_batch_proof(c: &mut Criterion) {
209210 || transcripts. clone ( ) ,
210211 |t| {
211212 // Verify the proofs in a batch
212- assert ! ( Proof :: verify_batch( & statements, & proofs, t) ) ;
213+ assert ! ( Proof :: verify_batch( & statements, & proofs, t) . is_ok ( ) ) ;
213214 } ,
214215 BatchSize :: SmallInput ,
215216 )
Original file line number Diff line number Diff line change 1+ arithmetic-side-effects-allowed = [ " curve25519_dalek::Scalar" , " curve25519_dalek::RistrettoPoint" ]
Original file line number Diff line number Diff line change @@ -43,7 +43,10 @@ deny = [
4343 ' clippy::cast_possible_truncation' ,
4444 ' clippy::cast_possible_wrap' ,
4545 ' clippy::cast_precision-loss' ,
46- ' clippy::cast_sign_loss'
46+ ' clippy::cast_sign_loss' ,
47+
48+ # Mathematical mistakes
49+ ' clippy::arithmetic_side_effects' ,
4750]
4851
4952warn = [
Original file line number Diff line number Diff line change @@ -54,17 +54,18 @@ impl GrayIterator {
5454 // Get a base-`N` decomposition
5555 let mut base_N = Vec :: with_capacity ( M as usize ) ;
5656 for _ in 0 ..M {
57- base_N. push ( v % N ) ;
58- v /= N ;
57+ // These are always defined since `N > 0`
58+ base_N. push ( v. checked_rem ( N ) ?) ;
59+ v = v. checked_div ( N ) ?;
5960 }
6061
6162 // Now get the Gray decomposition from the base-`N` decomposition
6263 let mut shift = 0 ;
6364 let mut digits = vec ! [ 0 ; M as usize ] ;
6465
6566 for i in ( 0 ..M ) . rev ( ) {
66- digits[ i as usize ] = ( base_N[ i as usize ] + shift) % N ;
67- shift = shift + N - digits[ i as usize ] ;
67+ digits[ i as usize ] = ( base_N[ i as usize ] . checked_add ( shift) ? ) . checked_rem ( N ) ? ;
68+ shift = shift. checked_add ( N ) ? . checked_sub ( digits[ i as usize ] ) ? ;
6869 }
6970
7071 Some ( digits)
@@ -128,7 +129,7 @@ impl Iterator for GrayIterator {
128129 #[ allow( non_snake_case) ]
129130 fn next ( & mut self ) -> Option < Self :: Item > {
130131 if self . i == 0 {
131- self . i + = 1 ;
132+ self . i = 1 ;
132133 return Some ( ( 0 , 0 , 0 ) ) ;
133134 }
134135
@@ -150,7 +151,7 @@ impl Iterator for GrayIterator {
150151 let new = next[ index] ;
151152
152153 // Update the state
153- self . i += 1 ;
154+ self . i = self . i . checked_add ( 1 ) ? ;
154155 self . last = next;
155156
156157 Some ( ( index, old, new) )
Original file line number Diff line number Diff line change 103103//! let proof = Proof::prove(&witness, &statement, &mut transcript.clone()).unwrap();
104104//!
105105//! // The proof should verify against the same statement and transcript
106- //! assert!(proof.verify(&statement, &mut transcript));
106+ //! assert!(proof.verify(&statement, &mut transcript).is_ok() );
107107//! # }
108108//! ```
109109
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ impl Parameters {
100100 hasher. update ( & m. to_le_bytes ( ) ) ;
101101 let mut hasher_xof = hasher. finalize_xof ( ) ;
102102 let mut CommitmentG_bytes = [ 0u8 ; 64 ] ;
103- let CommitmentG = ( 0 ..n * m )
103+ let CommitmentG = ( 0 ..n. checked_mul ( m ) . ok_or ( ParameterError :: InvalidParameter ) ? )
104104 . map ( |_| {
105105 hasher_xof. fill ( & mut CommitmentG_bytes ) ;
106106 RistrettoPoint :: from_uniform_bytes ( & CommitmentG_bytes )
You can’t perform that action at this time.
0 commit comments