@@ -9,7 +9,7 @@ use derive_more::{Deref, From, IntoIterator};
9
9
use rayon:: prelude:: * ;
10
10
use serde:: { Deserialize , Serialize } ;
11
11
use serde_with:: serde_as;
12
- use std:: { iter:: successors, num:: NonZeroU32 } ;
12
+ use std:: { iter:: successors, num:: NonZeroUsize } ;
13
13
14
14
use crate :: {
15
15
interpolation:: { interpolate, interpolate_in_exponent} ,
@@ -23,22 +23,22 @@ pub struct FeldmanVss<C: CurveGroup>(PhantomData<C>);
23
23
#[ derive( Debug , Clone , Copy ) ]
24
24
pub struct FeldmanVssPublicParam {
25
25
// reconstruction threshold t
26
- pub t : NonZeroU32 ,
26
+ pub t : NonZeroUsize ,
27
27
// total number of nodes
28
- pub n : NonZeroU32 ,
28
+ pub n : NonZeroUsize ,
29
29
}
30
30
31
31
impl FeldmanVssPublicParam {
32
- pub fn new ( t : NonZeroU32 , n : NonZeroU32 ) -> Self {
32
+ pub fn new ( t : NonZeroUsize , n : NonZeroUsize ) -> Self {
33
33
Self { t, n }
34
34
}
35
35
36
36
pub fn threshold ( & self ) -> usize {
37
- self . t . get ( ) as usize
37
+ self . t . get ( )
38
38
}
39
39
40
40
pub fn num_nodes ( & self ) -> usize {
41
- self . n . get ( ) as usize
41
+ self . n . get ( )
42
42
}
43
43
}
44
44
@@ -51,7 +51,7 @@ impl<C: CurveGroup> FeldmanVss<C> {
51
51
) -> ( DensePolynomial < C :: ScalarField > , FeldmanCommitment < C > ) {
52
52
// sample random polynomial of degree t-1 (s.t. any t evaluations can interpolate this poly)
53
53
// f(X) = Sum a_i * X^i
54
- let mut poly = DensePolynomial :: < C :: ScalarField > :: rand ( pp. t . get ( ) as usize - 1 , rng) ;
54
+ let mut poly = DensePolynomial :: < C :: ScalarField > :: rand ( pp. t . get ( ) - 1 , rng) ;
55
55
// f(0) = a_0 set to the secret, this index access will never panic since t>0
56
56
poly. coeffs [ 0 ] = secret;
57
57
@@ -67,7 +67,7 @@ impl<C: CurveGroup> FeldmanVss<C> {
67
67
pp : & FeldmanVssPublicParam ,
68
68
poly : & DensePolynomial < C :: ScalarField > ,
69
69
) -> impl Iterator < Item = C :: ScalarField > {
70
- ( 0 ..pp. n . get ( ) ) . map ( |node_idx| poly. evaluate ( & ( node_idx + 1 ) . into ( ) ) )
70
+ ( 0 ..pp. n . get ( ) ) . map ( |node_idx| poly. evaluate ( & ( ( node_idx + 1 ) as u64 ) . into ( ) ) )
71
71
}
72
72
73
73
/// same as [`Self::compute_shares()`], but output an iterator of bytes
@@ -86,8 +86,8 @@ impl<C: CurveGroup> FeldmanVss<C> {
86
86
node_idx : usize ,
87
87
commitment : & [ C :: Affine ] ,
88
88
) -> Result < C , VssError > {
89
- let n = pp. n . get ( ) as usize ;
90
- let t = pp. t . get ( ) as usize ;
89
+ let n = pp. n . get ( ) ;
90
+ let t = pp. t . get ( ) ;
91
91
92
92
// input validation
93
93
if node_idx >= n {
@@ -155,8 +155,8 @@ impl<C: CurveGroup> VerifiableSecretSharing for FeldmanVss<C> {
155
155
shares : impl Iterator < Item = ( usize , Self :: SecretShare ) > ,
156
156
) -> Result < Self :: Secret , VssError > {
157
157
let shares = shares. collect :: < Vec < _ > > ( ) ;
158
- let n = pp. n . get ( ) as usize ;
159
- let t = pp. t . get ( ) as usize ;
158
+ let n = pp. n . get ( ) ;
159
+ let t = pp. t . get ( ) ;
160
160
// input validation
161
161
if shares. len ( ) != t {
162
162
return Err ( VssError :: MismatchedSharesCount ( t, shares. len ( ) ) ) ;
@@ -316,8 +316,8 @@ mod tests {
316
316
let n_usize = n as usize ;
317
317
let t_usize = t as usize ;
318
318
319
- let n = NonZeroU32 :: new ( n) . unwrap ( ) ;
320
- let t = NonZeroU32 :: new ( t) . unwrap ( ) ;
319
+ let n = NonZeroUsize :: new ( n as usize ) . unwrap ( ) ;
320
+ let t = NonZeroUsize :: new ( t as usize ) . unwrap ( ) ;
321
321
let pp = FeldmanVssPublicParam :: new ( t, n) ;
322
322
323
323
let ( shares, commitment) = FeldmanVss :: < C > :: share ( & pp, rng, secret) ;
0 commit comments