matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
286 stars 123 forks source link

`forge coverage --via-ir` fails with stack too deep #475

Open PatrickAlphaC opened 2 months ago

PatrickAlphaC commented 2 months ago

Component

Forge

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

What version of Foundry are you on?

No response

What command(s) is the bug in?

No response

Operating System

None

Describe the bug

I'm forwarding this issue and tagging @0x5chn0uf.

Link to original issue: https://github.com/Cyfrin/foundry-full-course-cu/discussions/1966#discussioncomment-9986282


Hi!

At the end of Lesson 15: Foundry Account Abstraction, I'm looking to complete the test suite. However, I encounter a problem when using forge coverage --via-ir to compile my Solidity project. The following error occurs:

minimal-account-abstraction % forge coverage --via-ir
[⠒] Compiling...
[⠰] Compiling 88 files with Solc 0.8.24
[⠑] Solc 0.8.24 finished in 8.39s
Error: 
Compiler run failed:
Error: Compiler error (/solidity/libyul/backends/evm/AsmCodeGen.cpp:67):Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable value0 is 2 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.
CompilerError: Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable value0 is 2 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.

Command executed:

forge coverage --via-ir

Environment

Solidity Version: 0.8.24 Foundry Version: forge 0.0.2 (from foundry-zksync) OS: MacOS 14.2.1

Context

I also have this problem with the final code of the minimal-account-abstraction repository. I run the forge coverage command and get the error mentioned above.

What I've tried


I read that the error seems to be related to assembler, but I don't see where I can rework the code and modify the stack. Do you have any suggestions on how to solve this problem or additional leads to explore?

Thanks in advance!

0x5chn0uf commented 1 month ago

Hi there, thanks for bringing this up @PatrickAlphaC! 🙂

To add more context, I'm (in theory) using the latest version of foundry-zksync after running the foundryup-zksync installation command. I'm encountering this problem on the repo associated with Patrick's course on Account Abstraction, but also on another repo linked to ZkSync (MondrianWallet2 FirstFlight).

Here is the version installed:

minimal-account-abstraction % forge --version
forge 0.0.2 (ab00f2e 2024-07-12T00:22:09.735302000Z)

Additionally, here is the content of my foundry.toml file, where via-ir and is-system are set to true.

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
remappings = ['@openzeppelin/contracts=lib/openzeppelin-contracts/contracts']
is-system = true
via-ir = true
fs_permissions = [
    { access = "read", path = "./broadcast" },
    { access = "read", path = "./reports" },
]

forge build executes successfully with and without the zksync flag

minimal-account-abstraction % forge build --via-ir
[⠒] Compiling...
[⠰] Compiling 88 files with 0.8.24
[⠒] Solc 0.8.24 finished in 78.79s
Compiler run successful!
minimal-account-abstraction % forge build --via-ir --zksync
[⠃] Compiling (zksync)...
Compiler run successful with warnings:
.
.
.

However, when I try to obtain test coverage, despite using the --via-ir flag, the command fails with the Stack too deep error described in the initial thread.

 minimal-account-abstraction % forge coverage --via-ir

[⠆] Compiling...
[⠢] Compiling 88 files with 0.8.24
[⠒] Solc 0.8.24 finished in 9.12s
Error: 
Compiler run failed:
Error: Compiler error (/solidity/libyul/backends/evm/AsmCodeGen.cpp:67):Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable value0 is 2 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.
CompilerError: Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable value0 is 2 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.

Same with --zksync flag

minimal-account-abstraction % forge coverage --via-ir --zksync

[⠢] Compiling...
[⠒] Compiling 88 files with 0.8.24
[⠰] Solc 0.8.24 finished in 8.04s
Error: 
Compiler run failed:
.
.

Tests are compiled and run correctly with the forge test command

minimal-account-abstraction % forge test --zksync
[⠢] Compiling...
No files changed, compilation skipped
[⠢] Compiling (zksync)...
No files changed, compilation skipped

Ran 5 tests for test/ethereum/MinimalAccountTest.t.sol:MinimalAccountTest
[PASS] testEntryPointCanExecuteCommands() (gas: 42342)
[PASS] testNonOwnerCannotExecuteCommands() (gas: 42364)
.
.
.

Do not hesitate to let me know if you need any further information!