foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Forge debugger sometimes jumbles sourcemaps

Open emo-eth opened this issue 1 year ago • 0 comments

Component

Forge

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

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (79d2de60 2024-02-12T20:06:43.997810000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

This is difficult to reproduce, especially minimally.

Sometimes, Forge sourcemaps are jumbled, ie, the highlighted code is not at all what is being executed.

This can lead to panics, I assume because it tries to look up a PC out of range for the sourcemap.

Usually this is the result of an incremental build, ie, tweaking a single file and then entering the debugger – in the Seaport repo especially, this results in jumbled sourcemaps for at least some contracts. forge clean and building from scratch often fixes the issue in this scenario.

I have a couple theories:

  • solc may be assigning fresh+duplicate sourceIds to build artifacts (seems unlikely, but I have heard that eg incremental builds with via-ir enabled result in different bytecode than from clean)
  • Contracts with the same name but different sourceIds are getting loaded in the "wrong" order after an incremental build, which has downstream effects
  • Some other unidentified upstream effect

Recently, I encountered a case where a clean build still resulted in a jumbled sourcemap. There were no duplicate contract names. I am unsure if it is the same issue.

emo-eth avatar Feb 13 '24 22:02 emo-eth