The Solidity development team has officially released version 0.8.36, resolving a medium-severity compiler bug that could cause incorrect code generation in specific smart contracts utilizing mutual recursion via the IR-based code generation pipeline. Discovered internally on May 11, 2026, by team member clonker, the vulnerability affects the Yul optimizer’s call graph analysis, potentially misclassifying mutually recursive functions as non-recursive under narrow, complex conditions.
While the bug’s scope is restricted to the Intermediate Representation (IR) pipeline—leaving the legacy evmasm pipeline completely unaffected—it
highlights the complex challenges compilers face when optimizing Ethereum Virtual Machine (EVM) bytecode. Because the --via-ir compilation flag is not enabled by default, projects that have not explicitly opted into the IR pipeline face zero exposure. However, for development teams leveraging modern compiler features, understanding the nature of this bug and upgrading to Solidity 0.8.36 is a crucial step in maintaining smart contract security and correctness.
Understanding the Scope and Affected Versions
The root cause of the vulnerability traces back to a refactor introduced in version 0.6.12, which added a faulty cycle detection mechanism. Initially, this mechanism was consumed exclusively by the SideEffectsPropagator, where any misclassification had no observable impact on the compiled output. However, with the arrival of Solidity 0.7.2, a new consumer emerged in the form of the StackLimitEvader, also known as the stack-to-memory mover. Consequently, Solidity versions 0.7.2 through 0.8.35 are considered affected by the bug.
Despite the broad version range, triggering the miscompilation requires a very specific combination of factors. A comprehensive scan of approximately 207,000 contracts utilizing the --via-ir flag within the Sourcify database identified only 272 contracts—roughly 0.1% of the scanned corpus—containing a function misclassified by the call graph analysis. Furthermore, none of those deployed contracts actually relocated variables to memory inside the misclassified function, meaning no known production contracts suffered exploitation or live failure due to this vulnerability.
To meet the criteria for being affected, a smart contract must satisfy multiple narrow conditions simultaneously. Most importantly, the codebase must feature mutual recursion. If a contract lacks mutual recursion entirely, it is completely immune to the bug. On Solidity versions 0.8.21 and later, the bug operates independently of whether the optimizer is enabled, because the stack-to-memory relocation runs as a distinct stage of the IR pipeline regardless of user settings. For earlier affected versions spanning from 0.7.2 to 0.8.20, however, triggering the stack-to-memory mover required passing both --via-ir and --optimize, adding another barrier to accidental exposure.
Technical Details Behind the Call Graph Analysis Bug
To appreciate how the vulnerability manifests, one must look at how the EVM handles data storage during execution. The EVM can only directly access the topmost 16 stack slots. When a Solidity function declares a large number of simultaneously live local variables, it frequently exceeds this hardware limit, historically resulting in the familiar "Stack too deep" compilation error.
To mitigate this limitation, the IR pipeline incorporates a stack-to-memory mover. When a function’s variables cannot fit on the stack, the compiler relocates selected variables to fixed memory offsets, substituting standard stack operations with mstore and mload instructions targeting those specific memory slots.
Crucially, this memory relocation strategy is only sound for functions that are strictly non-recursive. Because fixed memory offsets are shared across every single activation of a given function, a recursive invocation presents a severe hazard. If a function holds a variable in a fixed memory slot across an external or internal call that subsequently re-enters the same function—either directly or through a multi-step cycle—the inner activation will overwrite the memory slot. When execution returns to the outer activation, it reads back corrupted data instead of its original local variable state.
To prevent this corruption, the compiler builds a Yul call graph and executes a cycle-detection algorithm to identify every function involved in recursion, explicitly exempting them from the memory spilling mechanism. The vulnerability in previous compiler versions lay within this cycle-detection logic, which relied on a path-based depth-first search implemented inside the CallGraphGenerator.
During traversal, the algorithm maintained the current path on a stack. When it encountered an invocation of a function already present on that active stack, it marked that function—along with any intermediate functions called between the two invocations—as participating in a cycle. Once all calls within a function were fully explored, the node was popped from the active path and added to a permanent visited set, causing any subsequent visits to short-circuit immediately.
This short-circuiting behavior proved fundamentally unsound when intersecting cycles were present in the call graph. Because finished nodes were never re-entered, if a function’s recursive cycle could only be closed by passing through a node that had already been marked as finished during an unrelated, earlier cycle search, the traversal halted prematurely. The algorithm would then incorrectly report the function as non-recursive, despite it genuinely sitting on a cyclic path.
Code Generation Effects and Real-World Implications
When the compiler misclassifies a recursive function as non-recursive, it opens the door for dangerous optimizations. If the misclassified function is simple, no variables are relocated, and the resulting code functions correctly. However, if the function is complex enough to exceed the EVM stack limit, the stack-to-memory mover steps in, treating the recursive function as if it were entirely safe to optimize.
Because the function actually participates in a recursive cycle, re-entry overwrites the fixed memory offsets assigned to local variables. The outer activation subsequently reads the corrupted memory value, leading to silent calculation errors, unexpected state modifications, or corrupted return values rather than an immediate transaction revert. This characteristic makes diagnosing the bug uniquely challenging, as affected code fails quietly unless comprehensive test suites specifically validate the affected execution paths under the IR pipeline.
The Solidity team constructed minimal reproducers to demonstrate this behavior clearly. In a representative contract featuring an interconnected cycle among three internal functions—traditionally labeled a, b, and c—function c could be erroneously flagged as non-recursive depending on traversal order. Because traversal order is dictated by internal data structure arrangements derived from Yul name hashes, the presence of the bug depends heavily on the specific naming and structural topology of the call graph.
In tests reproducing the issue, calling a trigger function that executed the misclassified recursive cycle resulted in storage variables retaining their initial default values rather than updating correctly, demonstrating how corrupted stack-to-memory offsets altered program execution without triggering an explicit runtime revert.
The Fix and Transition to Tarjan’s Algorithm
With the release of Solidity 0.8.36, the compiler replaces the flawed path-based depth-first search with a robust, industry-standard algorithm for identifying strongly connected components: Tarjan’s strongly connected components algorithm.
Tarjan’s algorithm partitions the call graph in a single pass without relying on traversal order, ensuring that cycle detection is entirely deterministic and immune to node ordering variations or intersecting cycle blind spots. Under the updated compiler logic, a function is classified as recursive if and only if it truly belongs to a strongly connected component containing cycles. As a result, functions like those in the illustrative multi-step recursion examples are correctly identified as recursive, and the stack-to-memory mover appropriately leaves their local variables on the stack.
An important side effect of this fix involves contracts that previously compiled successfully only because the compiler performed an unsound memory relocation. Once the compiler correctly recognizes a function as recursive, it refuses to apply unsafe memory spilling. If those functions still exceed the 16-slot EVM stack limit, the compiler will now emit a "Stack too deep" error.
While encountering a new compilation error after an upgrade can be frustrating, the Solidity team emphasizes that this is the correct and safe behavior. Code that fails to compile post-upgrade was silently generating flawed, miscompiled bytecode under older versions. Surfacing the "Stack too deep" error exposes the underlying architectural limitation, forcing developers to refactor their smart contracts safely rather than relying on broken compiler optimizers.
Recommended Actions for Developers
Smart contract development teams utilizing the Solidity compiler are strongly encouraged to evaluate their build configurations and adopt the latest release. Projects that rely on the experimental or production IR pipeline (--via-ir) should update their toolchain to version 0.8.36 immediately to ensure call graph analysis correctness.
Developers who encounter new "Stack too deep" compilation errors after upgrading should review their recursive function designs, break down overly complex functions into smaller modular components, or adjust local variable scopes to fit within EVM stack limits naturally. By adopting Solidity 0.8.36, teams eliminate exposure to unsound memory spilling in mutually recursive functions and ensure their decentralized applications operate on reliably compiled bytecode.

