@@ -26,7 +26,6 @@ use rand_chacha::{
2626use rayon:: prelude:: * ;
2727#[ cfg( feature = "serde" ) ]
2828use serde:: { Deserialize , Serialize } ;
29- use sp_arithmetic:: traits:: SaturatedConversion ;
3029use static_assertions:: const_assert_eq;
3130
3231use crate :: {
@@ -291,7 +290,8 @@ fn pad_to_chunk<const CHUNK_SIZE: usize>(chunk: DataChunk) -> Vec<u8> {
291290}
292291
293292fn pad_iec_9797_1 ( mut data : Vec < u8 > ) -> Vec < DataChunk > {
294- let padded_size = padded_len_of_pad_iec_9797_1 ( data. len ( ) . saturated_into ( ) ) ;
293+ let data_len = u32:: try_from ( data. len ( ) ) . unwrap_or ( u32:: MAX ) ;
294+ let padded_size = padded_len_of_pad_iec_9797_1 ( data_len) ;
295295 data. resize ( padded_size as usize , 0u8 ) ;
296296
297297 // Transform into `DataChunk`.
@@ -495,7 +495,8 @@ pub fn build_proof<M: Metrics>(
495495 res[ PROOF_SIZE ..] . copy_from_slice ( & point_bytes) ;
496496 } ) ;
497497
498- metrics. proof_build_time ( total_start. elapsed ( ) , cells. len ( ) . saturated_into ( ) ) ;
498+ let cells_len = u32:: try_from ( cells. len ( ) ) . unwrap_or ( u32:: MAX ) ;
499+ metrics. proof_build_time ( total_start. elapsed ( ) , cells_len) ;
499500
500501 if let Ok ( mut errors) = locked_errors. lock ( ) {
501502 if let Some ( error) = errors. pop ( ) {
@@ -522,7 +523,8 @@ pub fn par_build_commitments<const CHUNK_SIZE: usize, M: Metrics>(
522523 let ( tx_layout, block, block_dims) =
523524 flatten_and_pad_block :: < CHUNK_SIZE > ( rows, cols, extrinsics_by_key, rng_seed) ?;
524525
525- metrics. block_dims_and_size ( block_dims, block. len ( ) . saturated_into ( ) ) ;
526+ let block_len = u32:: try_from ( block. len ( ) ) . unwrap_or ( u32:: MAX ) ;
527+ metrics. block_dims_and_size ( block_dims, block_len) ;
526528
527529 let ext_matrix = par_extend_data_matrix ( block_dims, & block, metrics) ?;
528530
@@ -663,6 +665,7 @@ mod tests {
663665 constants:: kate:: { CHUNK_SIZE , COMMITMENT_SIZE , DATA_CHUNK_SIZE } ,
664666 DataLookup ,
665667 } ;
668+ use core:: usize;
666669 use hex_literal:: hex;
667670 use kate_recovery:: {
668671 com:: * ,
@@ -676,7 +679,6 @@ mod tests {
676679 prelude:: * ,
677680 } ;
678681 use rand:: { prelude:: IteratorRandom , Rng , SeedableRng } ;
679- use sp_arithmetic:: Percent ;
680682 use std:: { convert:: TryInto , iter:: repeat} ;
681683 use test_case:: test_case;
682684
@@ -885,15 +887,14 @@ mod tests {
885887 fn random_cells (
886888 max_cols : BlockLengthColumns ,
887889 max_rows : BlockLengthRows ,
888- percents : Percent ,
890+ percents : u8 ,
889891 ) -> Vec < Cell > {
890- let max_cols = max_cols. into ( ) ;
891- let max_rows = max_rows. into ( ) ;
892+ let max_cols: u32 = max_cols. into ( ) ;
893+ let max_rows: u32 = max_rows. into ( ) ;
892894
893895 let rng = & mut ChaChaRng :: from_seed ( [ 0u8 ; 32 ] ) ;
894- let amount: usize = percents
895- . mul_ceil :: < u32 > ( max_cols * max_rows)
896- . saturated_into ( ) ;
896+ let amount = ( percents as u32 * ( max_cols * max_rows) ) . div_ceil ( 100 ) ;
897+ let amount = usize:: try_from ( amount) . unwrap_or ( usize:: MAX ) ;
897898
898899 ( 0 ..max_cols)
899900 . flat_map ( move |col| {
@@ -923,7 +924,7 @@ mod tests {
923924 // let dims_cols = usize::try_from(dims.cols.0).unwrap();
924925 // let public_params = testnet::public_params(dims_cols);
925926 let public_params = couscous:: multiproof_params( ) ;
926- for cell in random_cells( dims. cols, dims. rows, Percent :: one ( ) ) {
927+ for cell in random_cells( dims. cols, dims. rows, 100 ) {
927928 let row = usize :: try_from( cell. row. 0 ) . unwrap( ) ;
928929
929930 let proof = build_proof( & public_params, dims, & matrix, & [ cell] , & metrics) . unwrap( ) ;
@@ -1199,12 +1200,12 @@ Let's see how this gets encoded and then reconstructed by sampling only some dat
11991200 #[ test_case( build_extrinsics( & [ ] ) => padded_len_group( & [ ] , 32 ) ; "Empty chunk list" ) ]
12001201 #[ test_case( build_extrinsics( & [ 4096 ] ) => padded_len_group( & [ 4096 ] , 32 ) ; "4K chunk" ) ]
12011202 fn test_padding_len ( extrinsics : Vec < Vec < u8 > > ) -> u32 {
1202- extrinsics
1203+ let sum = extrinsics
12031204 . into_iter ( )
12041205 . flat_map ( pad_iec_9797_1)
12051206 . map ( |chunk| pad_to_chunk :: < TCHUNK_SIZE > ( chunk) . len ( ) )
1206- . sum :: < usize > ( )
1207- . saturated_into ( )
1207+ . sum :: < usize > ( ) ;
1208+ u32 :: try_from ( sum ) . unwrap_or ( u32 :: MAX )
12081209 }
12091210
12101211 #[ test]
0 commit comments