Home / Smart Contract Auditing / Solidity Developers Urged to Update as Bug in Yul Optimizer Call Graph Analysis Discovered

Solidity Developers Urged to Update as Bug in Yul Optimizer Call Graph Analysis Discovered

On May 11, 2026, the Solidity development team announced the discovery of a medium-severity bug within the Yul optimizer’s call graph analysis framework. Identified internally by team member clonker, the software flaw led to a situation where mutually recursive functions were occasionally misclassified as non-recursive. Because of this misclassification, these functions failed to be properly excluded from the compiler’s memory spilling mechanism—a crucial safety feature designed to be entirely incompatible with recursive function calls.

The memory spilling mechanism, often referred to as the stack limit evader, exists to combat the Ethereum Virtual Machine’s strict limitation on stack depth, which only allows direct access to the topmost 16 stack slots. When a function’s simultaneously live local variables exceed this capacity, the compiler normally reports a "Stack too deep" error. To circumvent this and reduce compilation failures, the IR (Intermediate Representation) pipeline includes a stack-to-memory mover. This subsystem relocates certain local variables to fixed memory offsets and substitutes standard stack references with low-level memory operations such as mstore and mload.

However, this optimization technique is only mathematically sound for functions that completely lack recursion. Because fixed memory offsets are shared across every single activation of a given function, a recursive invocation creates a dangerous overlap. If a function holds a value in a designated memory slot across an internal call that eventually re-enters the same function—either directly or through an intricate cycle of calls—the inner activation will overwrite that memory slot. Consequently, when the outer activation attempts to read the variable back, it retrieves corrupted data. To prevent this, the compiler relies on accurate call graph analysis to ensure recursive functions never undergo stack-to-memory relocation.

The recently uncovered bug compromises this safety guarantee. Assigned a medium severity rating on the internal scale of the Solidity team, the issue exclusively affects the modern IR pipeline. The legacy evmasm pipeline remains entirely unaffected. Furthermore, because the --via-ir compilation flag is not enabled by default in Solidity projects, developments or smart contracts that have not explicitly opted into using the IR pipeline are completely safe from the vulnerability.

Historical analysis of the compiler codebase reveals that the affected code has technically been reachable since the release of Solidity version 0.7.2. However, the precise conditions required to trigger the miscompilation vary across the version range. Every version of Solidity released from 0.7.2 through 0.8.35 contains the vulnerable code paths. The issue has been formally addressed and resolved in Solidity version 0.8.36.

To gauge the real-world impact of the vulnerability, the development team conducted a comprehensive automated scan of all smart contracts utilizing the --via-ir flag stored within the Sourcify database. Out of roughly 207,000 scanned contracts, the analysis identified 272 contracts—accounting for approximately 0.1 percent of the total sample—that contained at least one function misclassified by the flawed graph analysis. Crucially, further investigation confirmed that none of these specific contracts actually relocated variables to memory inside the misclassified functions. As a result, the Solidity team has no record of any deployed production contracts being actively compromised by the bug.

Understanding which contracts are potentially vulnerable requires looking at a very specific conjunction of circumstances. A smart contract is only affected if multiple narrow conditions are met simultaneously, which explains why the vulnerable pattern remains exceptionally rare in real-world decentralized applications. If a contract contains no mutual recursion whatsoever, it cannot be affected by the bug.

The relationship between the compiler settings and the bug also evolved across different Solidity versions. From version 0.8.21 onward, the vulnerability operates independently of whether the developer explicitly enables the optimizer. Because the stack-to-memory relocation operates as a distinct phase of the modern IR pipeline that runs regardless of optimizer configurations, disabling the optimizer does not mitigate the risk on these newer versions. Conversely, on earlier affected versions spanning from 0.7.2 to 0.8.20, the Yul optimizer—and by extension the stack-to-memory mover—only activates when the --optimize flag is passed. Reaching the bug on those legacy versions required both the --via-ir flag and the --optimize flag to be active simultaneously.

A deeper examination of the compiler internals highlights the root cause of the flaw within the CallGraphGenerator component. A function is mathematically recursive if and only if it resides within a cycle in the call graph, meaning it either calls itself directly or belongs to a strongly connected component where all functions can mutually reach one another. Prior versions of the compiler computed this graph topology using a path-based depth-first search algorithm. While traversing the graph, the algorithm maintained the active path on a stack. Whenever it encountered an invocation pointing to a function already present on that active stack, it would designate that function and all intermediate callers as being part of a cycle. Once a function and its callees were fully explored, the node was popped and added to a visited set, ensuring any future visits would immediately short-circuit.

This short-circuiting mechanism proved to be fundamentally unsound when dealing with intersecting cycles. Because the traversal only recorded a cycle when encountering an edge pointing backward to a node currently active on the path stack, and because fully explored nodes were permanently marked as visited and skipped, complex topologies could break the logic. 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, the traversal would halt prematurely at that finished node before the second cycle could close. Consequently, the compiler would incorrectly report the function as non-recursive, despite it genuinely residing within a cycle.

Whether this flawed behavior manifests depends heavily on the traversal order of the call graph. The sequence in which callees are visited is dictated by the internal data structures of the graph, which in turn are determined by the cryptographic name hashes of the Yul functions. Different function names alter this traversal order, meaning the bug’s presence is intricately tied to the structural naming conventions within a contract’s IR output.

When a misclassification does occur, it only results in a functional error if the stack-to-memory mover targets the specific function the analysis misidentified. If the function is simple enough to fit its variables within the EVM stack limits, the generated code remains correct. However, if the function is complex enough to exceed the 16-slot threshold, the compiler mistakenly treats it as non-recursive and relocates its local variables to fixed memory offsets. Because the function is actually recursive, re-entering it overwrites those shared memory slots, causing outer activations to read corrupted data upon return.

The Solidity team has completely resolved the vulnerability in version 0.8.36 by replacing the flawed path-based depth-first search with Tarjan’s strongly connected components algorithm, a standard and robust graph theory approach. Tarjan’s algorithm partitions the call graph in a single pass without relying on traversal order, reliably identifying all recursive functions.

An important side effect accompanies upgrading to the patched compiler version. Because older compiler versions silently and incorrectly relocated the variables of certain recursive functions to memory, some contracts managed to compile successfully despite containing structural flaws. With Tarjan’s algorithm correctly identifying these functions as recursive, the compiler now leaves their variables on the stack. If those variables exceed the EVM’s 16-slot limit, the compiler will now emit a "Stack too deep" compilation error.

The Solidity team emphasizes that this new compiler behavior is entirely correct. Recursive functions cannot be safely compiled by spilling variables to a shared, fixed-size memory area. Contracts that fail to compile with a "Stack too deep" error after upgrading to version 0.8.36 were technically miscompiled by older compiler versions, and the new release surfaces the underlying structural issue rather than generating potentially corrupted bytecode. Developers are strongly encouraged to upgrade their toolchains to Solidity 0.8.36, review any newly surfaced compilation errors, and thoroughly test their smart contract test suites using the IR pipeline before deploying updates to production networks.

Tagged:

Leave a Reply

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