foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug: state appears to be shared between tests when linked libraries are used

Open mds1 opened this issue 6 months ago • 5 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [ ] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

forge 0.2.0 (1197fbe 2024-08-09T00:25:08.996768000Z)

What command(s) is the bug in?

forge test

Operating System

None

Describe the bug

  1. Clone the optimism monorepo and check out this branch: https://github.com/ethereum-optimism/optimism/pull/11423
  2. Run just test, and you'll notice testDebug fails. That is hardcoded data from a failed CI run
  3. Now, only run the failed test: forge test --mt testDebug -vvv. It will pass. If you run the full file containing that test it will also still pass.
  4. Compare the passing and failing traces (see below screenshots). Notice how in the passing one, the call is to an unlabeled address, and in the failing one it's to an address labeled ForgeArtifacts. Based on the hardcoded calldata in testDebug, we can see that address is 0x5F65cD7D792E9746EF82929D60de9a1C526f93A5.

So what appears to be happening here is that when the full suite is run, contracts deployed from another test (1) leak into the fuzzer dictionary of this test, and (2) the state leaks into this test as well.

image image

mds1 avatar Aug 09 '24 18:08 mds1