{"id":4640,"date":"2026-11-25T07:49:15","date_gmt":"2026-11-25T07:49:15","guid":{"rendered":"https:\/\/wyominginvest.com\/?p=4640"},"modified":"2026-11-25T07:49:15","modified_gmt":"2026-11-25T07:49:15","slug":"solidity-compiler-update-critical-fix-released-for-spill-slot-collision-bug-across-mutual-recursion","status":"publish","type":"post","link":"https:\/\/wyominginvest.com\/?p=4640","title":{"rendered":"Solidity Compiler Update: Critical Fix Released for Spill Slot Collision Bug Across Mutual Recursion"},"content":{"rendered":"<p>Security researchers and smart contract developers using the Ethereum ecosystem are reviewing a newly disclosed vulnerability in the Solidity compiler. On July 30, 2026, independent security researcher Ng Sze Hon discovered and responsibly reported a subtle compiler bug through the Ethereum Foundation\u2019s bug bounty program. The vulnerability resides within the intermediate representation (IR) pipeline&#8217;s stack-to-memory mover, a specialized mechanism often referred to as the &quot;stack limit evader.&quot; <\/p>\n<p>Under precise and uncommon conditions involving mutual recursion, the compiler could inadvertently assign the exact same memory spill slot to local variables belonging to two entirely different functions. Because both<\/p>\n<p>variables could remain simultaneously live during execution, one variable could silently overwrite the other. Consequently, affected smart contracts could compute, process, and permanently store values that were never explicitly assigned by the underlying source code.<\/p>\n<p>Ethereum Foundation maintainers have designated this issue a <strong>low-to-medium severity<\/strong> vulnerability on their internal scaling system. The bug exclusively impacts contracts compiled using the IR pipeline; the legacy <code>evmasm<\/code> pipeline remains completely unaffected. Furthermore, because the <code>--via-ir<\/code> compilation flag is not enabled by default across all projects, only development teams that explicitly opted into the IR pipeline face any potential exposure. Contracts completely devoid of mutually recursive functions are entirely safe from this miscompilation behavior.<\/p>\n<p>Despite the narrow requirements needed to trigger the flaw, the affected code paths have been reachable across a broad span of compiler versions. The vulnerability has been present in every release from Solidity 0.7.2 through Solidity 0.8.36. The development team officially resolved the issue in Solidity 0.8.37. In response to the discovery, maintainers performed an exhaustive rescan of the Sourcify verified contract database, recompiling roughly 319,000 verified smart contracts using compiler builds both with and without the security patch. Every single contract produced identical bytecode regardless of the compiler version used, indicating that no deployed, public smart contract on-chain is known to have been compromised or affected by this bug.<\/p>\n<h2>Which Contracts Are Affected?<\/h2>\n<p>For a smart contract to be vulnerable to this specific spill slot collision, a very specific and unusual combination of structural patterns must occur simultaneously. A contract is only impacted if several distinct criteria are met during the compilation process.<\/p>\n<p>The first condition requires that the contract is compiled via the IR pipeline, meaning the <code>--via-ir<\/code> flag is active. The second condition dictates that the code must contain mutually recursive functions. Whether functions qualify as mutually recursive is determined by analyzing the compiled Yul code rather than just scanning the high-level Solidity source code. In practical terms, this means that mutually recursive Yul functions defined explicitly inside an inline assembly block will trigger the condition just as standard Solidity functions would. If a project contains zero mutual recursion\u2014whether implemented in native Solidity or through inline assembly\u2014the contract is completely immune.<\/p>\n<p>An additional counterintuitive constraint involves memory safety annotations. The stack-to-memory relocation phase of the compiler exclusively operates on code that the compiler recognizes as memory-safe. Consequently, any contract containing inline assembly blocks that are not explicitly annotated as memory-safe cannot trigger the stack-to-memory mover in a way that exposes this bug. <\/p>\n<p>Compiler optimization settings also dictate whether the bug can manifest, depending on the version range in use. From Solidity 0.8.21 onward, the vulnerability is entirely independent of whether the optimizer is enabled. In those versions, stack-to-memory relocation functions as a distinct, mandatory stage of the IR pipeline that executes regardless of the optimizer configuration, meaning that disabling the optimizer does not circumvent the issue. Conversely, on earlier affected versions ranging from 0.7.2 through 0.8.20, the Yul optimizer\u2014and by extension the stack-to-memory mover\u2014only runs when the <code>--optimize<\/code> flag is explicitly passed. For those older versions, triggering the bug requires both <code>--via-ir<\/code> and <code>--optimize<\/code> to be enabled concurrently. In all scenarios, only the configuration parameters utilized during the final compilation of the deployed contract matter, rather than flags used exclusively in local test environments or continuous integration pipelines.<\/p>\n<h2>Technical Details and Root Cause<\/h2>\n<p>To understand how the vulnerability occurs at an implementation level, one must examine how the Ethereum Virtual Machine (EVM) handles execution limits. EVM instruction sets can directly access at most the topmost 16 stack slots. When a complex function features a high number of simultaneously live local variables that exceed this strict threshold, the compiler cannot compile it directly, resulting in the well-known &quot;Stack too deep&quot; compilation error.<\/p>\n<p>To bypass this limitation, the IR pipeline utilizes the stack-to-memory mover. This subsystem selects a subset of affected local variables and rewrites their storage operations into <code>mstore<\/code> and <code>mload<\/code> instructions targeting fixed memory offsets known as spill slots. These slots occupy a dedicated, reserved region at the very beginning of the contract&#8217;s memory space, with the total size of this region announced to the Yul optimizer via the <code>memoryguard<\/code> builtin.<\/p>\n<p>Because an individual spill slot is designed to be shared across every execution activation of a function, this relocation strategy is only sound for functions that are entirely non-recursive. Therefore, the mover explicitly excludes recursive functions from spilling their variables. The underlying issue, however, stems from how slot allocation is calculated across complex call graphs.<\/p>\n<p>Not every spilled variable requires a dedicated, independent slot; functions that can never be active simultaneously can safely share the same memory offset. However, a function must never reuse a spill slot assigned to one of its callers, because the caller&#8217;s spilled variables remain actively live while any callee executes. To optimize memory utilization, the mover&#8217;s slot allocator performs a depth-first traversal of the call graph, calculating the slot requirements for every function based on its own needs combined with everything it can reach. <\/p>\n<p>To prevent infinite descents into recursive call chains during this analysis, the allocator writes a provisional slot requirement of zero into its cache upon entering a function, updating it to the true calculated value only after exploring all downstream callees. The vulnerability arose because the traversal mechanism could mistakenly read this provisional zero as if it were a finalized, correct value. A function encountered again via a cycle would read zero instead of the actual requirement of its callee, finalizing and caching that incorrect figure. This undercount would then propagate upward to subsequent callers, including entirely unrelated code branches.<\/p>\n<h2>Relation to Earlier Spill Bugs<\/h2>\n<p>This vulnerability shares conceptual similarities with, but remains fundamentally distinct from, the &quot;Unsound Spill In Mutual Recursion Bug&quot; that was patched in Solidity 0.8.36. The earlier bug was fundamentally a classification error. Due to faulty cycle detection logic, certain mutually recursive functions were incorrectly treated as non-recursive, causing the compiler to unlawfully spill variables belonging to recursive functions and violating core safety guarantees.<\/p>\n<p>By contrast, the slot-allocation bug discovered by Ng Sze Hon involved correct classification: the colliding functions were properly recognized as non-recursive, and members of the cycle had no variables spilled. Instead, the violation occurred at the allocation level, where two variables that could be simultaneously live were incorrectly assigned to share the same spill slot. Because the root causes are separate, the slot-collision bug remained fully present even in Solidity 0.8.36, which already incorporated the patch for the earlier misclassification issue.<\/p>\n<h2>Severity Assessment and Recommended Actions<\/h2>\n<p>The compiler emits no warnings when this bug is triggered, and the resulting EVM bytecode does not execute a runtime revert. Because the miscompilation manifests quietly as incorrect computational results rather than an outright operational failure, diagnosing the issue in production can prove challenging. However, the miscompilation remains entirely deterministic; any test suite that compiles with identical production settings and executes the affected code path will consistently observe the anomalous behavior. Unlike many legacy compiler vulnerabilities, this issue can manifest entirely in native Solidity code without requiring any inline assembly.<\/p>\n<p>Given the narrow set of overlapping preconditions required, the practical likelihood of encountering this bug in the wild is exceptionally low. Sourcify database scans confirmed that no known deployed contracts were affected. Nevertheless, because manual inspection of high-level source code cannot reliably rule out compiler-internal behaviors, the Ethereum Foundation strongly advises all developers utilizing the IR pipeline to update their toolchains immediately.<\/p>\n<p>The official resolution implemented in Solidity 0.8.37 redesigns the graph traversal mechanism. Instead of evaluating code on a per-function basis, the compiler now analyzes the call graph by strongly connected components (SCCs)\u2014representing maximal sets of mutually recursive functions, with non-recursive functions forming isolated components of their own. Because all members of a recursive cycle reach one another, individual functions cannot maintain private slot budgets; the entire component is sized and budgeted as a single unified block. This structural adjustment eliminates provisional reading errors, ensuring that all cached memory requirements are fully resolved before allocation. Developers are urged to upgrade to Solidity 0.8.37 or later to ensure complete protection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Security researchers and smart contract developers using the Ethereum ecosystem are reviewing a newly disclosed vulnerability in the Solidity compiler. On July 30, 2026, independent security researcher Ng Sze Hon discovered and responsibly reported a subtle compiler bug through the Ethereum Foundation\u2019s bug bounty program. The vulnerability resides within the intermediate representation (IR) pipeline&#8217;s stack-to-memory<\/p>\n","protected":false},"author":6,"featured_media":4639,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[302,401,2258,1184,201,2201,2837,2014,5,2257,400,402,2256],"class_list":["post-4640","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-across","tag-auditing","tag-collision","tag-compiler","tag-critical","tag-mutual","tag-recursion","tag-released","tag-security","tag-slot","tag-smart-contracts","tag-solidity","tag-spill"],"_links":{"self":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/4640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4640"}],"version-history":[{"count":0,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/4640\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/media\/4639"}],"wp:attachment":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}