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];
29
29
30
30
// Generate a batch of witnesses, statements, and transcripts
31
31
#[ allow( non_snake_case) ]
32
+ #[ allow( clippy:: arithmetic_side_effects) ]
32
33
fn generate_data < R : CryptoRngCore > (
33
34
params : & Arc < Parameters > ,
34
35
b : usize ,
@@ -166,7 +167,7 @@ fn verify_proof(c: &mut Criterion) {
166
167
|| transcripts[ 0 ] . clone ( ) ,
167
168
|t| {
168
169
// Verify the proof
169
- assert ! ( proof. verify( & statements[ 0 ] , t) ) ;
170
+ assert ! ( proof. verify( & statements[ 0 ] , t) . is_ok ( ) ) ;
170
171
} ,
171
172
BatchSize :: SmallInput ,
172
173
)
@@ -209,7 +210,7 @@ fn verify_batch_proof(c: &mut Criterion) {
209
210
|| transcripts. clone ( ) ,
210
211
|t| {
211
212
// Verify the proofs in a batch
212
- assert ! ( Proof :: verify_batch( & statements, & proofs, t) ) ;
213
+ assert ! ( Proof :: verify_batch( & statements, & proofs, t) . is_ok ( ) ) ;
213
214
} ,
214
215
BatchSize :: SmallInput ,
215
216
)
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 = [
43
43
' clippy::cast_possible_truncation' ,
44
44
' clippy::cast_possible_wrap' ,
45
45
' clippy::cast_precision-loss' ,
46
- ' clippy::cast_sign_loss'
46
+ ' clippy::cast_sign_loss' ,
47
+
48
+ # Mathematical mistakes
49
+ ' clippy::arithmetic_side_effects' ,
47
50
]
48
51
49
52
warn = [
Original file line number Diff line number Diff line change @@ -54,17 +54,18 @@ impl GrayIterator {
54
54
// Get a base-`N` decomposition
55
55
let mut base_N = Vec :: with_capacity ( M as usize ) ;
56
56
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 ) ?;
59
60
}
60
61
61
62
// Now get the Gray decomposition from the base-`N` decomposition
62
63
let mut shift = 0 ;
63
64
let mut digits = vec ! [ 0 ; M as usize ] ;
64
65
65
66
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 ] ) ? ;
68
69
}
69
70
70
71
Some ( digits)
@@ -128,7 +129,7 @@ impl Iterator for GrayIterator {
128
129
#[ allow( non_snake_case) ]
129
130
fn next ( & mut self ) -> Option < Self :: Item > {
130
131
if self . i == 0 {
131
- self . i + = 1 ;
132
+ self . i = 1 ;
132
133
return Some ( ( 0 , 0 , 0 ) ) ;
133
134
}
134
135
@@ -150,7 +151,7 @@ impl Iterator for GrayIterator {
150
151
let new = next[ index] ;
151
152
152
153
// Update the state
153
- self . i += 1 ;
154
+ self . i = self . i . checked_add ( 1 ) ? ;
154
155
self . last = next;
155
156
156
157
Some ( ( index, old, new) )
Original file line number Diff line number Diff line change 103
103
//! let proof = Proof::prove(&witness, &statement, &mut transcript.clone()).unwrap();
104
104
//!
105
105
//! // 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() );
107
107
//! # }
108
108
//! ```
109
109
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ impl Parameters {
100
100
hasher. update ( & m. to_le_bytes ( ) ) ;
101
101
let mut hasher_xof = hasher. finalize_xof ( ) ;
102
102
let mut CommitmentG_bytes = [ 0u8 ; 64 ] ;
103
- let CommitmentG = ( 0 ..n * m )
103
+ let CommitmentG = ( 0 ..n. checked_mul ( m ) . ok_or ( ParameterError :: InvalidParameter ) ? )
104
104
. map ( |_| {
105
105
hasher_xof. fill ( & mut CommitmentG_bytes ) ;
106
106
RistrettoPoint :: from_uniform_bytes ( & CommitmentG_bytes )
You can’t perform that action at this time.
0 commit comments