argotorg / argotorg/solidity

Stack too deep errors with via-IR for some compilation routines

Open
#14,878 0 comments 2 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

I'm building a fairly large project using via-IR, here's the specific commit: https://github.com/drips-network/contracts/tree/57b0da62aceb0eb382c0d0472e53c1b42b962ebb. Depending on how the compilation is organized, the result may or may not be the stack too deep error.

## Environment

- Compiler version: 0.8.24
- Target EVM version (as per compiler settings): shanghai
- Framework/IDE (e.g. Truffle or Remix): Foundry
- EVM execution environment / backend / blockchain client: Anvil
- Operating system: Linux

## Steps to Reproduce

I can't provide a minimal example because the stack too deep errors only show up for large projects. Here are the steps to do after cloning the repository and installing Foundry. First of all, enable via-IR in the project:sd

```bash
export FOUNDRY_PROFILE=optimized
```

### The failing routine

Clean up the Foundry compilation cache:
```bash
foundry clean
```

Build the project with all the tests and run them:
```bash
foundry test
```

The result is the stack too deep error:
```
Error:
Compiler run failed:
Error: Yul exception:Cannot swap Variable var_idx with Variable _mpos_2: too deep in the stack by 1 slots in [ var_idx _mpos_2 var_accountId var_squeezeEndCap var_squeezeStartCap cleaned_4 cleaned_3 var_i_1 _mpos_1 var_amt var_currCycleConfigs RET var_squeezedRevIdxs_mpos var_squeezedNum dataSlot_3 var_streamsHistory_mpos _mpos_3 _mpos_2 ]
memoryguard was present.
memoryguard was present.
```

### The succeeding routine

Clean up the Foundry compilation cache:
```bash
foundry clean
```

Build the project without the tests:
```bash
foundry build --skip test
```

Build the project again, this time with all the tests and run them:
```bash
foundry test
```

The result is a successful compilation and tests being executed.

### Additional context

These results are reproducible, I tried both of them a few times and they always behave the same. I don't know if this is a Foundry issue or a Solc issue, I don't know how caching of the artifacts works and which component is responsible for putting them together in a reproducible way. This issue may or may not be even connected to the stack too deep issue at all, it could be only that this is an edge case where a caching issue causes a more visible result.

This is not necessarily an issue for the stack too deep error itself, it's already well known and has a few issues opened: https://github.com/ethereum/solidity/issues/14358, https://github.com/ethereum/solidity/issues/14187, https://github.com/ethereum/solidity/issues/14179 and https://github.com/ethereum/solidity/issues/14067, https://github.com/ethereum/solidity/issues/13906.

Contributor guide

Open the contributing guide

Research direction

Clone the referenced drips-network/contracts commit, install Foundry, set FOUNDRY_PROFILE=optimized, and compare foundry test with foundry build --skip test followed by foundry test after clearing the cache. Investigate whether the failure belongs to Solidity's via-IR compilation or Foundry's artifact caching; done means identifying the responsible component and reproducing the differing outcomes reliably.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.