18 Nov 2026, Wed

Solidity Team Discovers Medium-Severity Call Graph Bug in Yul Optimizer Affecting Versions 0.7.2 to 0.8.35

On May 11, 2026, developer clonker from the core Solidity team identified a critical underlying bug within the Yul optimizer’s call graph analysis framework. The vulnerability, which has been assigned a severity rating of medium on the internal scale, caused mutually recursive functions to be occasionally misclassified as non-recursive. Consequently, these functions were incorrectly included in a memory-spilling mechanism that is fundamentally incompatible with recursive code architecture.

The affected feature, known as the stack-to-memory mover or stack limit evader, is designed to combat the Ethereum Virtual Machine’s strict limitation on stack depth, which only permits direct access to the topmost sixteen stack slots. When a function accumulates a large number of simultaneously live local variables, it risks triggering a "Stack too deep" compilation error. To circumvent this, the IR (Intermediate Representation) pipeline automatically relocates selected local variables to fixed memory offsets, replacing direct stack operations with standard memory store and load instructions.

However, this optimization strategy is only sound for non-recursive functions. Because fixed memory offsets are shared globally across every invocation of a given function, a recursive call pattern introduces dangerous side effects. If a function maintains a value in a fixed memory slot across an execution call that subsequently re-enters the same function—either directly or through an intricate cycle of mutual recursion—the inner activation overwrites the designated slot. When control returns to the outer activation, the program reads back a corrupted value rather than its original local state. To prevent this, the compiler must exclude any function belonging to a recursive call chain from the memory-spilling mechanism.

The discovery revealed that the faulty cycle-detection logic failed to account for intersecting recursive cycles, leading to misclassifications. The bug is exclusively confined to the IR pipeline; the legacy evmasm pipeline remains entirely unaffected. Furthermore, because the crucial --via-ir compilation flag is not enabled by default, smart contract projects that have not explicitly opted into the IR-based pipeline are completely safe from the issue.

An extensive security scan performed across approximately 207,000 contracts utilizing the --via-ir flag within the Sourcify database uncovered only 272 contracts—representing roughly 0.1 percent of the total dataset—that contained a function misclassified by the flawed analysis. Crucially, none of these specific contracts actually relocated variables to memory inside the misclassified functions, meaning no deployed contracts are currently known to have suffered operational failures or financial losses due to this vulnerability.

Which Contracts Are Affected?

For a smart contract to be vulnerable to this specific compilation bug, a precise set of narrow conditions must align simultaneously, explaining why the problematic pattern remains exceptionally rare in real-world deployments. A contract is only affected if it utilizes the IR pipeline, incorporates mutual recursion involving complex functions with many live variables, and triggers the memory-spilling mechanism on a function that was erroneously marked as non-recursive by the faulty call graph analyzer. If a project does not make use of mutual recursion, it is completely immune to the issue.

The vulnerability spans a wide range of Solidity compiler versions, affecting all releases from 0.7.2 through 0.8.35. The issue has been officially resolved in Solidity 0.8.36.

The behavioral nuances of the bug shifted across compiler versions due to architectural updates. Starting with Solidity 0.8.21, the bug manifests independently of whether the optimizer is enabled. Because the stack-to-memory relocation runs as a distinct, mandatory stage of the IR pipeline regardless of user optimizer settings, simply disabling the optimizer does not provide a workaround on newer versions. Conversely, on earlier affected versions ranging from 0.7.2 to 0.8.20, the Yul optimizer—and by extension the stack-to-memory mover—only executes when the --optimize flag is explicitly passed. Consequently, triggering the bug on those older releases required both --via-ir and --optimize to be enabled simultaneously.

Technical Details and Root Cause

The historical roots of the flawed cycle-detection mechanism trace back to a major internal refactoring introduced in Solidity 0.6.12. At that time, the affected code interacted with only a single consumer, the SideEffectsPropagator, where any misclassification proved entirely benign and produced no observable runtime impact.

The first consumer where this misclassification carried real consequences arrived in version 0.7.2 with the introduction of the StackLimitEvader, marking 0.7.2 as the earliest affected version. While core developers were able to reliably reproduce the miscompilation behavior on versions from 0.8.8 onward—and from 0.8.10 through the experimental --experimental-via-ir entry point—earlier versions typically triggered a standard "Stack too deep" compilation error before the incorrect optimization behavior could surface. Although developers could not construct a working exploit reproducer below version 0.8.8, they could not formally prove the bug was entirely unreachable in those older releases, prompting a conservative classification of the entire 0.7.2 to 0.8.35 range as affected.

The underlying engineering flaw resided in the CallGraphGenerator component, which previously relied on a path-based depth-first search algorithm to detect recursion. During graph traversal, the algorithm maintained the active traversal path on an internal stack. Upon encountering an invocation of a function already present on that active path, it would designate that function—along with any intermediate functions called between the two invocations—as part of a recursive cycle. Once all calls originating from a function were fully explored, the function was popped from the path and added to a visited set, causing any subsequent visits to short-circuit immediately.

This short-circuit optimization proved fundamentally unsound when handling intersecting cycles. Because the traversal recorded a cycle exclusively when walking an edge back to a function still residing on the active path, finished nodes marked as visited 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 earlier, separate cycle traversal, the algorithm prematurely halted at the finished node before the second cycle could close. Consequently, the function was incorrectly reported as non-recursive, despite genuinely belonging to an active call graph cycle.

The exact manifestation of this bug heavily depended on the traversal order of the call graph’s internal data structures, which were dictated by the name hashes of the Yul functions. Variations in function naming altered this deterministic ordering, meaning two structurally identical contracts with different function names could yield entirely different analysis results regarding recursion.

Example and Observed Behavior

To demonstrate the vulnerability, developers constructed minimal contract examples featuring mutually recursive functions like a, b, and c, where function c maintains numerous local variables live across a call to b. Because c was misclassified as non-recursive, the compiler attempted to ease stack pressure by moving its local variable tracking m to a fixed memory offset.

When the contract executed, the nested recursive calls caused the inner activation of c to overwrite the shared memory slot assigned to m. When the outer activation attempted to read the variable back to finalize state updates, it retrieved corrupted data, leading to silent state corruption where variables were written to incorrect indices or assigned unintended values. In testing scenarios, functions that should have returned specific operational parameters instead returned untouched initial default values without triggering any runtime reverts or compiler warnings.

The Fix and Recommended Actions

The core development team resolved the vulnerability by replacing the flawed path-based depth-first search with Tarjan’s algorithm, a well-established and robust standard algorithm for identifying strongly connected components within directed graphs. Tarjan’s algorithm partitions the call graph in a single deterministic pass, independent of traversal order, ensuring that any function participating in a cycle is accurately classified as recursive.

Following the upgrade to Solidity 0.8.36, developers may occasionally encounter "Stack too deep" errors on contracts that previously compiled successfully under older versions. The Solidity team emphasizes that this represents the correct, expected behavior. Projects experiencing this post-upgrade compilation failure were previously relying on unsound, hazardous memory relocations that silently generated corrupted bytecode.

Developers maintaining projects utilizing the IR pipeline are strongly advised to update their compiler toolchains to Solidity 0.8.36 or later, thoroughly review their test suites, and ensure that contracts employing mutual recursion compile correctly without relying on unsafe memory-spilling optimizations.

Leave a Reply

Your email address will not be published. Required fields are marked *