@@ -344,8 +344,8 @@ impl RawEigenClient {
344
344
is_retriable : false ,
345
345
} ) ;
346
346
}
347
- //TODO: remove zkgpad_rs
348
- let data = kzgpad_rs :: remove_empty_byte_from_padded_bytes ( & get_response. data ) ;
347
+
348
+ let data = remove_empty_byte_from_padded_bytes ( & get_response. data ) ;
349
349
Ok ( Some ( data) )
350
350
}
351
351
}
@@ -383,3 +383,56 @@ fn convert_by_padding_empty_byte(data: &[u8]) -> Vec<u8> {
383
383
valid_data. truncate ( valid_end) ;
384
384
valid_data
385
385
}
386
+
387
+ #[ cfg( test) ]
388
+ fn remove_empty_byte_from_padded_bytes ( data : & [ u8 ] ) -> Vec < u8 > {
389
+ let parse_size = DATA_CHUNK_SIZE ;
390
+
391
+ // Calculate the number of chunks
392
+ let data_len = ( data. len ( ) + parse_size - 1 ) / parse_size;
393
+
394
+ // Pre-allocate `valid_data` with enough space for all chunks
395
+ let mut valid_data = vec ! [ 0u8 ; data_len * ( DATA_CHUNK_SIZE - 1 ) ] ;
396
+ let mut valid_end = data_len * ( DATA_CHUNK_SIZE - 1 ) ;
397
+
398
+ for ( i, chunk) in data. chunks ( parse_size) . enumerate ( ) {
399
+ let offset = i * ( DATA_CHUNK_SIZE - 1 ) ;
400
+
401
+ let copy_end = offset + chunk. len ( ) - 1 ;
402
+ valid_data[ offset..copy_end] . copy_from_slice ( & chunk[ 1 ..] ) ;
403
+
404
+ if i == data_len - 1 && chunk. len ( ) < parse_size {
405
+ valid_end = offset + chunk. len ( ) - 1 ;
406
+ }
407
+ }
408
+
409
+ valid_data. truncate ( valid_end) ;
410
+ valid_data
411
+ }
412
+
413
+ #[ cfg( test) ]
414
+ mod test {
415
+ #[ test]
416
+ fn test_pad_and_unpad ( ) {
417
+ let data = vec ! [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ;
418
+ let padded_data = super :: convert_by_padding_empty_byte ( & data) ;
419
+ let unpadded_data = super :: remove_empty_byte_from_padded_bytes ( & padded_data) ;
420
+ assert_eq ! ( data, unpadded_data) ;
421
+ }
422
+
423
+ #[ test]
424
+ fn test_pad_and_unpad_large ( ) {
425
+ let data = vec ! [ 1 ; 1000 ] ;
426
+ let padded_data = super :: convert_by_padding_empty_byte ( & data) ;
427
+ let unpadded_data = super :: remove_empty_byte_from_padded_bytes ( & padded_data) ;
428
+ assert_eq ! ( data, unpadded_data) ;
429
+ }
430
+
431
+ #[ test]
432
+ fn test_pad_and_unpad_empty ( ) {
433
+ let data = Vec :: new ( ) ;
434
+ let padded_data = super :: convert_by_padding_empty_byte ( & data) ;
435
+ let unpadded_data = super :: remove_empty_byte_from_padded_bytes ( & padded_data) ;
436
+ assert_eq ! ( data, unpadded_data) ;
437
+ }
438
+ }
0 commit comments