11use  ark_ff:: { self ,  BigInteger ,  BigInteger256 ,  One ,  Zero } ; 
22use  itertools:: unfold; 
3- use  num:: { rational:: Ratio ,  BigInt ,  FromPrimitive ,  Signed } ; 
3+ use  num_bigint_generic:: { BigInt ,  Sign } ; 
4+ use  num_rational_generic:: Ratio ; 
5+ use  num_traits:: { FromPrimitive ,  Signed } ; 
46
57use  crate :: { BigInt2048 ,  BigInt256 ,  BigInt4096 ,  BigRational2048 ,  BigRational4096 } ; 
68
@@ -20,7 +22,10 @@ impl Threshold {
2022        // 1. set up parameters to calculate threshold 
2123        // Note: IMO all these parameters can be represented as constants. They do not change. The calculation is most likely in the 
2224        //       code to adjust them in the future. We could create an utility that generates these params using f and log terms 
23-         let  f = BigRational2048 :: new ( BigInt :: from_u8 ( 3 ) . unwrap ( ) ,  BigInt :: from_u8 ( 4 ) . unwrap ( ) ) ; 
25+         let  f = BigRational2048 :: new ( 
26+             BigInt2048 :: from_u8 ( 3 ) . unwrap ( ) , 
27+             BigInt2048 :: from_u8 ( 4 ) . unwrap ( ) , 
28+         ) ; 
2429
2530        let  base = BigRational2048 :: one ( )  - f; 
2631
@@ -29,15 +34,15 @@ impl Threshold {
2934        let  ( per_term_precission,  terms_needed,  _)  = Self :: bit_params ( & abs_log_base) ; 
3035
3136        let  terms_needed:  i32  = terms_needed. try_into ( ) . unwrap ( ) ; 
32-         let  mut  linear_term_integer_part = BigInt :: zero ( ) ; 
37+         let  mut  linear_term_integer_part = BigInt4096 :: zero ( ) ; 
3338
3439        let  abs_log_base:  BigRational4096  = abs_log_base. to_nlimbs :: < 64 > ( ) ; 
3540
3641        let  coefficients = ( 1 ..terms_needed) . map ( |x| { 
3742            let  c = abs_log_base. pow ( x)  / Self :: factorial ( x. into ( ) ) ; 
3843            let  c_frac = if  x == 1  { 
39-                 let  c_whole = c. to_integer ( ) ; 
40-                 let  c_frac = c - bigint_to_bigrational ( & c_whole) ; 
44+                 let  c_whole:   BigInt4096  = c. to_integer ( ) ; 
45+                 let  c_frac = c - bigint_to_bigrational :: < 64 > ( & c_whole) ; 
4146                linear_term_integer_part = c_whole; 
4247                c_frac
4348            }  else  { 
@@ -62,7 +67,7 @@ impl Threshold {
6267        let  input =
6368            BigRational4096 :: new ( numer. to_nlimbs ( ) ,  two_tpo_per_term_precission. to_nlimbs ( ) ) ; 
6469
65-         let  denom = BigInt :: one ( )  << per_term_precission; 
70+         let  denom = BigInt2048 :: one ( )  << per_term_precission; 
6671
6772        let  ( res,  _)  = coefficients. into_iter ( ) . fold ( 
6873            ( BigRational4096 :: zero ( ) ,  BigRational4096 :: one ( ) ) , 
@@ -90,8 +95,8 @@ impl Threshold {
9095    } 
9196
9297    fn  terms_needed ( log_base :  & BigRational2048 ,  bits_of_precission :  u32 )  -> i32  { 
93-         let  two  = BigInt4096 :: one ( )  + BigInt :: one ( ) ; 
94-         let  lower_bound = bigint_to_bigrational ( & two. pow ( bits_of_precission) ) ; 
98+         let  two:   BigInt4096   = BigInt4096 :: one ( )  + BigInt4096 :: one ( ) ; 
99+         let  lower_bound:   BigRational4096  = bigint_to_bigrational ( & two. pow ( bits_of_precission) ) ; 
95100
96101        let  mut  n = 0 ; 
97102        let  log_base:  BigRational4096  = log_base. to_nlimbs ( ) ; 
@@ -190,7 +195,7 @@ pub fn get_fractional(vrf_out: BigInteger256) -> Ratio<BigInt2048> {
190195    //                 Field.size_in_bits = 255 
191196    let  two_tpo_256 = BigInt2048 :: one ( )  << 253u32 ; 
192197
193-     let  vrf_out = BigInt2048 :: from_bytes_be ( num :: bigint :: Sign :: Plus ,  & vrf_out. to_bytes_be ( ) ) ; 
198+     let  vrf_out = BigInt2048 :: from_bytes_be ( Sign :: Plus ,  & vrf_out. to_bytes_be ( ) ) ; 
194199
195200    Ratio :: new ( vrf_out,  two_tpo_256) 
196201} 
0 commit comments