@@ -5,7 +5,7 @@ use crate::{
55 strategies:: { EvmFuzzState , fuzz_calldata_from_state, fuzz_param} ,
66} ;
77use alloy_json_abi:: Function ;
8- use alloy_primitives:: Address ;
8+ use alloy_primitives:: { Address , U256 } ;
99use parking_lot:: RwLock ;
1010use proptest:: prelude:: * ;
1111use rand:: seq:: IteratorRandom ;
@@ -17,6 +17,7 @@ pub fn override_call_strat(
1717 contracts : FuzzRunIdentifiedContracts ,
1818 target : Arc < RwLock < Address > > ,
1919 fuzz_fixtures : FuzzFixtures ,
20+ max_fuzz_int : Option < U256 > ,
2021) -> impl Strategy < Value = CallDetails > + Send + Sync + ' static {
2122 let contracts_ref = contracts. targets . clone ( ) ;
2223 proptest:: prop_oneof![
@@ -41,7 +42,13 @@ pub fn override_call_strat(
4142 } ;
4243
4344 func. prop_flat_map ( move |func| {
44- fuzz_contract_with_calldata ( & fuzz_state, & fuzz_fixtures, target_address, func)
45+ fuzz_contract_with_calldata (
46+ & fuzz_state,
47+ & fuzz_fixtures,
48+ target_address,
49+ func,
50+ max_fuzz_int,
51+ )
4552 } )
4653 } )
4754}
@@ -62,19 +69,22 @@ pub fn invariant_strat(
6269 contracts : FuzzRunIdentifiedContracts ,
6370 dictionary_weight : u32 ,
6471 fuzz_fixtures : FuzzFixtures ,
72+ max_fuzz_int : Option < U256 > ,
6573) -> impl Strategy < Value = BasicTxDetails > {
6674 let senders = Rc :: new ( senders) ;
6775 any :: < prop:: sample:: Selector > ( )
6876 . prop_flat_map ( move |selector| {
6977 let contracts = contracts. targets . lock ( ) ;
7078 let functions = contracts. fuzzed_functions ( ) ;
7179 let ( target_address, target_function) = selector. select ( functions) ;
72- let sender = select_random_sender ( & fuzz_state, senders. clone ( ) , dictionary_weight) ;
80+ let sender =
81+ select_random_sender ( & fuzz_state, senders. clone ( ) , dictionary_weight, max_fuzz_int) ;
7382 let call_details = fuzz_contract_with_calldata (
7483 & fuzz_state,
7584 & fuzz_fixtures,
7685 * target_address,
7786 target_function. clone ( ) ,
87+ max_fuzz_int,
7888 ) ;
7989 ( sender, call_details)
8090 } )
@@ -88,14 +98,15 @@ fn select_random_sender(
8898 fuzz_state : & EvmFuzzState ,
8999 senders : Rc < SenderFilters > ,
90100 dictionary_weight : u32 ,
101+ max_fuzz_int : Option < U256 > ,
91102) -> impl Strategy < Value = Address > + use<> {
92103 if !senders. targeted . is_empty ( ) {
93104 any :: < prop:: sample:: Index > ( ) . prop_map ( move |index| * index. get ( & senders. targeted ) ) . boxed ( )
94105 } else {
95106 assert ! ( dictionary_weight <= 100 , "dictionary_weight must be <= 100" ) ;
96107 proptest:: prop_oneof![
97- 100 - dictionary_weight => fuzz_param( & alloy_dyn_abi:: DynSolType :: Address ) ,
98- dictionary_weight => fuzz_param_from_state( & alloy_dyn_abi:: DynSolType :: Address , fuzz_state) ,
108+ 100 - dictionary_weight => fuzz_param( & alloy_dyn_abi:: DynSolType :: Address , max_fuzz_int ) ,
109+ dictionary_weight => fuzz_param_from_state( & alloy_dyn_abi:: DynSolType :: Address , fuzz_state, max_fuzz_int ) ,
99110 ]
100111 . prop_map ( move |addr| {
101112 let mut addr = addr. as_address ( ) . unwrap ( ) ;
@@ -122,13 +133,14 @@ pub fn fuzz_contract_with_calldata(
122133 fuzz_fixtures : & FuzzFixtures ,
123134 target : Address ,
124135 func : Function ,
136+ max_fuzz_int : Option < U256 > ,
125137) -> impl Strategy < Value = CallDetails > + use<> {
126138 // We need to compose all the strategies generated for each parameter in all possible
127139 // combinations.
128140 // `prop_oneof!` / `TupleUnion` `Arc`s for cheap cloning.
129141 prop_oneof ! [
130- 60 => fuzz_calldata( func. clone( ) , fuzz_fixtures) ,
131- 40 => fuzz_calldata_from_state( func, fuzz_state) ,
142+ 60 => fuzz_calldata( func. clone( ) , fuzz_fixtures, max_fuzz_int ) ,
143+ 40 => fuzz_calldata_from_state( func, fuzz_state, max_fuzz_int ) ,
132144 ]
133145 . prop_map ( move |calldata| {
134146 trace ! ( input=?calldata) ;
0 commit comments