File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed
fastcrypto/src/groups/bn254 Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -63,21 +63,18 @@ impl groups::Scalar for Scalar {
6363
6464impl ToFromByteArray < SCALAR_LENGTH > for Scalar {
6565 fn from_byte_array ( bytes : & [ u8 ; SCALAR_LENGTH ] ) -> Result < Self , FastCryptoError > {
66- // Arkworks uses little-endian byte order for serialization, but we use big-endian.
67- let mut reversed = * bytes;
68- reversed. reverse ( ) ;
69- Fr :: deserialize_compressed ( reversed. as_slice ( ) )
66+ // Note that arkworks uses little-endian byte order for serialization here.
67+ Fr :: deserialize_compressed ( bytes. as_slice ( ) )
7068 . map_err ( |_| FastCryptoError :: InvalidInput )
7169 . map ( Scalar )
7270 }
7371
7472 fn to_byte_array ( & self ) -> [ u8 ; SCALAR_LENGTH ] {
73+ // Note that arkworks uses little-endian byte order for serialization here.
7574 let mut bytes = [ 0u8 ; SCALAR_LENGTH ] ;
7675 self . 0
7776 . serialize_compressed ( bytes. as_mut_slice ( ) )
7877 . expect ( "Never fails" ) ;
79- // Arkworks uses little-endian byte order for serialization, but we use big-endian.
80- bytes. reverse ( ) ;
8178 bytes
8279 }
8380}
Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ fn test_serde_and_regression() {
184184 verify_serialization (
185185 & s1,
186186 Some (
187- hex:: decode ( "0000000000000000000000000000000000000000000000000000000000000001 " )
187+ hex:: decode ( "0100000000000000000000000000000000000000000000000000000000000000 " )
188188 . unwrap ( )
189189 . as_slice ( ) ,
190190 ) ,
@@ -225,13 +225,15 @@ fn test_serialization_scalar() {
225225 assert_eq ! ( Scalar :: from_byte_array( & bytes) . unwrap( ) , Scalar :: zero( ) ) ;
226226
227227 // Scalar::from_byte_array should not accept the order or above it.
228- let order =
228+ let mut order =
229229 hex:: decode ( "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001" ) . unwrap ( ) ;
230+ order. reverse ( ) ; // Little-endian
230231 assert ! ( Scalar :: from_byte_array( <& [ u8 ; 32 ] >:: try_from( order. as_slice( ) ) . unwrap( ) ) . is_err( ) ) ;
231232
232233 // Scalar::from_byte_array should accept the order - 1.
233- let order_minus_one =
234+ let mut order_minus_one =
234235 hex:: decode ( "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000" ) . unwrap ( ) ;
236+ order_minus_one. reverse ( ) ; // Little-endian
235237 assert_eq ! (
236238 Scalar :: from_byte_array( <& [ u8 ; 32 ] >:: try_from( order_minus_one. as_slice( ) ) . unwrap( ) )
237239 . unwrap( ) ,
You can’t perform that action at this time.
0 commit comments