The Ethereum Foundation and the Solidity core development team have officially announced the release of Solidity 0.8.37, addressing a newly discovered low-to-medium severity vulnerability within the Intermediate Representation (IR) compilation pipeline. Reported responsibly by security researcher Ng Sze Hon through the Ethereum Foundation bug bounty program on July 30, 2026, the issue involves a subtle stack-to-memory allocation flaw that could lead to silent variable overwrites under specific conditions involving mutual recursion.
While the bug has existed across multiple compiler versions spanning several years, extensive scanning of verified smart contract deployments indicates that no known mainnet contracts have been compromised. Nevertheless, developers utilizing the modern IR pipeline are strongly advised to update their toolchains immediately to mitigate any theoretical risk.
Understanding the Stack-to-Memory Mover and the Root Cause
To comprehend the nature of this security advisory, one must look closely at how the Ethereum Virtual Machine (EVM) operates. The EVM restricts direct stack manipulation to the topmost 16 slots. When a Solidity contract contains functions with a high volume of simultaneously live local variables, it traditionally triggers the familiar "Stack too deep" compiler error.
To overcome this structural limitation, the Solidity IR pipeline incorporates a feature known as the stack-to-memory mover, frequently referred to as the "stack limit evader." This optimization mechanism selectively relocates—or "spills"—affected local variables into fixed memory locations designated as spill slots. These fixed offsets are reserved in a dedicated region at the very beginning of the memory space, with the exact boundaries communicated to the Yul optimizer via the memoryguard builtin.
Because spill slots are designed to be reused across different function executions to conserve memory, the compiler must ensure that two variables whose lifespans overlap are never assigned to the same slot. Functions that are recursive are naturally barred from this optimization because their self-referencing activations would inevitably collide. However, managing mutual recursion—where function A calls function B, and function B calls function A—presents a far more complex challenge for static analysis.
The bug reported by Ng Sze Hon stems from a flaw in how the compiler’s slot allocator calculates memory requirements while traversing the call graph. During compilation, the allocator conducts
a depth-first search, caching the slot requirements of each function. To prevent infinite loops when encountering recursive cycles, the algorithm writes a provisional value of zero into the cache upon entering a function, updating it to the true calculated requirement only after all callees have been fully explored.
The core failure occurred because the traversal mechanism could prematurely read that provisional zero as a final value when a cycle looped back onto a function currently under evaluation. This undercount systematically propagated to subsequent callers, resulting in a reserved memory region that was too small. Consequently, distinct variables from entirely different functions could be allocated to the exact same physical spill slot. At runtime, as execution flowed through the call graph, one variable would silently overwrite another, causing the smart contract to compute and store unexpected data that the original source code never specified.
Which Contracts Are Affected?
Despite the technical complexity of the underlying compiler defect, the practical likelihood of encountering this bug in real-world applications is exceptionally low. A smart contract is vulnerable only if a precise combination of architectural conditions is met simultaneously.
First and foremost, the contract must be compiled using the IR pipeline via the --via-ir flag, which is not enabled by default in standard Solidity configurations. Projects relying entirely on the legacy evmasm pipeline are completely immune.
Secondly, the codebase must feature mutually recursive functions. Contracts lacking mutual recursion—whether written natively in Solidity or implemented via inline assembly blocks—cannot trigger the slot undercount. Furthermore, the stack-to-memory relocation phase exclusively targets code blocks that the compiler recognizes as memory-safe. Ironically, this means that contracts containing unannotated inline assembly that lacks explicit memory-safe designations are entirely unaffected by the bug.
Depending on the compiler version, optimizer settings also play a role. From Solidity 0.8.21 onward, the stack-to-memory mover operates as an independent stage of the IR pipeline regardless of whether the optimizer is enabled, meaning disabling optimization does not bypass the issue. In contrast, for older affected versions ranging from 0.7.2 to 0.8.20, the Yul optimizer—and by extension the stack-to-memory mover—only runs when the --optimize flag is explicitly passed.
Scope of Affected Versions and Sourcify Analysis
The vulnerable code path has technically been reachable in the compiler since version 0.7.2, coinciding with the initial introduction of the stack limit evader. Every subsequent release up through Solidity 0.8.36 contains the flaw. Notably, this issue is entirely distinct from the "Unsound Spill In Mutual Recursion Bug" that was patched in Solidity 0.8.36. While that prior incident involved misclassifying recursive functions as non-recursive, the newly discovered bug involves correct classification paired with flawed slot budgeting. Consequently, even projects running Solidity 0.8.36 remain susceptible if they meet the aforementioned recursion and IR criteria.
To assess the real-world impact of the vulnerability, the Solidity development team performed a comprehensive rescan of the Sourcify database, recompiling approximately 319,000 verified smart contracts using compiler builds both with and without the patch. The analysis revealed that none of the tested contracts compiled into differing bytecode versions, confirming that no known deployed mainnet contracts were actively affected by the compiler flaw.
The Solution in Solidity 0.8.37
Solidity 0.8.37 permanently resolves the slot-allocation bug by fundamentally altering how the compiler’s call graph analyzer handles recursion. Rather than evaluating functions on an individual basis, the updated algorithm performs its traversal across strongly connected components (SCCs) of the call graph. A strongly connected component represents a maximal set of mutually recursive functions, while non-recursive functions naturally form independent single-node components.
Within an SCC, every member function can reach all other members, eliminating the possibility of maintaining a private slot budget for individual cycle participants. Instead, the entire component is evaluated and sized collectively as a single unit. Because the resulting components form an strictly acyclic graph, the compiler can never re-enter a component while it is still actively undergoing processing. This architectural change eliminates provisional cache readings, ensuring that all slot requirements are fully calculated and finalized before allocation.
Furthermore, the Solidity team has reinforced the compiler’s test suite by introducing new property-based fuzz tests designed to generate random, complex call graphs and rigorously verify program execution behavior both before and after variable spilling occurs.
Because the fix merely corrects the sizing of the reserved memory region and adjusts the assigned spill slots without introducing breaking changes, upgrading to Solidity 0.8.37 will not cause existing builds to fail with "Stack too deep" errors. Developers utilizing the --via-ir compilation pipeline are encouraged to update their projects to version 0.8.37 as part of standard maintenance procedures.

