@@ -42,7 +42,7 @@ pub fn poly_sub(a: PolyCoeff, b: PolyCoeff) -> PolyCoeff {
42
42
/// Given a polynomial `f(x)` and a scalar `z`. This method will compute
43
43
/// the result of `f(z)` and return the result.
44
44
pub fn poly_eval ( poly : & PolyCoeff , value : & Scalar ) -> Scalar {
45
- let mut result = Scalar :: from ( 0u64 ) ;
45
+ let mut result = Scalar :: ZERO ;
46
46
for coeff in poly. iter ( ) . rev ( ) {
47
47
result = result * value + coeff;
48
48
}
@@ -66,9 +66,9 @@ pub fn poly_mul(a: PolyCoeff, b: PolyCoeff) -> PolyCoeff {
66
66
///
67
67
/// Example: vanishing_poly([1, 2, 3]) = (x - 1)(x - 2)(x - 3)
68
68
pub fn vanishing_poly ( roots : & [ Scalar ] ) -> PolyCoeff {
69
- let mut poly = vec ! [ Scalar :: from ( 1u64 ) ] ;
69
+ let mut poly = vec ! [ Scalar :: ONE ] ;
70
70
for root in roots {
71
- poly = poly_mul ( poly, vec ! [ -root, Scalar :: from ( 1u64 ) ] ) ;
71
+ poly = poly_mul ( poly, vec ! [ -root, Scalar :: ONE ] ) ;
72
72
}
73
73
poly
74
74
}
@@ -89,13 +89,13 @@ pub fn lagrange_interpolate(points: &[(Scalar, Scalar)]) -> Option<Vec<Scalar>>
89
89
max_degree_plus_one >= 2 ,
90
90
"should interpolate for degree >= 1"
91
91
) ;
92
- let mut coeffs = vec ! [ Scalar :: from ( 0u64 ) ; max_degree_plus_one] ;
92
+ let mut coeffs = vec ! [ Scalar :: ZERO ; max_degree_plus_one] ;
93
93
// external iterator
94
94
for ( k, p_k) in points. iter ( ) . enumerate ( ) {
95
95
let ( x_k, y_k) = p_k;
96
96
// coeffs from 0 to max_degree - 1
97
- let mut contribution = vec ! [ Scalar :: from ( 0u64 ) ; max_degree_plus_one] ;
98
- let mut denominator = Scalar :: from ( 1u64 ) ;
97
+ let mut contribution = vec ! [ Scalar :: ZERO ; max_degree_plus_one] ;
98
+ let mut denominator = Scalar :: ONE ;
99
99
let mut max_contribution_degree = 0 ;
100
100
// internal iterator
101
101
for ( j, p_j) in points. iter ( ) . enumerate ( ) {
@@ -127,7 +127,7 @@ pub fn lagrange_interpolate(points: &[(Scalar, Scalar)]) -> Option<Vec<Scalar>>
127
127
} )
128
128
. collect ( ) ;
129
129
130
- contribution. insert ( 0 , Scalar :: from ( 0u64 ) ) ;
130
+ contribution. insert ( 0 , Scalar :: ZERO ) ;
131
131
contribution. truncate ( max_degree_plus_one) ;
132
132
133
133
assert_eq ! ( mul_by_minus_x_j. len( ) , max_degree_plus_one) ;
@@ -161,7 +161,7 @@ mod tests {
161
161
use bls12_381:: ff:: Field ;
162
162
163
163
fn naive_poly_eval ( poly : & PolyCoeff , value : & Scalar ) -> Scalar {
164
- let mut result = Scalar :: from ( 0u64 ) ;
164
+ let mut result = Scalar :: ZERO ;
165
165
for ( i, coeff) in poly. iter ( ) . enumerate ( ) {
166
166
result += coeff * value. pow_vartime ( & [ i as u64 ] ) ;
167
167
}
@@ -241,7 +241,7 @@ mod tests {
241
241
242
242
// Check that this polynomial evaluates to zero on the roots
243
243
for root in roots. iter ( ) {
244
- assert_eq ! ( poly_eval( & poly, & root) , Scalar :: from ( 0u64 ) ) ;
244
+ assert_eq ! ( poly_eval( & poly, & root) , Scalar :: ZERO ) ;
245
245
}
246
246
}
247
247
0 commit comments