-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat invariant (#5868) - configure calldata fuzzed addresses dictionary #7240
Conversation
- added `FuzzDictionaryConfig.max_calldata_fuzz_dictionary_addresses` option to specify how many random addresses to generate and to randomly select from when fuzzing calldata. If option is not specified then current behavior applies - to narrow down number of runs / addresses involved in invariant test the `CalldataFuzzDictionaryConfig` is populated with random addresses plus all accounts from db (from `EvmFuzzState`) - added `fuzz_calldata_with_config` fn that accepts `Option<CalldataFuzzDictionary>` as param. Non invariants tests use existing `fuzz_calldata` fn and pass None as config arg
5c05252
to
692adef
Compare
692adef
to
abe6c8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense
left some nits
} | ||
|
||
impl CalldataFuzzDictionaryConfig { | ||
pub fn new(config: &FuzzDictionaryConfig, state: EvmFuzzState) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in b77dcb6
use proptest::prelude::{BoxedStrategy, Strategy}; | ||
use std::{fmt, sync::Arc}; | ||
|
||
pub type CalldataFuzzDictionary = Arc<CalldataFuzzDictionaryConfig>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really disklike this alias style, this makes it much harder to navigate.
I know we have this in a few other places, but this isn't very helpful. I'd prefer a new wrapper type like
struct CalldataFuzzDictionary {
inner: Arc<CalldataFuzzDictionaryConfig>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done with b77dcb6 plus some code cleanup
Will this also allow users to specify the number of distinct senders? AFAIK Foundry currently uses an unlimited number of It should be nice to configure that as well |
correct, there is a new config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, pending conflicts
done |
Motivation
Atm there's no way to configure calldata fuzzed params behavior - this could in particular be an issue when fuzzing addresses as there's little to no chance the same address is reused.
For invariant testing this is a bigger issue as one would often want to randomly reuse addresses when calling different handler selectors (see #5868). Some projects maintains an array of addresses in handlers and fuzz the indexes / prank with users from array of addresses - that's a little bit hard to mantain and cannot scale for too many addresses.
Solution
This PR introduce an additional config for the dictionary of addresses used in calldata fuzzing.
FuzzDictionaryConfig.max_calldata_fuzz_dictionary_addresses
option to specify how many random addresses to generate and to randomly select from when fuzzing calldata. If option is not specified then current behavior appliesCalldataFuzzDictionaryConfig
is populated with random addresses plus all accounts from db (fromEvmFuzzState
)fuzz_calldata_with_config
fn that acceptsOption<CalldataFuzzDictionary>
as param. Non invariants tests use existingfuzz_calldata
fn and pass None as config argFurther improvements:
Todo: