@@ -196,11 +196,15 @@ impl CorpusManager {
196
196
197
197
let can_reply_tx = |tx : & BasicTxDetails | -> bool {
198
198
fuzzed_contracts. is_some_and ( |contracts| contracts. targets . lock ( ) . can_replay ( tx) )
199
- || fuzzed_function
200
- . is_some_and ( |function| function. selector ( ) == tx. call_details . calldata [ ..4 ] )
199
+ || fuzzed_function. is_some_and ( |function| {
200
+ tx. call_details
201
+ . calldata
202
+ . get ( ..4 )
203
+ . is_some_and ( |selector| function. selector ( ) == selector)
204
+ } )
201
205
} ;
202
206
203
- for entry in std:: fs:: read_dir ( corpus_dir) ? {
207
+ ' corpus_replay : for entry in std:: fs:: read_dir ( corpus_dir) ? {
204
208
let path = entry?. path ( ) ;
205
209
if path. is_file ( )
206
210
&& let Some ( name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) )
@@ -246,6 +250,12 @@ impl CorpusManager {
246
250
}
247
251
} else {
248
252
failed_replays += 1 ;
253
+
254
+ // If the only input for fuzzed function cannot be replied, then move to
255
+ // next one without adding it in memory.
256
+ if fuzzed_function. is_some ( ) {
257
+ continue ' corpus_replay;
258
+ }
249
259
}
250
260
}
251
261
@@ -368,7 +378,7 @@ impl CorpusManager {
368
378
let mutation_type = self
369
379
. mutation_generator
370
380
. new_tree ( test_runner)
371
- . expect ( "Could not generate mutation type" )
381
+ . map_err ( |err| eyre ! ( "Could not generate mutation type {err}" ) ) ?
372
382
. current ( ) ;
373
383
let rng = test_runner. rng ( ) ;
374
384
let corpus_len = self . in_memory_corpus . len ( ) ;
@@ -491,7 +501,6 @@ impl CorpusManager {
491
501
let corpus = & self . in_memory_corpus
492
502
[ test_runner. rng ( ) . random_range ( 0 ..self . in_memory_corpus . len ( ) ) ] ;
493
503
self . current_mutated = Some ( corpus. uuid ) ;
494
-
495
504
let new_seq = corpus. tx_seq . clone ( ) ;
496
505
let mut tx = new_seq. first ( ) . unwrap ( ) . clone ( ) ;
497
506
self . abi_mutate ( & mut tx, function, test_runner, fuzz_state) ?;
@@ -573,10 +582,7 @@ impl CorpusManager {
573
582
debug ! ( target: "corpus" , "evict corpus {uuid}" ) ;
574
583
575
584
// Flush to disk the seed metadata at the time of eviction.
576
- let eviction_time = SystemTime :: now ( )
577
- . duration_since ( UNIX_EPOCH )
578
- . expect ( "Time went backwards" )
579
- . as_secs ( ) ;
585
+ let eviction_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) ?. as_secs ( ) ;
580
586
foundry_common:: fs:: write_json_file (
581
587
self . config
582
588
. corpus_dir
@@ -611,7 +617,7 @@ impl CorpusManager {
611
617
} ;
612
618
let mut prev_inputs = function
613
619
. abi_decode_input ( & tx. call_details . calldata [ 4 ..] )
614
- . expect ( "function cannot abi decode input" ) ;
620
+ . map_err ( |err| eyre ! ( "failed to load previous inputs: {err}" ) ) ? ;
615
621
616
622
// For now, only new inputs are generated, no existing inputs are
617
623
// mutated.
0 commit comments