-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix(invariant
): do not record newly created contracts as targetContracts
#6200
Conversation
@Evalir Could you get a bit more concrete on describing the new behavior, e.g. if I use any I also wonder if this should be behind a flag since it's technically a breaking change? Wonder if anyone relies on this, cc @lucas-manuel |
Yep @mds1 so expanding & clarifying:
super curious about you guys's thoughts—i think we need to explicitly document this. |
Hmm interesting, my first reaction is to avoid adding these automatically, and document that if a dev wants to add contracts deployed during a run to target contracts, they should do so explicitly (in a handler for example). Just to clarify:
Does this adding happen in the first option? Cause i'm thinking it could be nice if we did:
|
For what it's worth, I am doing some invariant testing in which this has become a problem for me. I have a contract that manages rewards for staking with a variety of tokens, and I want to test its behavior when new staking contracts are added. In one of my handlers I deploy a new underlying ERC20 as well as its staked counterpart, which requires its own handler. When trying to explicitly add the new handler using After reading this thread, it seems that calling |
Maybe the simplest solution here is to have a global default for whether or not to add new contracts during a run. This would apply regardless of how you setup targeted/excluded contracts. Then, have a config flag to change the default, which can be set in |
@mds1 would it still be possible to explicitly add or exclude contracts during a run, if it's configured to not add new contracts automatically? |
To that point, on second thought, maybe a better UX here is ditch my config flag idea and just add a new contract getter method, |
Happy new year! |
hey @webthethird ! i'll be picking this up again soon. Just needs a bit of a different approach as currently some tests are failing, and we probably wanna discuss the UX a bit further. |
Hey, guys, I just encoutered the similar case of #6166 , that in each run of an invariant test, the second call is made to non-target contract at a non-target function with very high possibility. In my case, the handler is dealing with token approval and access control. So it does interact with several pre-deployed contracts which are not supposed to be targets of invariant testing. Before reading this pr, I just have no idea of its reason. Thanks to @Evalir for your very detailed explanation that answers my question. Waiting for updates. Does the |
Motivation
Potential fix to #6166 and #5625 cc @mds1 @PatrickAlphaC
Solution
Right now,
targetContracts()
is not "static" aftersetUp()
—it gets updated after each depth call with the newly created contracts and their selectors. This has been foundry's behavior since invariants were added.However, people expect to only see contracts added in
targetContracts
during setup to be used for creating inputs. This means that if contracts are deployed after setup they should not see them in fuzz runs.The fix is to stop adding these new contracts to the targeted contracts.