{"id":3235,"date":"2026-11-02T23:15:46","date_gmt":"2026-11-02T23:15:46","guid":{"rendered":"https:\/\/smartcryptosecurity.com\/?p=3235"},"modified":"2026-11-02T23:15:46","modified_gmt":"2026-11-02T23:15:46","slug":"critical-solidity-compiler-update-released-to-fix-spill-slot-collision-bug-in-intermediate-representation-pipeline","status":"publish","type":"post","link":"https:\/\/smartcryptosecurity.com\/?p=3235","title":{"rendered":"Critical Solidity Compiler Update Released to Fix Spill Slot Collision Bug in Intermediate Representation Pipeline"},"content":{"rendered":"<p><strong>The Ethereum Foundation and the Solidity development team have officially released Solidity version 0.8.37, addressing a newly discovered low-to-medium severity compiler defect within the intermediate representation (IR) pipeline&#8217;s stack-to-memory mover. Disclosed through the Ethereum Foundation bug bounty program by researcher Ng Sze Hon, the vulnerability could theoretically cause local variables across mutually recursive functions to overwrite one another silently, leading to unexpected runtime states.<\/strong><\/p>\n<p>Despite its technical severity, comprehensive database rescans indicate that no deployed smart contracts in the wild are known to be affected by the vulnerability. The issue is restricted exclusively to the IR-based compilation pipeline, leaves the legacy <code>evmasm<\/code> pipeline completely untouched, and requires a rare combination of specific compiler flags and architectural patterns to manifest.<\/p>\n<h2>Understanding the Stack Limit Evader and Spill Slots<\/h2>\n<p>To fully comprehend the nature of the vulnerability, it is necessary to examine how the Ethereum Virtual Machine (EVM) and the Solidity compiler manage execution stack limitations. The EVM architecture enforces a strict architectural constraint: low-level execution instructions can access at most the topmost 16 stack slots. When a complex smart contract function contains a high volume of simultaneously live local variables, exceeding this 16-slot ceiling triggers the well-known &quot;Stack too deep&quot; compilation error. <\/p>\n<p>To bypass this barrier and enable developers to write more expressive, modular code without running hard into EVM stack boundaries, the Solidity compiler features an advanced IR pipeline component colloquially known as the &quot;stack limit evader.&quot; When active, this component identifies variables that exceed safe stack thresholds and relocates\u2014or &quot;spills&quot;\u2014them from the stack to fixed memory offsets known as spill slots. These spill slots occupy a dedicated, reserved region at the absolute beginning of contract memory. The total size of this memory region is communicated dynamically to the underlying Yul optimizer through the <code>memoryguard<\/code> builtin function.<\/p>\n<p>Because these spill slots are designed to be reused across different execution phases to conserve memory, the compiler must ensure that two variables whose lifespans overlap are never assigned the same slot. While the stack-to-memory mover traditionally excludes recursive functions to prevent state corruption, a more subtle flaw existed within the way slot requirements were calculated across mutually recursive call graphs.<\/p>\n<h2>The Root Cause: Call Graph Traversal and Provisional Slot Undercounts<\/h2>\n<p>The core mechanism behind the vulnerability lies in how the compiler&#8217;s slot allocator analyzes call graphs. To optimize memory layout, the slot allocator performs a depth-first traversal of the call graph, computing the precise slot requirements for every function and everything it can reach. Functions that cannot be active simultaneously are permitted to share spill slots, but a function must never reuse a slot belonging to one of its callers, because the caller&#8217;s spilled variables remain active while the callee executes.<\/p>\n<p>To prevent infinite loops when descending into recursive call chains, the allocator writes a provisional slot requirement of zero into an internal cache upon first entering a function. This provisional value is intended to be overwritten with the true, final requirement once all downstream callees have been fully explored. However, a critical flaw emerged: during certain traversal patterns involving mutual recursion, the algorithm could read the provisional zero value as if it were final. <\/p>\n<p>When a function was revisited through a cycle, it incorrectly received a requirement of zero instead of the actual slot count needed by the function it called. This underestimated requirement was then finalized, cached, and propagated to subsequent callers throughout the broader compilation process, regardless of whether those later callers had any relation to the recursive cycle.<\/p>\n<p>Consequently, the overall reserved memory region was sized too small. Two distinct variables belonging to entirely separate functions could be mapped to the exact same memory spill slot. At runtime, when one function wrote data to its variable and subsequently invoked a mutually recursive routine, a downstream function would overwrite the shared slot. When the original function attempted to read its variable back, it inadvertently retrieved the corrupted value written by the other function, leading to silent state manipulation that did not match the original source code.<\/p>\n<h2>Affected Versions and Precise Trigger Conditions<\/h2>\n<p>The vulnerability was originally introduced into the Solidity compiler ecosystem alongside the stack limit evader feature in version 0.7.2. It has remained present across all subsequent releases through version 0.8.36. <\/p>\n<p>However, reaching the vulnerable code path depends heavily on the compiler version and configuration flags used during build time. The bug is closely related to, yet distinct from, an earlier issue known as the &quot;Unsound Spill In Mutual Recursion Bug,&quot; which was successfully patched in Solidity 0.8.36. Because the underlying root causes differ, this new slot-collision defect persists even in compiler versions that incorporate the previous fix.<\/p>\n<p>A smart contract is considered potentially vulnerable only if a strict confluence of conditions is met simultaneously:<\/p>\n<ul>\n<li>The contract must be compiled using the IR pipeline via the <code>--via-ir<\/code> flag, which is not enabled by default in most development environments.<\/li>\n<li>The contract&#8217;s source code or inline assembly must contain mutually recursive functions.<\/li>\n<li>The functions involved must utilize a sufficient number of simultaneously live local variables to trigger the stack-to-memory mover.<\/li>\n<li>The compiler must execute a traversal path that encounters the provisional cache bug during call graph analysis.<\/li>\n<\/ul>\n<p>In versions ranging from 0.7.2 through 0.8.20, the Yul optimizer\u2014and by extension the stack-to-memory mover\u2014only executes when the <code>--optimize<\/code> flag is explicitly passed, meaning compilation required both <code>--via-ir<\/code> and <code>--optimize<\/code> enabled. From version 0.8.21 onward, the stack-to-memory relocation operates as a distinct, standalone stage of the IR pipeline that runs regardless of the optimizer&#8217;s status. <\/p>\n<p>It is important to note that only the compilation settings utilized to build the final deployed bytecode matter; development test suites or continuous integration pipelines that used different parameters do not introduce risk to production deployments if the production artifacts were compiled safely. Furthermore, contracts lacking mutual recursion entirely, or those containing inline assembly blocks that are explicitly annotated as memory-safe under specific compiler guidelines, remain unaffected.<\/p>\n<h2>Verification, Severity Assessment, and Remediation<\/h2>\n<p>Upon discovering and analyzing the issue, the Solidity team performed an exhaustive security audit of the broader Ethereum ecosystem. Researchers rescinded the entire database hosted by Sourcify, 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 to different bytecode versions, verifying that no known deployed smart contracts in production have been compromised by this compiler defect.<\/p>\n<p>The Ethereum Foundation classified the vulnerability as having a <em>low\/medium<\/em> internal severity rating. Because the defect manifests as unexpected mathematical or state outcomes rather than outright execution reverts or transaction failures, it can occasionally prove challenging to diagnose without comprehensive test coverage. Nevertheless, because the miscompilation is entirely deterministic, any standard test suite that compiles with the matching production parameters and exercises the affected logical pathways will reliably expose incorrect behavior.<\/p>\n<p>To permanently resolve the vulnerability, the Solidity development team implemented a structural refactoring of the slot allocator. Instead of evaluating call graphs on a function-by-function basis, the updated compiler analyzes strongly connected components (SCCs)\u2014representing maximal sets of mutually recursive functions, with non-recursive functions forming isolated single-node components. <\/p>\n<p>Within this updated framework, slot requirements are computed and cached at the component level. Calls occurring between members of the exact same strongly connected component are ignored during the graph walk, as their collective requirements are fully accounted for within the component&#8217;s unified budget. Because these components form a strictly acyclic overarching graph, a component can never be revisited while actively processing, entirely eliminating provisional value misreads and ensuring all cached data remains authoritative.<\/p>\n<p>Crucially, the patch does not introduce breaking compilation changes. Unlike previous compiler updates that occasionally caused previously functional code to throw &quot;Stack too deep&quot; errors due to stricter safety checks, upgrading to Solidity 0.8.37 safely adjusts reserved memory regions and assigned slots without disrupting existing build pipelines. The fix is further reinforced by newly introduced property-based fuzz tests designed to generate randomized call graphs and verify program behavior continuity before and after variable spilling.<\/p>\n<p>Developers utilizing the experimental IR compilation pipeline are strongly advised to upgrade their projects to Solidity 0.8.37 immediately. Projects not utilizing the <code>--via-ir<\/code> flag or those without mutual recursion face no operational exposure, but adopting the latest compiler release ensures long-term code integrity and compliance with the latest upstream security standards.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ethereum Foundation and the Solidity development team have officially released Solidity version 0.8.37, addressing&#8230;<\/p>\n","protected":false},"author":4,"featured_media":3234,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[401,2220,1230,201,867,2223,2001,868,5,2219,400,402,2218],"class_list":["post-3235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-auditing","tag-collision","tag-compiler","tag-critical","tag-intermediate","tag-pipeline","tag-released","tag-representation","tag-security","tag-slot","tag-smart-contracts","tag-solidity","tag-spill"],"_links":{"self":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/3235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3235"}],"version-history":[{"count":0,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/3235\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/media\/3234"}],"wp:attachment":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}