abi.decode failing with "Stack too deep" for a list of structs when optimizations are enabled
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Abi decoding `SomeStruct[]` fails with
```
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 3 slot(s) too deep inside the stack.K
```
Strangely, wrapping it in a struct with a `SomeStruct` field on it "fixes" the issue
https://github.com/beehive-innovation/rain-protocol/pull/452/files#diff-e5cf60434f03c13e62d93df0932957c2208a64a15065489486b9aea0d158e723R9
```
SomeStruct[] memory foo_ = abi.decode(data_, (SomeStruct[]));
```
fails, as does
```
struct Foo {
SomeStruct[] bar;
}
```
but this passes
```
struct Foo {
SomeStruct bar;
SomeStruct[] baz;
}
```
The issue only appears with compiler optimizations enabled and appears for both IR and non-IR
## Environment
- Compiler version: 0.8.17
- Target EVM version (as per compiler settings):
- Framework/IDE (e.g. Truffle or Remix): hardhat
- EVM execution environment / backend / blockchain client:
- Operating system:
## Steps to Reproduce
https://github.com/beehive-innovation/rain-protocol/pull/452/files#diff-e5cf60434f03c13e62d93df0932957c2208a64a15065489486b9aea0d158e723R9
Contributor guide
Research direction
Reproduce the linked PR #452 example with Solidity 0.8.17 in Hardhat, with optimizations enabled, comparing direct SomeStruct[] decoding with the two wrapper-struct forms. Done means the direct array decode no longer produces Stack too deep for both IR and non-IR compilation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100