@@ -4,8 +4,9 @@ use crate::{
44} ;
55use allocative:: Allocative ;
66use ark_serialize:: {
7- buffer_byte_size , CanonicalDeserialize , CanonicalDeserializeWithFlags , CanonicalSerialize ,
7+ CanonicalDeserialize , CanonicalDeserializeWithFlags , CanonicalSerialize ,
88 CanonicalSerializeWithFlags , Compress , EmptyFlags , Flags , SerializationError , Valid , Validate ,
9+ buffer_byte_size,
910} ;
1011use ark_std:: {
1112 cmp:: * ,
@@ -98,6 +99,11 @@ pub trait FpConfig<const N: usize>: Send + Sync + 'static + Sized {
9899 /// this range.
99100 fn from_bigint ( other : BigInt < N > ) -> Option < Fp < Self , N > > ;
100101
102+ /// Construct a field element from an integer in the range
103+ /// `0..(Self::MODULUS - 1)`. Returns `None` if the integer is outside
104+ /// this range (but do not do any Reductions)
105+ fn from_bigint_unchecked ( other : BigInt < N > ) -> Option < Fp < Self , N > > ;
106+
101107 /// Convert a field element to an integer in the range `0..(Self::MODULUS -
102108 /// 1)`.
103109 fn into_bigint ( other : Fp < Self , N > ) -> BigInt < N > ;
@@ -371,6 +377,11 @@ impl<P: FpConfig<N>, const N: usize> PrimeField for Fp<P, N> {
371377 P :: into_bigint ( self )
372378 }
373379
380+ #[ inline]
381+ fn from_bigint_unchecked ( r : BigInt < N > ) -> Option < Self > {
382+ P :: from_bigint_unchecked ( r)
383+ }
384+
374385 #[ inline]
375386 fn from_u64 < const NPLUS1 : usize > ( r : u64 ) -> Option < Self > {
376387 P :: from_u64 :: < NPLUS1 > ( r)
@@ -433,11 +444,7 @@ impl<P: FpConfig<N>, const N: usize> From<u128> for Fp<P, N> {
433444impl < P : FpConfig < N > , const N : usize > From < i128 > for Fp < P , N > {
434445 fn from ( other : i128 ) -> Self {
435446 let abs = Self :: from ( other. unsigned_abs ( ) ) ;
436- if other. is_positive ( ) {
437- abs
438- } else {
439- -abs
440- }
447+ if other. is_positive ( ) { abs } else { -abs }
441448 }
442449}
443450
@@ -464,11 +471,7 @@ impl<P: FpConfig<N>, const N: usize> From<u64> for Fp<P, N> {
464471impl < P : FpConfig < N > , const N : usize > From < i64 > for Fp < P , N > {
465472 fn from ( other : i64 ) -> Self {
466473 let abs = Self :: from ( other. unsigned_abs ( ) ) ;
467- if other. is_positive ( ) {
468- abs
469- } else {
470- -abs
471- }
474+ if other. is_positive ( ) { abs } else { -abs }
472475 }
473476}
474477
@@ -485,11 +488,7 @@ impl<P: FpConfig<N>, const N: usize> From<u32> for Fp<P, N> {
485488impl < P : FpConfig < N > , const N : usize > From < i32 > for Fp < P , N > {
486489 fn from ( other : i32 ) -> Self {
487490 let abs = Self :: from ( other. unsigned_abs ( ) ) ;
488- if other. is_positive ( ) {
489- abs
490- } else {
491- -abs
492- }
491+ if other. is_positive ( ) { abs } else { -abs }
493492 }
494493}
495494
@@ -506,11 +505,7 @@ impl<P: FpConfig<N>, const N: usize> From<u16> for Fp<P, N> {
506505impl < P : FpConfig < N > , const N : usize > From < i16 > for Fp < P , N > {
507506 fn from ( other : i16 ) -> Self {
508507 let abs = Self :: from ( other. unsigned_abs ( ) ) ;
509- if other. is_positive ( ) {
510- abs
511- } else {
512- -abs
513- }
508+ if other. is_positive ( ) { abs } else { -abs }
514509 }
515510}
516511
@@ -527,11 +522,7 @@ impl<P: FpConfig<N>, const N: usize> From<u8> for Fp<P, N> {
527522impl < P : FpConfig < N > , const N : usize > From < i8 > for Fp < P , N > {
528523 fn from ( other : i8 ) -> Self {
529524 let abs = Self :: from ( other. unsigned_abs ( ) ) ;
530- if other. is_positive ( ) {
531- abs
532- } else {
533- -abs
534- }
525+ if other. is_positive ( ) { abs } else { -abs }
535526 }
536527}
537528
@@ -554,7 +545,7 @@ impl<P: FpConfig<N>, const N: usize> ark_std::rand::distributions::Distribution<
554545 u64:: MAX >> shave_bits
555546 } ;
556547
557- if let Some ( val) = tmp. 0 . 0 . last_mut ( ) {
548+ if let Some ( val) = tmp. 0 . 0 . last_mut ( ) {
558549 * val &= mask
559550 }
560551
0 commit comments