On May 11, 2026, developer clonker from the core Solidity team identified a critical compiler bug within the Yul optimizer’s call graph analysis framework. The vulnerability, which has been assigned a medium severity rating on the internal scale, caused mutually recursive functions to be intermittently misclassified as non-recursive. Because of this flaw, these functions were mistakenly included in a memory-spilling optimization mechanism that is fundamentally incompatible with recursion.
The underlying optimization mechanism, known as the stack limit evader or stack-to-memory mover, is designed to work around the Ethereum Virtual Machine’s strict limit on stack depth, which only allows direct access to the topmost 16 stack slots. When a function’s simultaneously live local variables exceed this threshold, the compiler traditionally triggers a "stack too deep" error. To mitigate this constraint in the IR (Intermediate Representation) pipeline, the compiler relocates local variables to fixed memory offsets, substituting standard stack operations with explicit memory store and load instructions.
However, this stack-to-memory relocation strategy is only sound for functions that execute linearly without recursion. Because fixed memory offsets are shared statically across every single invocation of a given function, a recursive re-entry overwrites these slots during inner executions, leading to corrupted data when the outer activation attempts to read back its stored variables. To prevent this, the compiler must reliably exclude any function participating in a recursive call chain from the memory-spilling procedure.
The vulnerability strictly affects the IR-based compilation pipeline, meaning that projects relying on the legacy evmasm pipeline remain entirely unaffected. Furthermore, because the --via-ir compilation flag is not enabled by default in the Solidity toolchain, development teams that have not explicitly opted into the IR pipeline face no exposure.
Historical analysis conducted by the Solidity team reveals that the vulnerable code path has been reachable since Solidity version 0.7.2, though the exact triggering conditions vary across the affected range. Every version released from 0.7.2 through 0.8.35 contains the flaw. Fortunately, the issue has been fully resolved in Solidity version 0.8.36.
To gauge the real-world impact of the vulnerability, the Solidity team performed an automated scan of all smart contracts utilizing the --via-ir flag within the Sourcify database. Out of roughly 207,000 inspected contracts, only 272—representing approximately 0.1 percent of the total dataset—contained a function where the call graph analysis misclassified the recursion status. Crucially, a deeper inspection revealed that none of these specific contracts actually performed variable relocations to memory within the misclassified functions, confirming that no deployed smart contracts are known to have suffered active exploits or runtime corruption.
Which Contracts Are Affected?
A smart contract is vulnerable only if a very specific set of narrow conditions coincide during the compilation process. First and foremost, if a contract lacks mutual recursion entirely, it is completely immune to the bug. For a contract to be susceptible, it must utilize the IR pipeline via the --via-ir flag, involve complex functions with enough live variables to trigger stack-to-memory relocation, and contain mutually recursive cycles that the faulty cycle-detection algorithm fails to recognize.
The dependency of the bug on compiler settings also shifts across versions. From Solidity 0.8.21 onward, the vulnerability operates independently of whether the optimizer is explicitly enabled, because the stack-to-memory relocation stage runs as an independent component of the IR pipeline regardless of optimizer configurations. Consequently, simply disabling the optimizer does not shield code compiled with these later versions.
In contrast, across earlier affected versions spanning from 0.7.2 to 0.8.20, the Yul optimizer—and by extension the stack-to-memory mover—only executed when the --optimize flag was explicitly passed to the compiler. Triggering the bug in those legacy versions therefore required both the --via-ir flag and the optimization flag to be active simultaneously.
Technical Details and Root Cause
A deeper look into the compiler internals reveals how the flaw manifested within the architecture of the Solidity codebase. The faulty cycle-detection mechanism responsible for the misclassifications was originally introduced during a major compiler refactoring in version 0.6.12. At the time of its introduction, the code had only a single consumer, known as the SideEffectsPropagator, where any misclassification of recursion had no observable impact on the final generated bytecode.
The situation changed with the release of Solidity 0.7.2, which introduced a second consumer for the call graph data: the StackLimitEvader. Because this component actively relies on accurate recursion detection to determine whether memory spilling is safe, version 0.7.2 is marked as the beginning of the affected range. In practical testing, engineers could only reliably reproduce actual miscompilations starting from version 0.8.8, or from version 0.8.10 when utilizing the experimental --experimental-via-ir entry point. In older versions, test reproducers typically encountered a standard "stack too deep" compilation error before the unsound optimization behavior could manifest. While working reproducers could not be constructed below version 0.8.8, the development team conservatively classifies the entire span from 0.7.2 to 0.8.35 as potentially affected.
The root cause of the misclassification lies in a flaw within the CallGraphGenerator’s path-based depth-first search algorithm. To determine if a function is recursive, the compiler checks whether it belongs to a strongly connected component where functions can reach one another through cyclical call paths. The original traversal implementation maintained the current path on a stack, marking a function and all intermediate callees as recursive whenever it encountered an edge pointing back to an active node still present on the stack.
Once a function and its callees were fully explored, the algorithm popped the node from the path and added it to a permanent visited set, ensuring that any subsequent visits would short-circuit immediately. However, this short-circuiting logic proved unsound in the presence of intersecting cycles. If a function’s cyclical path could only be closed by passing through a node that had already been fully processed and marked as visited during an earlier, separate traversal, the algorithm prematurely halted its search at that finished node. As a result, the target function was erroneously reported as non-recursive despite genuinely participating in an active cycle.
Whether this flaw triggered depended heavily on the exact traversal order of the call graph’s internal data structures, which were determined by the name hashes of the Yul functions. Because altering function names changed the traversal sequence, some codebases successfully exposed the bug while identical logical structures with different naming conventions did not.
Impact on Generated Code and Illustrative Example
When a function is incorrectly marked as non-recursive, the compiler’s stack limit evader treats it as eligible for memory spilling if its local variables exceed the 16-slot stack limit. If the function is genuinely recursive, the re-entry into the function overwrites the fixed memory locations assigned to those local variables. When the outer activation resumes execution, it reads back corrupted data from those shared memory offsets instead of its original values.
The Solidity team provided a minimal reproducer contract to demonstrate the exact failure mode. The test case constructs a triangular call graph involving three internal functions, labeled a, b, and c, where every function can reach the others, forming a strongly connected component. Function c maintains 25 local variables live across a call to b, forcing the compiler to exceed addressable stack limits and relocate the function’s parameter m to a fixed memory slot. Because c is part of a recursive cycle, the inner invocation overwrites this memory slot, causing subsequent read operations to fail and returning an uninitialized state value rather than the expected runtime output.
Unlike many historical compiler vulnerabilities, this issue does not require the presence of inline assembly to manifest. Furthermore, the compiler emits no warning when the misclassification occurs, and the resulting bytecode does not trigger an explicit runtime revert. Instead, the corruption surfaces silently as incorrect application logic or unexpected numerical results during execution, making diagnosis challenging unless developers run comprehensive test suites under the --via-ir configuration prior to deployment.
The Fix and Recommended Actions
The vulnerability has been decisively resolved in Solidity 0.8.36. The fix completely replaces the flawed path-based depth-first search with Tarjan’s algorithm, a standard and mathematically rigorous approach for identifying strongly connected components in directed graphs.
Tarjan’s algorithm partitions the entire call graph in a single pass without depending on arbitrary traversal orders or name-hash-based sequencing. Under the updated compiler logic, a function is classified as recursive if and only if it is genuinely contained within a strongly connected component of size greater than one, or if it makes a direct recursive call to itself.
An important side effect of this robust fix is that some smart contracts that previously compiled successfully under older compiler versions may now fail with a "Stack too deep" error when upgraded to version 0.8.36. The Solidity team emphasizes that this new compiler behavior is entirely correct. Contracts that encounter this error were previously relying on unsound memory relocations that risked data corruption during recursive execution. Rather than silently generating unsafe bytecode, the updated compiler correctly identifies the underlying structural limitation, requiring developers to refactor their code to manage stack usage more efficiently.
Development teams utilizing the --via-ir compilation pipeline are strongly advised to upgrade their toolchains to Solidity 0.8.36 or later. Projects that make use of mutual recursion alongside complex local variable management should review their test suites thoroughly to ensure compatibility with the updated compiler analysis.

