You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to be able to instruct Foundry to sort the array on our behalf. I'm thinking of something like this (echo-ing the proposal I left in #4085):
That is, whenever the custom NatSpec tag above is specified, Foundry would provide the user with a sorted array arr, every time. It would be cheaper to let Foundry do this in Rust rather than sorting the array in memory in Solidity.
As an alternative to the above, we could consider using a specific prefix for the array variable names:
function test_Something(uint256[] memorysortedArr) external {
// ...
}
The idea being, every time Foundry sees a function param that is an array type and its name starts with sorted, it would automatically sort the array.
Sorted arrays should be a common enough use case for a feature like this to be worth considering and implementing.
The text was updated successfully, but these errors were encountered:
We can use proptest::prop_map to generate a sorted array out of a proptest strategy.
We could also extend the input of the fuzz_param function to accept some kind of metadata associated to param.
Such metadata would let us generate more sophisticated compound strategies (i.e. for sorted arrays).
imho the NatSpec approach is probably more flexible than the param name. Given though we should define some meta language to convey strategy configs to the fuzzer i.e.
Wondering if what lacks from current Foundry fuzz testing framework is a corpus, just like we have with libfuzzer for instance, see the Corpus enum https://docs.rs/libfuzzer-sys/latest/libfuzzer_sys/macro.fuzz_target.html
Instead of adding features top down for every strategy, just implement the corpus and it will do that for free
Component
Forge
Describe the feature you would like
As discussed in #3948, my protocol has some business logic that is dependent upon the end user sending a sorted array as a function argument.
I've been bashing my head against the wall trying to fuzz the input arrays in a way that is scalable (tests don't take ages to run), to no fruition.
I pulled together an implementation of the quicksort algorithm in Solidity based on the sources I found on the Internet. The issue is that sorting a fuzzed arrays slows down test run times.
It would be nice to be able to instruct Foundry to sort the array on our behalf. I'm thinking of something like this (echo-ing the proposal I left in #4085):
That is, whenever the custom NatSpec tag above is specified, Foundry would provide the user with a sorted array
arr
, every time. It would be cheaper to let Foundry do this in Rust rather than sorting the array in memory in Solidity.As an alternative to the above, we could consider using a specific prefix for the array variable names:
The idea being, every time Foundry sees a function param that is an array type and its name starts with
sorted
, it would automatically sort the array.Sorted arrays should be a common enough use case for a feature like this to be worth considering and implementing.
The text was updated successfully, but these errors were encountered: