Skip to content
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

bug: Stack too deep in TestHelperOz5 contract when using forge coverage #979

Open
LI-YONG-QI opened this issue Nov 6, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@LI-YONG-QI
Copy link

Describe the bug
Command

forge coverage

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 headStart is 1 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 headStart is 1 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.

This error occurred when I imported TestHelperOz5 into Foundry test contract

To Reproduce

  1. Prepare test contract
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

// Mock imports
import {OFTMock} from "./OFTMock.sol";
import {ERC20Mock} from "./ERC20Mock.sol";
import {OFTComposerMock} from "./OFTComposerMock.sol";

// OApp imports
import {
    IOAppOptionsType3, EnforcedOptionParam
} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OAppOptionsType3.sol";
import {OptionsBuilder} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";

// OFT imports
import {IOFT, SendParam, OFTReceipt} from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol";
import {MessagingFee, MessagingReceipt} from "@layerzerolabs/oft-evm/contracts/OFTCore.sol";
import {OFTMsgCodec} from "@layerzerolabs/oft-evm/contracts/libs/OFTMsgCodec.sol";
import {OFTComposeMsgCodec} from "@layerzerolabs/oft-evm/contracts/libs/OFTComposeMsgCodec.sol";

// OZ imports
import {IERC20} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

// Forge imports
import "forge-std/console.sol";

// DevTools imports
import {TestHelperOz5} from "@layerzerolabs/test-devtools-evm-foundry/contracts/TestHelperOz5.sol";
  1. Check TestHelperOz5 contract imported
import {TestHelperOz5} from "@layerzerolabs/test-devtools-evm-foundry/contracts/TestHelperOz5.sol";
  1. Run coverage
forge coverage
  1. Error

Expected behavior

Display test coverage data.

Like this:

| test/mocks/OFTComposerMock.sol                  | 0.00% (0/5)      | 0.00% (0/5)      | 100.00% (0/0)  | 0.00% (0/1)    |
| test/mocks/OFTMock.sol                          | 0.00% (0/8)      | 0.00% (0/15)     | 100.00% (0/0)  | 0.00% (0/9)    |
| test/utils/DeployBase.t.sol                     | 89.45% (195/218) | 88.24% (210/238) | 38.24% (13/34) | 84.21% (16/19) |
| Total                                           | 7.58% (211/2783) | 6.31% (227/3597) | 1.80% (14/778) | 4.86% (22/453) |

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: macOS
  • OS Version 15.0
  • VM Version: solc 0.8.22
  • forge Version: forge 0.2.0 (fb86e5d 2024-06-05T00:17:33.761343000Z)

foundry.toml

[profile.default]
src = "src"
out = "out"
solc_version = "0.8.22"
optimizer = true
optimizer_runs = 200
fs_permissions = [{ access = "read", path = "./"}]
@LI-YONG-QI LI-YONG-QI added the bug Something isn't working label Nov 6, 2024
@ryandgoulding
Copy link
Contributor

Hi @LI-YONG-QI , this is a known limitation of TestHelperOz5. To produce coverage, you must use either --via-ir or --ir-minimum flags.

@ryandgoulding ryandgoulding added enhancement New feature or request and removed bug Something isn't working labels Nov 6, 2024
@LI-YONG-QI
Copy link
Author

Hi @LI-YONG-QI , this is a known limitation of TestHelperOz5. To produce coverage, you must use either --via-ir or --ir-minimum flags.

Yes, it's a good solution, but I think this could be a bit inconvenient as it will make the compilation time too long.
Do you have any other recommended solutions?

@KevinYum
Copy link

Same here, cannot even build after import TestHelperOz5
with command forge build --via-ir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants