@@ -365,13 +365,13 @@ where
365
365
366
366
let mut u64_bytes = [ 0u8 ; 8 ] ;
367
367
u64_bytes. copy_from_slice ( & bytes[ hash_size..hash_size + 8 ] ) ;
368
- let nr_leaves = usize :: from_be_bytes ( u64_bytes) ;
368
+ let nr_leaves = u64 :: from_be_bytes ( u64_bytes) ;
369
369
u64_bytes. copy_from_slice ( & bytes[ hash_size + 8 ..hash_size + 16 ] ) ;
370
370
let total_stake = u64:: from_be_bytes ( u64_bytes) ;
371
371
372
372
let mt_commitment = MerkleTreeCommitment :: < D > {
373
373
root,
374
- nr_leaves,
374
+ nr_leaves : nr_leaves as usize ,
375
375
hasher : Default :: default ( ) ,
376
376
} ;
377
377
@@ -385,7 +385,7 @@ where
385
385
pub fn to_bytes ( & self ) -> Vec < u8 > {
386
386
let mut output = Vec :: new ( ) ;
387
387
output. extend_from_slice ( & self . mt_commitment . root ) ;
388
- output. extend_from_slice ( & self . mt_commitment . nr_leaves . to_be_bytes ( ) ) ;
388
+ output. extend_from_slice ( & ( self . mt_commitment . nr_leaves as u64 ) . to_be_bytes ( ) ) ;
389
389
output. extend_from_slice ( & self . total_stake . to_be_bytes ( ) ) ;
390
390
output
391
391
}
@@ -659,7 +659,7 @@ impl StmInitializer {
659
659
let party_id = u64:: from_be_bytes ( u64_bytes) ;
660
660
u64_bytes. copy_from_slice ( & bytes[ 8 ..16 ] ) ;
661
661
let stake = u64:: from_be_bytes ( u64_bytes) ;
662
- let params = StmParameters :: from_bytes ( & bytes[ 16 ..] ) ?;
662
+ let params = StmParameters :: from_bytes ( & bytes[ 16 ..40 ] ) ?;
663
663
let sk = SigningKey :: from_bytes ( & bytes[ 40 ..] ) ?;
664
664
let pk = StmVerificationKeyPoP :: from_bytes ( & bytes[ 72 ..] ) ?;
665
665
@@ -1149,6 +1149,15 @@ mod tests {
1149
1149
proptest ! {
1150
1150
#![ proptest_config( ProptestConfig :: with_cases( 10 ) ) ]
1151
1151
1152
+ #[ test]
1153
+ fn test_parameters_serialize_deserialize( m in any:: <u64 >( ) , k in any:: <u64 >( ) , phi_f in any:: <f64 >( ) ) {
1154
+ let params = StmParameters { m, k, phi_f } ;
1155
+
1156
+ let bytes = params. to_bytes( ) ;
1157
+ let deserialised = StmParameters :: from_bytes( & bytes) ;
1158
+ assert!( deserialised. is_ok( ) )
1159
+ }
1160
+
1152
1161
#[ test]
1153
1162
fn test_initializer_serialize_deserialize( seed in any:: <[ u8 ; 32 ] >( ) ) {
1154
1163
let mut rng = ChaCha20Rng :: from_seed( seed) ;
@@ -1157,6 +1166,9 @@ mod tests {
1157
1166
let stake = rng. next_u64( ) ;
1158
1167
let initializer = StmInitializer :: setup( params, pid, stake, & mut rng) ;
1159
1168
1169
+ let bytes = initializer. to_bytes( ) ;
1170
+ assert!( StmInitializer :: from_bytes( & bytes) . is_ok( ) ) ;
1171
+
1160
1172
let bytes = bincode:: serialize( & initializer) . unwrap( ) ;
1161
1173
assert!( bincode:: deserialize:: <StmInitializer >( & bytes) . is_ok( ) )
1162
1174
}
0 commit comments