@@ -63,12 +63,10 @@ primeorder::impl_mont_field_element!(
6363
6464impl FieldElement {
6565 #[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
66- #[ inline( never) ]
6766 pub ( crate ) fn from_words_le ( fe : [ u32 ; 8 ] ) -> CtOption < Self > {
68- // use elliptic_curve::bigint::Encoding;
69- // println!("r2: {:0X?}", fe_from_montgomery(R_2.as_words()));
70-
7167 let fe = FieldElement256 :: new_unchecked ( fe) ;
68+
69+ // Convert to montgomery form with aR mod p
7270 let mut mont = FieldElement256 :: default ( ) ;
7371 fe. mul_unchecked ( & R_2_LE , & mut mont) ;
7472
@@ -81,16 +79,24 @@ impl FieldElement {
8179 CtOption :: new ( Self ( uint) , is_within_modulus)
8280 }
8381
82+ #[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
83+ pub ( crate ) fn to_words_le ( & self ) -> [ u32 ; 8 ] {
84+ use crate :: elliptic_curve:: bigint:: Encoding ;
85+ // NOTE: this from mont conversion could be accelerated, but it's very little cycles.
86+ let canonical = self . to_canonical ( ) ;
87+ let input = canonical. to_le_bytes ( ) ;
88+ let array = bytemuck:: cast :: < _ , [ u32 ; 8 ] > ( input) ;
89+
90+ array
91+ }
92+
8493 /// Returns the multiplicative inverse of self, if self is non-zero.
85- #[ inline( never) ]
8694 pub fn invert ( & self ) -> CtOption < Self > {
8795 #[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
8896 {
8997 use crate :: elliptic_curve:: bigint:: Encoding ;
9098
91- let canonical = self . to_canonical ( ) ;
92- let input = canonical. to_le_bytes ( ) ;
93- let input_words = bytemuck:: cast :: < _ , [ u32 ; 8 ] > ( input) ;
99+ let input_words = self . to_words_le ( ) ;
94100 let mut output = [ 0u32 ; 8 ] ;
95101 risc0_bigint2:: field:: modinv_256_unchecked (
96102 & input_words,
0 commit comments