Skip to content

Stack too deep error without viaIR and 0% coverage #760

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

Closed
vladikopl01 opened this issue Sep 29, 2022 · 13 comments
Closed

Stack too deep error without viaIR and 0% coverage #760

vladikopl01 opened this issue Sep 29, 2022 · 13 comments

Comments

@vladikopl01
Copy link

Hello, need some help. Had the same problems with stack too deep error and viaIR set is true as someone already reported. Done everything as you suggested but nothing helps.

My solcover.js file

module.exports = {
  skipFiles: ['BCDeimosContractRef.sol', 'ERC20Token.sol'],
  configureYulOptimizer: true,
  solcOptimizerDetails: {
    peephole: false,
    inliner: false,
    jumpdestRemover: false,
    orderLiterals: true,
    deduplicate: false,
    cse: false,
    constantOptimizer: false,
    yul: false,
  },
};

My hardhat.config.ts file

const config: HardhatUserConfig = {
  solidity: {
    version: '0.8.15',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
      // viaIR: true,
    },
  },
  networks: {
    ...networksConfig,
    hardhat: {
      gas: 99999999,
      gasPrice: 20000000000,
      blockGasLimit: 999999999,
      allowUnlimitedContractSize: true,
    },
  },
  defaultNetwork: 'hardhat',
  typechain: {
    outDir: 'typechain',
    target: 'ethers-v5',
  },
  etherscan: etherscanConfig,
  gasReporter: {
    coinmarketcap: envConfig.coinmarketcapApiKey,
    currency: 'USD',
    showTimeSpent: true,
    enabled: envConfig.reportGas,
  },
};

I had solidity version 0.8.15 as you can see, hardhat version is ^2.11.2 and solidity-coverage version is ^0.8.2. Also, I have installed a typychain package with version ^8.1.0.

With such configuration I ran into such errors:

Version
=======
> solidity-coverage: v0.8.2

Instrumenting for coverage...
=============================

> BCDeimosContract.sol

Coverage skipped for:
=====================

> BCDeimosContractRef.sol
> ERC20Token.sol

Compilation:
============

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.
    --> contracts/BCDeimosContract.sol:1122:36:
     |
1122 | SaleInfo storage saleInfo = _sales[saleId_].saleInfo;
     |                                    ^^^^^^^


Error in plugin solidity-coverage: HardhatError: HH600: Compilation failed

For more info run Hardhat with --show-stack-traces

When viaIR is turned to true it has this output:

Version
=======
> solidity-coverage: v0.8.2

Instrumenting for coverage...
=============================

> BCDeimosContract.sol

Coverage skipped for:
=====================

> BCDeimosContractRef.sol
> ERC20Token.sol

Compilation:
============

YulException: Variable var_amount_1136 is 1 slot(s) too deep inside the stack.


Error in plugin solidity-coverage: HardhatError: HH600: Compilation failed

For more info run Hardhat with --show-stack-traces

Then I tried to find a workaround for this and set yul to true in solcOptimizerDetails property in solcover.js file and had this result:

-----------------------|----------|----------|----------|----------|----------------|
File                   |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------------|----------|----------|----------|----------|----------------|
 contracts\            |        0 |        0 |        0 |        0 |                |
  BCDeimosContract.sol |        0 |        0 |        0 |        0 |... 919,920,921 |
-----------------------|----------|----------|----------|----------|----------------|
All files              |        0 |        0 |        0 |        0 |                |
-----------------------|----------|----------|----------|----------|----------------|

> Istanbul reports written to ./coverage/ and ./coverage.json

All examples were performed right after npx hardhat clean and npx hardhat coverage commands

@rkdud007
Copy link

rkdud007 commented Nov 3, 2022

I had same issue. I solved this by using these options + solidity-coverage doesn't seems to support viaIR pipline
ethereum/solidity#11638 (comment)

@cathalmf
Copy link

Im having this problem too. No other optimizer options work.

Without enabling viaIR i get "stack too deep", so i dont have a choice.

@jmendiola222
Copy link

Same problem here, see my comment on #715 (comment)

@SevenSwen
Copy link

I had same issue.
https://github.com/1inch/farming/tree/feature/enable_viaIR
If using this scheme then all tests into coverage will crash with
NomicLabsHardhatPluginError: The contract <contract_name> is missing links for the following libraries: @openzeppelin/contracts/utils/math/Math.sol:Math
I think this happens because we have remove i flag (full inliner). But if we will return inliner (change "gvf" step to "gvif") than the error will disappear, but the coverage will still remain 0%.

It seems to me that turning off the inliner should not affect the coverage so much that the internal libraries are no longer inlined. In normal tests, I could not reproduce such logic, so it is probably the coverage that affects this case.

@emretepedev
Copy link

same issue here.

@diego-G
Copy link

diego-G commented Apr 17, 2023

Same problem here...

@hung-native
Copy link

same here

@vladikopl01
Copy link
Author

Answer on ethereum/solidity#11638 (comment)

Could not check this answer, but hope it solves such a problem
Thanks @rkdud007

@diego-G
Copy link

diego-G commented Jul 12, 2023

It doesn't @vladikopl01. ViaIR is necessary to compile due to Stack too deep errors. Then we lose the coverage.

@vladikopl01 vladikopl01 reopened this Jul 12, 2023
@jmendiola222
Copy link

There is a proposed workaround here, but it seems it only worked for one user, certainly not for me. :/

@mariogutval
Copy link

It doesn't @vladikopl01. ViaIR is necessary to compile due to Stack too deep errors. Then we lose the coverage.

Same issue here

@zarifpour
Copy link

We were able to resolve our need for viaIR by using remix to connect with our localhost to identify the problematic contract(s) causing the Stack too deep. error.

Once our workspace was imported into remix, we manually compiled each contract and monitored the output of the compiler. We identified a single mock file causing the issue. When the mock was removed and we disabled viaIR our coverage was back as expected.

It would be awesome if errors and warnings are isolated to the individual file(s) causing them. That would have saved us a lot of time.

I hope this helps!

@cgewecke
Copy link
Member

Closing this as duplicate, there's ongoing discussion at #715

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

No branches or pull requests