The Ethereum Foundation and the Solidity development team have officially disclosed a low-to-medium severity bug within the intermediate representation (IR) pipeline’s stack-to-memory mover—widely known as the "stack limit evader." Discovered and responsibly reported by researcher Ng Sze Hon via the Ethereum Foundation bug bounty program, the vulnerability poses a silent data-corruption risk under very specific architectural conditions, including mutual recursion and complex local variable layouts. While a comprehensive rescan of verified contracts on Sourcify indicates that no currently deployed mainnet contracts are affected, developers utilizing vulnerable compiler versions are strongly advised to upgrade to Solidity 0.8.37 immediately.
Understanding the Mechanism: The Stack-to-Memory Mover
To fully grasp the nature of this compiler vulnerability, one must look closely at how the Ethereum Virtual Machine (EVM) manages data execution limits. The EVM restricts direct stack access to a maximum of the topmost sixteen stack slots. When a Solidity function contains a high number of simultaneously live local variables, it routinely exceeds this strict limit, triggering the well-known "Stack too deep" compilation error.
To bypass this roadblock and allow developers to write more complex, expressive code without constantly refactoring variable scopes, the Solidity IR pipeline utilizes a dedicated feature referred to as the stack limit evader. This system intelligently
selects specific affected local variables and rewrites their access patterns into standard memory operations (mstore and mload), effectively spilling them into fixed memory offsets known as "spill slots." These slots reside inside a reserved memory region at the very beginning of EVM memory, the size of which is communicated to the Yul optimizer using the memoryguard builtin function.
Because these spill slots are designed to be shared across multiple function activations to conserve memory space, the compiler must enforce strict rules. Specifically, a function must never reuse a spill slot belonging to any of its active callers, because those callers’ spilled variables remain actively live while the child function executes. Furthermore, recursive functions have historically been strictly excluded from this spilling mechanism, as sharing slots across recursive frames would immediately corrupt data.
The Root Cause: Mutual Recursion and Slot Allocation Undercounts
The vulnerability uncovered by Ng Sze Hon involves a flaw in how the compiler’s slot allocator traverses the call graph to calculate memory requirements. Under normal operational circumstances, the slot allocator conducts a depth-first search through the call graph to determine how many spill slots a function and its callees collectively require. To prevent this traversal from descending into infinite loops when encountering recursive call chains, the allocator writes a provisional requirement value of zero into its cache upon entering a function, updating it to the true calculated requirement only after all child callees have been fully explored.
The bug manifests when the traversal mechanism reads that provisional zero value as if it were a final, absolute requirement. If a function is revisited through a cyclical path of mutual recursion, it encounters the cached zero instead of the true required value of the function it calls. Consequently, an incorrect, undercounted slot requirement gets finalized and cached. This undercount then propagates upward to subsequent callers, eventually resulting in two different functions being assigned the exact same physical spill slot even though their respective variables can be simultaneously live.
When this happens, one variable is silently overwritten by the other during contract execution. The affected smart contract computes, stores, and processes values that the original source code never explicitly assigned. Because the compiler emits no warning and the EVM does not trigger a runtime revert, the failure presents itself purely as silent, incorrect state data, making it exceptionally difficult to diagnose without targeted automated testing or property-based fuzzing.
Relationship to Previous Vulnerabilities and Affected Versions
This newly disclosed bug shares conceptual similarities with the "Unsound Spill In Mutual Recursion Bug" that was previously patched in Solidity 0.8.36, yet it remains distinctly different. The earlier bug was fundamentally a classification error wherein faulty cycle detection caused certain mutually recursive functions to be incorrectly treated as non-recursive, leading to illegal spilling inside recursive routines.
In contrast, the bug identified in the current disclosure involves correct classification—the recursive cycle members are properly identified and do not have their own variables spilled—but the slot allocation logic fails because of the provisional cache-reading flaw. Consequently, this vulnerability remains fully present even in Solidity 0.8.36, which successfully incorporated the fix for the previous issue.
The vulnerable code path has technically been reachable in the compiler since the introduction of the stack limit evader in version 0.7.2. Every release from Solidity 0.7.2 through 0.8.36 is theoretically affected, though the exact conditions required to trigger it vary across version ranges. For instance, on compiler versions 0.8.21 and later, the bug manifests independently of the optimizer setting because the stack-to-memory mover runs as an independent stage of the IR pipeline. On older versions ranging from 0.7.2 through 0.8.20, reaching the bug requires both the --via-ir flag and the --optimize flag to be explicitly enabled, as the Yul optimizer was previously tied directly to the optimizer configuration.
Strict Conditions Required for Exploitation
Despite the wide range of affected compiler versions, the practical likelihood of encountering this bug in the wild is extremely low. A smart contract is vulnerable only if a precise combination of architectural and environmental conditions is simultaneously met.
First, the contract must be compiled using the experimental IR-based code generator via the --via-ir flag, which is not enabled by default in standard developer toolchains. Second, the contract must contain mutually recursive functions—either written natively in Solidity or defined within inline assembly assembly blocks using Yul. Third, the code must be considered memory-safe by the compiler, meaning that contracts containing unannotated, raw inline assembly blocks that lack the explicit memory-safe designation are structurally insulated from this specific relocation pipeline stage. Finally, the call graph must feature the precise topological configuration required to trigger the slot allocation undercount during traversal.
To determine the real-world impact of the vulnerability, the Solidity team performed a comprehensive rescan of the Sourcify database, recompiling approximately 319,000 verified smart contracts using compiler builds both with and without the security patch. The analysis confirmed that none of the verified contracts compiled into differing bytecode when subjected to the patched compiler, verifying that no known deployed mainnet contracts have been actively compromised by this flaw.
The Permanent Fix and Recommended Actions
To permanently resolve the issue, the Solidity development team has refactored the compiler’s call graph traversal algorithm. Instead of performing slot allocation walks on a per-function basis, the updated compiler processes code per strongly connected component (SCC) of the call graph—representing maximal sets of mutually recursive functions, with non-recursive functions treated as single-element components.
Within this new architecture, calls between members of the same recursive component are entirely ignored during the traversal walk, because any memory requirements needed by the callees are already factored into the component’s aggregate total. Because the resulting components form a strictly acyclic graph, a component can never be revisited while it is actively being processed, completely eliminating provisional zero values and ensuring that all cached requirements are finalized accurately. Furthermore, the fix is fortified by new property-based fuzz tests designed to generate random call graphs and continuously verify program execution consistency.
Developers maintaining Ethereum smart contracts are encouraged to review their build pipelines to verify whether they rely on the --via-ir compilation flag. Projects utilizing vulnerable compiler versions between 0.7.2 and 0.8.36 that incorporate mutual recursion should upgrade to Solidity 0.8.37 at the earliest opportunity. Upgrading will safely adjust the internal reservation sizing and slot assignments without breaking builds or triggering unexpected "Stack too deep" compilation errors.






