{"id":3726,"date":"2026-11-10T07:50:14","date_gmt":"2026-11-10T07:50:14","guid":{"rendered":"https:\/\/wyominginvest.com\/?p=3726"},"modified":"2026-11-10T07:50:14","modified_gmt":"2026-11-10T07:50:14","slug":"solidity-0-8-37-released-to-patch-critical-ir-pipeline-spill-slot-collision-bug-involving-mutual-recursion","status":"publish","type":"post","link":"https:\/\/wyominginvest.com\/?p=3726","title":{"rendered":"Solidity 0.8.37 Released to Patch Critical IR Pipeline Spill Slot Collision Bug Involving Mutual Recursion"},"content":{"rendered":"<p>The Ethereum Foundation and the Solidity core development team have officially released Solidity 0.8.37, addressing a subtle and dangerous compiler bug in the Intermediate Representation (IR) pipeline. Discovered and reported by security researcher Ng Sze Hon through the Ethereum Foundation\u2019s official bug bounty program on July 30, 2026, the vulnerability involves a stack-to-memory relocation flaw. Under specific, rare conditions involving mutual recursion, this flaw could cause local variables across different functions to share the exact same memory spill slot, resulting in silent variable overwrites and unexpected smart contract behavior at runtime.<\/p>\n<p>Although the bug can cause contracts to execute operations and store values never intended by the original source code, exhaustive scanning of the Sourcify verified contract database indicates that no deployed production contracts are currently known to be affected. The core team has assigned the issue a &quot;low\/medium&quot; severity rating due to the exceptionally narrow set of conditions required to trigger it, combined with the fact that the experimental <code>--via-ir<\/code> compilation pipeline is not enabled by default for most developer projects.<\/p>\n<h3>Understanding the Stack-to-Memory Mover and the Root Cause<\/h3>\n<p>To understand how the bug manifests, it is necessary to examine how modern Ethereum Virtual Machine (EVM) compilers manage execution constraints. The EVM possesses a rigid architectural limitation: its instruction set can natively access at most the topmost 16 stack slots. When a Solidity function contains too many simultaneously active local variables, the compiler encounters the well-known &quot;Stack too deep&quot; error, preventing compilation.<\/p>\n<p>To bypass this limitation within the modern IR pipeline, the Solidity compiler employs a feature known as the stack-to-memory mover, frequently referred to as the &quot;stack limit evader.&quot; When invoked, this mechanism identifies affected local variables and rewrites their access patterns into memory operations\u2014specifically <code>mstore<\/code> and <code>mload<\/code> instructions\u2014directing them to fixed memory offsets designated as &quot;spill slots.&quot; These slots reside within a reserved memory region at the very beginning of contract memory, the size of which is communicated to the Yul optimizer using the <code>memoryguard<\/code> built-in function.<\/p>\n<p>Because these spill slots are designed to be reused across different function activations to conserve memory, the compiler must strictly ensure that two variables whose live ranges overlap are never assigned the same slot. While the stack-to-memory mover traditionally excludes recursive functions from spilling to maintain safety, mutual recursion introduces a far more complex topological challenge within the call graph.<\/p>\n<p>The vulnerability discovered by Ng Sze Hon stems from a flaw in how the compiler&#8217;s slot allocator calculates memory requirements during a depth-first traversal of the call graph. To prevent infinite loops when encountering recursive cycles, the allocator writes a provisional slot requirement value of zero into its cache upon entering a function, updating it to the true calculated requirement only after exploring all downstream callees. <\/p>\n<p>However, the traversal logic could prematurely read this provisional zero value as a final, definitive result if a cycle looped back to a function currently being processed. Consequently, an undercount of required spill slots would be computed, finalized, and propagated to subsequent callers throughout the call graph. If two unrelated functions ultimately shared a collapsed spill slot, executing a transaction could cause one function to silently overwrite the memory location of another. When the program later attempted to read its variable back, it would retrieve corrupted data generated elsewhere in the call graph.<\/p>\n<h3>Relation to Previous Spill Bugs and Version Impact<\/h3>\n<p>This newly uncovered vulnerability is closely related to, yet distinct from, the &quot;Unsound Spill In Mutual Recursion Bug&quot; that was previously patched in Solidity 0.8.36. That earlier issue was primarily a classification failure, where faulty cycle detection caused certain mutually recursive functions to be incorrectly treated as non-recursive, thereby violating the cardinal rule that recursive functions must never have their variables spilled.<\/p>\n<p>By contrast, the vulnerability patched in Solidity 0.8.37 involves correct classification\u2014the recursive functions themselves are properly identified and left unspilled\u2014but fails during slot allocation sizing. Because the root causes are fundamentally different, the bug persisted even in Solidity version 0.8.36, which already incorporated the fix for the earlier issue. <\/p>\n<p>The flawed code path has been reachable across a wide range of compiler versions, specifically affecting all releases from Solidity 0.7.2 through 0.8.36. The bug is fully resolved starting with Solidity 0.8.37.<\/p>\n<h3>Which Contracts Are Affected?<\/h3>\n<p>In practice, the likelihood of a project encountering this vulnerability in the wild is extremely low. For a smart contract to be susceptible to the stack slot collision bug, a specific set of rigorous conditions must simultaneously align. <\/p>\n<p>First, the contract must be compiled using the IR pipeline via the <code>--via-ir<\/code> command-line flag. Projects relying on the traditional legacy <code>evmasm<\/code> pipeline are completely immune. Because <code>--via-ir<\/code> is not enabled by default in standard compiler configurations, projects that have not explicitly opted into it face no risk.<\/p>\n<p>Second, the contract must contain functions that exhibit mutual recursion. Contracts completely devoid of mutually recursive function structures\u2014whether defined natively in Solidity or via inline assembly blocks inside <code>assembly<\/code> statements\u2014are unaffected. <\/p>\n<p>Third, the code must contain sufficient local variables to force the compiler to trigger the stack-to-memory mover, and it must include memory-safe inline assembly blocks, as stack-to-memory relocation exclusively targets code the compiler recognizes as memory-safe. <\/p>\n<p>Finally, compiler version dynamics play a role. For Solidity versions ranging from 0.8.21 to 0.8.36, the bug operates independently of whether the optimizer is enabled, because the stack-to-memory mover runs as an independent stage of the IR pipeline. In contrast, for earlier affected versions spanning 0.7.2 through 0.8.20, the Yul optimizer\u2014and consequently the stack-to-memory mover\u2014only executes when the <code>--optimize<\/code> flag is explicitly supplied. Developers should note that vulnerability status is strictly determined by the compiler settings used to produce the final deployed bytecode, rather than configurations utilized exclusively for local testing or continuous integration pipelines.<\/p>\n<h3>Verification and Safety Audits<\/h3>\n<p>To quantify the real-world impact of the bug, the Solidity development team conducted an extensive rescan of the Sourcify verified contract repository, recompiling approximately 319,000 verified smart contracts using compiler builds both with and without the patch. The analysis revealed that none of the compiled bytecodes differed between the two builds, confirming that no known deployed smart contracts on public networks were compromised or affected by the compiler flaw.<\/p>\n<p>Furthermore, the vulnerability does not trigger explicit compilation warnings or runtime transaction reverts, meaning that identifying it relies entirely on deterministic test suites or static analysis. Because the miscompilation is entirely deterministic, any comprehensive test suite exercising the impacted execution paths will consistently expose the anomalous behavior.<\/p>\n<h3>The Technical Fix and Recommended Actions<\/h3>\n<p>To permanently eliminate the bug, the Solidity core team refactored the slot allocation algorithm. Instead of performing a traversal on a per-function basis, the compiler now analyzes the call graph using strongly connected components (SCCs)\u2014representing maximal sets of mutually recursive functions, with non-recursive functions each forming an individual component. <\/p>\n<p>Within this updated architecture, because every member of a mutually recursive cycle reaches all other members, individual functions cannot maintain private slot budgets. Instead, slot requirements are computed and cached at the holistic component level, and internal calls between members of the same component are gracefully ignored during the walk. Because the resulting component graph is strictly acyclic, provisional values can no longer be misread as final, ensuring deterministic and accurate memory allocation. <\/p>\n<p>Unlike previous critical compiler patches that occasionally introduced breaking changes, upgrading to Solidity 0.8.37 will not cause existing builds to fail with &quot;Stack too deep&quot; errors. The fix merely corrects the sizing of reserved memory regions and the assignment of spill slots. Additionally, the core team has instituted new property-based fuzz testing suites that automatically generate random call graphs and verify behavioral parity before and after memory spilling takes place.<\/p>\n<p>Developers utilizing the experimental IR pipeline are strongly advised to upgrade their projects to Solidity 0.8.37 as part of their standard maintenance workflows. Those maintaining projects that incorporate mutual recursion alongside high local variable density should review their compilation toolchains to ensure they are building with the patched release.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ethereum Foundation and the Solidity core development team have officially released Solidity 0.8.37, addressing a subtle and dangerous compiler bug in the Intermediate Representation (IR) pipeline. Discovered and reported by security researcher Ng Sze Hon through the Ethereum Foundation\u2019s official bug bounty program on July 30, 2026, the vulnerability involves a stack-to-memory relocation flaw.<\/p>\n","protected":false},"author":12,"featured_media":3725,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[401,2258,201,215,2201,881,2259,2837,2014,5,2257,400,402,2256],"class_list":["post-3726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-auditing","tag-collision","tag-critical","tag-involving","tag-mutual","tag-patch","tag-pipeline","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\/3726","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\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3726"}],"version-history":[{"count":0,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/3726\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/media\/3725"}],"wp:attachment":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}