A critical software flaw affecting the Intermediate Representation (IR) compilation pipeline in the Solidity programming language has been officially disclosed. Discovered and reported by security researcher Ng Sze Hon via the Ethereum Foundation’s bug bounty program on July 30, 2026, the vulnerability involves a subtle memory management error within the compiler’s stack-to-memory mover—informally known as the "stack limit evader."
The vulnerability, formally categorized by the Solidity development team with a low/medium internal severity rating, stems from how the compiler allocates temporary storage spaces known as "spill slots" during recursive function calls. Because of the flaw, variables belonging to two completely distinct functions can inadvertently be assigned the same physical spill slot when mutual recursion is present in the call graph. This overlap occurs even if both variables remain active simultaneously at runtime. Consequently, one local variable can be silently overwritten by another, causing the smart contract to calculate, process, and permanently store erroneous values that were never explicitly defined in the original source code.
Despite the potentially severe implications of silent data corruption in smart contracts, developers have been reassured by subsequent investigations. A comprehensive rescan of approximately 319,000 verified smart contracts indexed in the Sourcify database revealed that none of the compiled bytecodes changed when built with compiler versions featuring the fix. This indicates that no known deployed contracts in the wild have been compromised or affected by this specific issue. Furthermore, the vulnerability is strictly contained within the IR compilation pipeline; the legacy evmasm pipeline remains completely unaffected, and projects that have not explicitly opted into the --via-ir compilation flag face no exposure.
Understanding the Root Cause: The Stack Limit Evader and Mutual Recursion
To fully grasp the nature of the bug, it is necessary to examine how the Ethereum Virtual Machine (EVM) handles local variables and stack limitations. The EVM architecture restricts low-level stack operations, allowing direct access to no more than the topmost 16 stack slots. When a smart contract function contains a high number of simultaneously active local variables, it inevitably exceeds this structural boundary, triggering the familiar and frustrating "Stack too deep" compiler error.
To circumvent this restriction and enable the compilation of complex logic, the Solidity IR pipeline employs a mechanism called the stack-to-memory mover. This system intelligently identifies overwhelmed variables and rewrites their access patterns, migrating them away from the EVM stack and into designated fixed memory offsets referred to as spill slots. These slots are allocated within a specialized, reserved region situated at the very beginning of memory. The exact size of this reserved storage area is communicated to the Yul optimizer via a built-in function called memoryguard.
Ordinarily, to optimize memory usage, the compiler allows distinct functions that can never be active at the same time to share a single spill slot. However, a strict safety invariant must be maintained: a function can never safely reuse a slot belonging to any of its active callers, because the callers’ spilled variables remain live while a callee executes. To enforce this, the compiler’s slot allocator conducts a depth-first traversal of the call graph. It calculates the cumulative slot requirements for every function and caches the results to avoid redundant calculations.
The flaw arises in how this traversal manages cyclical call structures, specifically mutual recursion. To prevent the allocator from descending indefinitely into infinite loops along recursive chains, the algorithm writes a provisional placeholder value of zero into the cache when it first encounters a function. This provisional zero is supposed to be overwritten with the true calculated requirement once all downstream callees are fully explored.
However, the traversal logic can mistakenly read this provisional zero as a finalized value. When a function is revisited through a cyclical path, it encounters the zero rather than the actual requirement of the function it calls. This premature, inaccurate value is then finalized and cached, propagating an undercount to all subsequent callers—including parts of the contract entirely unrelated to the recursive cycle. Consequently, the compiler under-allocates the reserved memory region, causing independent functions to share the exact same spill slot and overwrite each other’s data during execution.
Precise Conditions Required for Exploitation
While the bug has existed in the codebase since the introduction of the stack limit evader in Solidity 0.7.2, triggering it in a real-world environment is exceptionally difficult. A smart contract is only vulnerable if a very specific set of compounding conditions are met simultaneously.
First, the contract must be compiled using the IR pipeline via the --via-ir flag. Second, the code must contain mutually recursive functions—either defined explicitly within the Solidity source or implicitly via inline assembly blocks within a assembly block, as the compiler evaluates recursion based on the generated Yul code rather than high-level syntax. Third, the code must be memory-safe, meaning that stack-to-memory relocation routines are actively permitted to run. Counterintuitively, contracts containing unannotated, non-memory-safe inline assembly bypass these relocation routines entirely and remain immune.
Finally, compiler version specifics dictate whether optimizer settings play a role. From Solidity version 0.8.21 onward, the stack-to-memory relocation runs independently of the optimizer settings, meaning that disabling the optimizer will not evade the bug. In contrast, for older affected versions spanning 0.7.2 through 0.8.20, the Yul optimizer and its stack mover only execute when the --optimize flag is explicitly enabled. In all scenarios, however, vulnerability is determined strictly by the compilation flags used to build the deployed bytecode, rather than configurations used during local testing or continuous integration pipelines.
Relationship to Previous Spilling Vulnerabilities
This newly disclosed bug is closely related to, yet distinct from, another critical flaw patched recently in Solidity 0.8.36, known as the "Unsound Spill In Mutual Recursion Bug." That earlier issue was fundamentally a classification failure wherein faulty cycle detection caused certain mutually recursive functions to be incorrectly treated as non-recursive. As a result, the compiler improperly spilled variables belonging to recursive functions—a direct violation of the foundational rule that recursive functions must never have spilled variables.
In contrast, the newer bug involves correct function classification. In this scenario, the cycle members are properly identified as recursive and correctly avoid having their own variables spilled. Instead, the failure lies entirely in slot allocation arithmetic: two completely non-recursive variables that happen to be live concurrently are assigned to the same spill slot due to the propagation of provisional cache undercounts. Because the root causes and violated invariants differ, this second bug persists even in compiler versions like 0.8.36 that successfully implemented the patch for the earlier spilling flaw.
The Permanent Solution and Recommended Actions
The Solidity core development team has formally addressed the vulnerability with the release of Solidity version 0.8.37. The fix fundamentally alters how the compiler’s call graph traversal operates. Instead of evaluating dependencies on a per-function basis, the updated allocator processes the call graph by Strongly Connected Components (SCCs)—representing maximal sets of mutually recursive functions, with non-recursive functions each forming an independent component of their own.
Within an SCC, every member can reach all others, meaning no individual member can maintain a private slot budget; instead, the entire component is sized as a single cohesive unit. Slot requirements are calculated and cached per component, and internal calls between members of the same component are ignored during the walk since their requirements are already bundled into the collective total. Because these components form a strictly acyclic graph at the macro level, a component can never be revisited while it is still actively being processed. This eliminates provisional values entirely, ensuring that every cached requirement is final and accurate.
Additionally, the development team has reinforced the compiler’s testing infrastructure by introducing a new property-based fuzz test suite. This testing mechanism automatically generates random, complex call graphs to rigorously compare program behavior both before and after variable spilling occurs, safeguarding against future regressions.
Security teams and smart contract developers maintaining projects built with Solidity versions 0.7.2 through 0.8.36 are strongly advised to audit their codebases for the presence of mutual recursion paired with the --via-ir compilation flag. The definitive remediation step is to upgrade the Solidity compiler toolchain to version 0.8.37 or later. Because the patch corrects slot sizing and memory offsets without altering valid compilation constraints, upgrading will not introduce unexpected "Stack too deep" build failures in contracts that already compile successfully.






