I've been working on a refactor for a while now. On a relatively large project. I'm getting an error:

CompilerError: Stack too deep when compiling inline assembly: Variable headStart is 3 slot(s) too deep inside the stack.

I've refactoring and split a bunch of the files into smaller ones but after a few days of work still no luck.

Is there any simple way to identify where the stack becomes too deep so I can look into fixing it?


Okay I found the culprit, still not sure how to fix this heres a reproducible example:

struct MyInnerStruct {
    uint256 amount;
    bytes options;

struct MyOuterStruct {
    MyInnerStruct[][] groupedOptions;

Error Occurs when attempting to decode:

MyOuterStruct memory outer = abi.decode(params, (MyOuterStruct));

2 Answers 2


Could you share your code?

With a quick search on google, I found this article that may help you. Copying from the article:

The reason is a limitation in how variables can be referenced in the EVM stack. While you can have more than 16 variables in it, once you try to reference a variable in slot 16 or higher, it will fail.

  • Okay, I found the code causing this, still not sure why it occurs. I pretty much commented out every file until I found the file which caused this
    – Ritzy Dev
    Commented Feb 10, 2023 at 0:27

Okay there are a ton of ways this can happen, its mostly because ABI decode is not that robust and does not support deserializing structs with nested variable arrays.

I'm not really sure why because it seems to supply deserializing bytes just fine which is also dynamic.

As a workaround I've created a Serializable model and I adapt to it internally

struct SerializableOuterStruct {
   // the inner struct
   MyInnerStruct[] data;
   // the the index where to split the data on
   // Note: if you don't need to support jagged arrays
   // this can just be a single variable arrayLength
   uint256[] splitIndexes;

From there you can parse the data into the original struct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.