Home / Smart Contract Auditing / Solidity 0.8.37 Released: Critical Fix Issued for Spill Slot Collision Bug in IR Pipeline

Solidity 0.8.37 Released: Critical Fix Issued for Spill Slot Collision Bug in IR Pipeline

Smart contract developers using the Solidity compiler are being urged to update their toolchains following the disclosure of a compiler bug affecting the Intermediate Representation (IR) pipeline. Discovered and reported by security researcher Ng Sze Hon on July 30, 2026, via the Ethereum Foundation’s bug bounty program, the vulnerability involves a subtle memory management flaw in the compiler’s stack-to-memory mover—often referred to as the "stack limit evader."

The issue can lead to silent variable overwrites under very specific conditions involving mutual recursion and complex local variable allocations. Although the Ethereum Foundation and the Solidity development team have classified the bug as having a low/medium severity rating, it introduces a dangerous miscompilation vector because it does not trigger compiler warnings or runtime transaction reverts. Instead, it can cause contracts to execute with silently corrupted internal data.

Fortunately, rapid remediation has already taken place. The bug has been officially patched in Solidity version 0.8.37. Furthermore, extensive ecosystem scans of verified smart contracts on Sourcify indicate that no currently deployed mainnet contracts are known to be impacted by the defect.


Understanding the Mechanism: The Stack-to-Memory Mover

To appreciate how the bug manifests, it is necessary to examine how the Ethereum Virtual Machine (EVM) handles execution state. The EVM architecture enforces a strict physical limitation on stack access, allowing operations to interact with at most the topmost 16 stack slots. When a Solidity function declares a high volume of simultaneously live local variables, exceeding this threshold typically triggers the familiar "Stack too deep" compilation error.

To circumvent this limitation when compiling through the modern IR pipeline, the Solidity compiler employs a mechanism known as the stack-to-memory mover. This system identifies variables that exceed safe stack depths and relocates—or "spills"—them into fixed memory offsets designated as spill slots. These slots are allocated within a reserved memory region at the very beginning of the contract’s memory space, with the total size of this region communicated to the Yul optimizer via the memoryguard built-in function.

Because spill slots are designed to be reused across different function executions to conserve memory, the compiler must ensure that two variables whose live lifecycles overlap are never assigned to the same slot. Crucially, the stack-to-memory mover was designed to entirely exclude recursive functions from spilling, as individual function activations share the same memory offsets. However, a deeper flaw in how the compiler calculates slot requirements across call graphs created a vulnerability during mutual recursion scenarios.


The Root Cause: Flawed Slot Allocation and Provisional Caching

The core of the vulnerability lies within the slot allocator’s methodology for traversing call graphs. To optimize memory layout and determine the size of the reserved spill region, the compiler’s allocator walks the call graph in a depth-first manner. For every function encountered, it computes a "slot requirement"—the number of memory slots needed by that function and any downstream callees it reaches.

To prevent the depth-first walk from descending into an infinite loop when encountering recursive call chains, the allocator writes a provisional placeholder value of zero into its cache upon entering a function. This provisional zero acts as a termination signal when a cycle loops back, halting further descent.

The bug occurred because the graph traversal mechanism could inadvertently read this provisional zero as if it were a finalized, correct slot requirement. When a function was revisited through a mutual recursion cycle, it evaluated the child function’s requirement as zero rather than its true, pending value. This undercount was then finalized, cached, and propagated upward to subsequent callers throughout the compilation pipeline.

As a result, the compiler underestimated the total size required for the reserved memory region. Independent functions within the contract were assigned overlapping spill slots despite having overlapping lifecycles. At runtime, when one function executed and interacted with the stack-to-memory mover, it would silently overwrite the memory slot assigned to another active variable belonging to a completely different function path. When the program later attempted to read that variable back, it retrieved the corrupted data left behind by the intervening call.


Scope of Impact and Affected Versions

Despite the severe nature of any compiler miscompilation, the conditions required to trigger this specific spill slot collision are exceptionally narrow. For a contract to be vulnerable, a precise combination of architectural features and compiler configurations must align simultaneously:

  1. The IR Pipeline Must Be Enabled: The bug strictly affects code compiled via the IR pipeline using the --via-ir flag. Projects relying entirely on the legacy evmasm pipeline are completely unaffected. Furthermore, because --via-ir is not enabled by default in standard configurations, projects must have explicitly opted into the IR pipeline.
  2. Mutual Recursion Must Be Present: The contract must contain mutually recursive functions. This includes both standard Solidity function recursion and mutually recursive Yul functions defined within inline assembly blocks. Contracts lacking any form of mutual recursion cannot trigger the bug.
  3. Memory-Safe Inline Assembly: The stack-to-memory relocation only activates on code sections that the compiler deems memory-safe. Paradoxically, this means inline assembly blocks that are not explicitly annotated as memory-safe actually bypass the vulnerable relocation phase entirely.
  4. Compiler Version and Optimizer Settings: The vulnerable code path has been reachable across all compiler releases ranging from version 0.7.2 through 0.8.36. On versions spanning from 0.8.21 to 0.8.36, the stack-to-memory mover operates as an independent stage regardless of whether the optimizer is enabled. On earlier versions (0.7.2 through 0.8.20), the Yul optimizer must also be explicitly active via the --optimize flag to trigger the relocation mover.

Because these prerequisites must occur in tandem, the affected pattern is considered extremely rare in real-world decentralized applications.


Relation to Previous Spill Bugs and Ecosystem Safety

This vulnerability shares conceptual similarities with another recent compiler defect—the "Unsound Spill In Mutual Recursion Bug"—which was patched earlier in Solidity 0.8.36. That previous issue involved a misclassification flaw where certain mutually recursive functions were mistakenly treated as non-recursive, leading to illegal variable spilling inside recursive loops.

However, the newly disclosed bug is distinct. In this scenario, the compiler correctly identifies the recursive cycle and avoids spilling variables within the cycle itself. Instead, the failure occurs during the accounting of memory slot requirements for non-recursive functions that interact with the call graph. Consequently, this vulnerability persisted even in Solidity 0.8.36, remaining active until the release of version 0.8.37.

To gauge the real-world impact on deployed infrastructure, the Solidity development team collaborated with Sourcify to perform a comprehensive rescan of approximately 319,000 verified smart contracts. Each contract was recompiled using compiler builds both with and without the security patch. The analysis confirmed that none of the recompiled contracts produced differing bytecode outputs, verifying that no known deployed mainnet contracts were exposed to the bug.


The Solution and Recommended Actions

The core fix implemented in Solidity 0.8.37 restructures how the compiler analyzes call graphs during memory planning. Instead of performing a walk on a function-by-function basis, the updated allocator analyzes the call graph by Strongly Connected Components (SCCs)—grouping maximal sets of mutually recursive functions together while treating non-recursive functions as individual components.

Within this updated framework, members of a recursive cycle share a unified component-level evaluation, and internal recursive calls are ignored during slot requirement calculations because all necessary offsets are accounted for globally. Because SCCs form an acyclic graph, provisional caching anomalies are eliminated entirely, ensuring that every computed memory requirement is finalized and accurate.

Unlike the patch for the earlier spill bug—which occasionally caused strict builds to fail with "Stack too deep" errors—upgrading to Solidity 0.8.37 will not break existing successful builds. The fix solely corrects the calculation of reserved memory regions and slot assignments without imposing new structural compilation constraints. Additionally, the development team has introduced a new suite of property-based fuzz tests to continuously validate compiler behavior against random call graph generation.

Developers utilizing the --via-ir compilation pipeline are strongly advised to upgrade their projects to Solidity 0.8.37 immediately. Developers should also review their build environments to ensure that production deployments align with the patched compiler version.

Tagged: