foundry: bug(`forge coverage`): stack too deep when using `--ir-minimum` and coverage report is not accurate
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 (ddaf100 2022-09-24T00:05:44.382307Z)
What command(s) is the bug in?
forge coverage
Operating System
macOS (Apple Silicon)
Describe the bug
on executing forge coverage i am getting the below error
Error:
Compiler run failed
CompilerError: Stack too deep when compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack.
but forge test and forge build are working fine.
NOTE: I noticed also that forge build and forge test are considering the cache but forge coverage is trying to re-compile even though I have a cached successful build
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 22
- Comments: 29 (9 by maintainers)
Commits related to this issue
- Fix "coverage stack too deep" issue https://github.com/foundry-rs/foundry/issues/3357 — committed to SizeCredit/size-solidity by aviggiano 3 years ago
vouching for reopening this issue
AFAIK
forge coveragecurrently compiles with the optimizer off, which is needed for better source maps.forge test(and build) work because you’re using the optimizer or via-IR which resolve the stack too deep error that’s occurring with the optimizer off (this is also why you see it recompile for coverage).Unfortunately for now to use coverage you’ll need to refactor such that you can compile with the optimizer off / without via-IR
Hey! Same issue for me. I think the issue should be re-opened,
For future readers:
This workaround is better than
--ir-minimum:https://github.com/taikoxyz/taiko-mono/pull/14489
hi, @mattsse @spockP
--ir-minimumdoesn’t work too@uranium93 structs are a neat way to solve Stack Too Deep.
I understand the reasoning for compiling without the optimizer – but I will note that this means currently any project that imports Seaport contracts directly cannot use forge coverage, as some assembly results in stack-too-deep errors.
There’s probably not much to do at the moment – but we’d love if we could encourage new projects to build on top of Seaport with Foundry (including coverage) in the future.
Any updates on this issue. When running forge coverage --via-ir and ir min I still get the stack too deep error but I dont get it with forge build or forge test
In my case
--ir-minimumdoesn’t work, only makes the error more sophisticated:The solution that @aviggiano linked is for some specific blockchain as far as I can tell? Could be wrong.
Overall, I think we should reopen the issue as it’s not solved yet.
I think this is a question for @uranium93? But yes I’d say this is a known issue/limitation so we can close this
Unfortunately not, as solc does not provide this information since it’s complex to retrieve. You can read more here: https://github.com/ethereum/solidity/issues/11638#issuecomment-1057485738
In our case the
ir-minimumflag allows us to run coverage but we get a lot of false positives, coverage goes pretty down in %Looks like there will be a remedy when solidity 0.8.21 comes out: https://github.com/ethereum/solidity/issues/13972
This is still the case, however this is not easy to resolve in forge due to the current coverage limitations (which themselves are due to solc limitations). The easiest solution is to update your code to avoid stack too deep issues
Hey @Rubilmax , for me the only fix that was possible and fast is to re-write the affected tests with hardhat