@@ -70,6 +70,12 @@ impl Tx {
7070
7171 // Read tx size
7272 bytes. read_exact ( & mut u32_buf) ?;
73+ let tx_size = u32:: from_be_bytes ( u32_buf) ;
74+ ensure ! (
75+ tx_size as usize == bytes. len( ) ,
76+ "Invalid tx size, expected: {tx_size}, provided: {0}." ,
77+ bytes. len( )
78+ ) ;
7379
7480 bytes. read_exact ( & mut u8_buf) ?;
7581 ensure ! (
@@ -106,7 +112,7 @@ impl Tx {
106112 bytes. read_exact ( & mut u8_buf) ?;
107113 let proof = VoterProof :: from_bytes ( bytes, u8_buf[ 0 ] . into ( ) )
108114 . map_err ( |e| anyhow ! ( "Invalid voter proof, error: {e}." ) ) ?;
109- bytes = & bytes[ vote . bytes_size ( ) ..] ;
115+ bytes = & bytes[ proof . bytes_size ( ) ..] ;
110116
111117 Vote :: Private ( vote, proof)
112118 } ,
@@ -155,7 +161,7 @@ impl Tx {
155161
156162#[ cfg( test) ]
157163mod tests {
158- use proptest:: prelude:: { any, any_with, Arbitrary , BoxedStrategy , ProptestConfig , Strategy } ;
164+ use proptest:: prelude:: { any, any_with, Arbitrary , BoxedStrategy , Strategy } ;
159165 use test_strategy:: proptest;
160166
161167 use super :: * ;
@@ -201,13 +207,10 @@ mod tests {
201207 }
202208 }
203209
204- #[ proptest( ProptestConfig :: with_cases ( 1 ) ) ]
210+ #[ proptest]
205211 #[ allow( clippy:: indexing_slicing) ]
206212 fn tx_to_bytes_from_bytes_test ( t1 : Tx ) {
207213 let bytes = t1. to_bytes ( ) ;
208- // verify correctness serializing tx size field
209- let size = u32:: from_be_bytes ( bytes[ 0 ..4 ] . try_into ( ) . unwrap ( ) ) ;
210- assert_eq ! ( size as usize , bytes. len( ) - 4 ) ;
211214 let t2 = Tx :: from_bytes ( & bytes) . unwrap ( ) ;
212215 assert_eq ! ( t1, t2) ;
213216 }
0 commit comments