-
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
targeted_contracts in invariant test is getting updated unexpectedly partway through an invariant test run #5625
Comments
hey—could you try with the latest foundry version by using |
Hey, just upgraded to:
and I'm still seeing the |
@Melvillian I'm seeing something similar. My |
We never ended up being able to figure this out, and instead we threw up our hands and commented out the invariant test. From what I remember from debugging with a local version of Foundry that I could add If I had more time, I'd write and submit a patch which exempted |
this is still happing on |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (a0a31c3 2023-08-11T18:45:55.249069000Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
Background:
I am running a invariant test contract using a forked version of the blockchain pointing at Mainnet, with a single Handler, and I only want the Handler and its functions to be called throughout the entire invariant test run. Any calls to non-handler functions is undesired and results in me needing to set
fail_on_revert = false
in order to prevent my invariant test run from failing every time.Expected Behavior:
I use
targetContract
andtargetSelector
to select my Handler's address and various Handler functions, respectively, in thesetUp
function of my InvariantTest contract. This will mean that the only function I ever see being fuzzed should be the Handler. I should runforge test -vvvv
and not see any calls to other contractsActual Behavior:
When I run
forge test -vvvv
, I see that there are many calls being made to a contract that was deployed during thesetUp
of my InvariantTest contract. Specifically, the only other contract besides the Handler being fuzzed is the one that was setup with the code below. The purpose of the code below is to take an already-deployed (i.e. already existing contract on the mainnet fork) and overwrite its bytecode with my own supplied code in order to mock it and make testing simpler:Hypothesis:
I cloned
foundry
and added some debugging logs to a locally running version offorge
in order to try to understand what is going on. From running that, I was able to that in this executor.rs function the list of targeted_contracts is being updated with the MockBridge code's address. Whys is that happening, even though we never deployed the MockBridge in our InvariantTeest? My guess is that because of this check in collect_data, because of the call tovm.etch
, there is a bug where Forge thinks that we actually did deploy the contract with a sender that didn't have any code (whatever addresses is used byvm
) and so it ends up adding the MockBridge contract to the listed ofcreated_contracts
, which ultimately gets sampled from to decide on the next fuzz run, and thus will probabilistically end up choosing the MockBridge code and its selectors to be fuzzed.Solution:
when calculated
created_contracts
, exclude any that were touched by Cheatcode addresses, as those are not really created, as we can see here withetch
. Though to be clear, I'm not sure this is the problem because I'm not super familiar with Forge's codebase; that is just what I've been able to uncover by manually debugging.The text was updated successfully, but these errors were encountered: