@@ -63,20 +63,18 @@ primeorder::impl_mont_field_element!(
6363
6464impl FieldElement {
6565 #[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
66- pub ( crate ) fn from_words_le ( fe : [ u32 ; 8 ] ) -> CtOption < Self > {
66+ pub ( crate ) fn from_words_le ( fe : [ u32 ; 8 ] ) -> Self {
6767 let fe = FieldElement256 :: new_unchecked ( fe) ;
6868
6969 // Convert to montgomery form with aR mod p
7070 let mut mont = FieldElement256 :: default ( ) ;
71- fe. mul ( & R_2_LE , & mut mont) ;
7271
73- let buffer: [ u32 ; 8 ] = mont. data ;
72+ // This mul will check if the result is within the modulus.
73+ fe. mul ( & R_2_LE , & mut mont) ;
7474
75- use crate :: elliptic_curve:: subtle:: ConstantTimeLess as _;
76- let uint = U256 :: from_le_slice ( bytemuck:: cast_slice :: < u32 , u8 > ( & buffer) ) ;
77- let is_within_modulus = uint. ct_lt ( & MODULUS ) ;
75+ let uint = U256 :: from_le_slice ( bytemuck:: cast_slice :: < u32 , u8 > ( & mont. data ) ) ;
7876
79- CtOption :: new ( Self ( uint) , is_within_modulus )
77+ Self ( uint)
8078 }
8179
8280 #[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
@@ -108,7 +106,8 @@ impl FieldElement {
108106 & crate :: __risc0:: SECP256R1_PRIME ,
109107 & mut output,
110108 ) ;
111- FieldElement :: from_words_le ( output)
109+ let element = FieldElement :: from_words_le ( output) ;
110+ return CtOption :: new ( element, Choice :: from ( 1 ) ) ;
112111 }
113112 }
114113
0 commit comments