{"id":4290,"date":"2026-11-19T07:49:13","date_gmt":"2026-11-19T07:49:13","guid":{"rendered":"https:\/\/wyominginvest.com\/?p=4290"},"modified":"2026-11-19T07:49:13","modified_gmt":"2026-11-19T07:49:13","slug":"solidity-security-advisory-medium-severity-yul-optimizer-bug-discovered-in-versions-0-7-2-through-0-8-35","status":"publish","type":"post","link":"https:\/\/wyominginvest.com\/?p=4290","title":{"rendered":"Solidity Security Advisory: Medium-Severity Yul Optimizer Bug Discovered in Versions 0.7.2 through 0.8.35"},"content":{"rendered":"<p>The Solidity development team has released version 0.8.36 of the popular Ethereum smart contract programming language, addressing a medium-severity bug discovered in the Yul optimizer\u2019s call graph analysis. The vulnerability, which affects the intermediate representation (IR) compilation pipeline, could under very specific circumstances cause mutually recursive functions to be incorrectly classified as non-recursive. This misclassification could subsequently lead to memory corruption in contracts utilizing complex stack-to-memory variable relocation mechanisms.<\/p>\n<p>The issue was uncovered on May 11, 2026, by a developer known as clonker from the core Solidity team. According to the advisory, the bug specifically impacts the IR-based pipeline, while the legacy <code>evmasm<\/code> pipeline remains completely unaffected. Because the modern <code>--via-ir<\/code> compilation flag is not enabled by default in Solidity projects, developers who have not explicitly opted into using the IR pipeline are entirely shielded from the vulnerability. However, for projects utilizing the modern pipeline across versions 0.7.2 through 0.8.35, the bug represents a subtle and potentially hazardous flaw in how the compiler manages local variables during recursive executions.<\/p>\n<p>To understand the mechanics of the bug, developers must look at how the Ethereum Virtual Machine (EVM) handles execution context and stack depth limitations. The EVM natively permits direct access only to the topmost 16 stack slots. When a function attempts to manage a high number of simultaneously live local variables, it frequently exceeds this threshold, historically throwing the well-known &quot;Stack too deep&quot; compilation error. To mitigate this restriction and improve developer experience, the modern IR pipeline incorporates a stack-to-memory mover, also referred to as the stack limit evader. <\/p>\n<p>When a function cannot fit its variables onto the EVM stack, the compiler relocates selected variables to fixed memory offsets, substituting standard stack instructions with <code>mstore<\/code> and <code>mload<\/code> operations pointing to those specific memory locations. However, this optimization technique is only mathematically sound for functions that are strictly non-recursive. Because fixed memory offsets are shared universally by every activation of a given function, a recursive function poses a severe risk. If a function holds a value in a fixed memory slot across a call that re-enters the same function\u2014either directly or through an intricate cycle of mutual recursion\u2014the inner function invocation will overwrite the memory slot. Consequently, when the outer function invocation resumes and attempts to read back its variable, it retrieves corrupted data.<\/p>\n<p>To prevent this dangerous condition, the compiler is designed to construct a Yul call graph and run a specialized cycle detection algorithm, ensuring that any function participating in a recursive call chain is strictly excluded from the stack-to-memory spilling mechanism. The root cause of the newly discovered vulnerability lies precisely within this cycle detection logic.<\/p>\n<p>The flawed cycle detection implementation was originally introduced during an internal refactor as early as version 0.6.12. At the time of its introduction, the code had only a single consumer, the <code>SideEffectsPropagator<\/code>, where a function misclassification had no observable side effects or impact on generated bytecode. However, beginning with version 0.7.2, the newly implemented <code>StackLimitEvader<\/code> began relying on this analysis, establishing 0.7.2 as the earliest affected version. <\/p>\n<p>In practice, the Solidity core team was only able to successfully reproduce actual miscompilations in versions 0.8.8 and later, or via the experimental <code>--experimental-via-ir<\/code> entry point found in versions 0.8.10 and onward. In earlier versions, code samples designed to trigger the bug typically hit a &quot;Stack too deep&quot; compilation barrier before the incorrect runtime behavior could manifest. Nevertheless, because the team could not definitively prove that the underlying bug was unreachable in those earlier versions, the entire range from 0.7.2 through 0.8.35 is conservatively classified as vulnerable. Furthermore, the conditions required to reach the affected code vary depending on compiler versions. On Solidity 0.8.21 and later, the bug occurs independently of whether the optimizer is enabled, because the stack-to-memory relocation runs as a distinct stage of the IR pipeline regardless of compiler optimization settings. On earlier affected versions, the optimization flag <code>--optimize<\/code> was required alongside <code>--via-ir<\/code> to activate the stack-to-memory mover.<\/p>\n<p>The technical root cause stems from a flaw in how path-based depth-first searches handle intersecting cycles. The previous <code>CallGraphGenerator<\/code> implementation tracked traversal paths using a stack. When an invocation of a function already present on the current path was encountered, the algorithm marked that function\u2014along with all intermediate functions called between the two points\u2014as contained within a cycle. Once all calls inside a function were thoroughly explored, the function was popped from the path, added to a set representing fully visited nodes, and configured to short-circuit immediately on any subsequent visits.<\/p>\n<p>This short-circuit mechanism proved unsound when handling intersecting cycles. Because the traversal only recorded a cycle when encountering an active edge pointing back to a function still present on the current path, it failed if a cycle could only be closed by passing through a node that had already been marked as finished during an earlier, separate cycle traversal. When the algorithm encountered that already-finished node, it halted prematurely before the second cycle could be closed. As a result, the function was incorrectly reported as non-recursive, despite genuinely lying on a recursive cycle.<\/p>\n<p>Whether this erroneous classification occurred depended heavily on the traversal order of the call graph&#8217;s internal data structures, which are determined by the name hashes of the Yul functions. Because different function names yield entirely different hash-based orderings, the bug only manifested under precise and uncommon graph configurations.<\/p>\n<p>To gauge the real-world impact of the vulnerability, the Solidity team conducted a comprehensive automated scan of approximately 207,000 contracts utilizing the <code>--via-ir<\/code> flag stored within the Sourcify database. The analysis identified just 272 contracts\u2014representing roughly 0.1% of the scanned dataset\u2014that contained a function misclassified by the flawed analysis. Crucially, none of these deployed contracts actually relocated variables to memory inside the misclassified functions, meaning no known mainnet contracts were compromised or negatively impacted by the bug.<\/p>\n<p>A contract is only vulnerable if a very specific set of narrow conditions align simultaneously. Most importantly, the contract must feature mutual recursion involving functions that are complex enough to exceed stack limitations, and the specific traversal ordering must trigger the cycle detection failure. If a contract contains no mutual recursion whatsoever, it is completely unaffected by the vulnerability.<\/p>\n<p>The release of Solidity 0.8.36 permanently resolves the issue by replacing the faulty path-based depth-first search with Tarjan&#8217;s algorithm, a well-established and robust standard algorithm for identifying strongly connected components within directed graphs. Tarjan&#8217;s algorithm partitions the call graph in a single, comprehensive pass that does not rely on traversal order, ensuring that every function contained within any cycle is reliably identified and classified as recursive. With this fix implemented, the compiler correctly preserves the variables of recursive functions on the stack rather than risking unsafe memory relocation.<\/p>\n<p>An important consequence of this fix is that certain contracts which previously compiled successfully under older compiler versions may now trigger a &quot;Stack too deep&quot; compilation error when upgraded to Solidity 0.8.36. The Solidity team emphasizes that this behavior is correct and expected. In these instances, the previous compiler versions were silently generating incorrect, unsafe code by performing an unsound memory relocation on recursive functions. When the fix forces these variables to remain on the stack, the underlying function exceeds the 16-slot EVM limit, exposing the structural stack issue that was previously masked. Developers encountering this compilation error after upgrading are advised to restructure their functions to reduce local variable pressure rather than relying on flawed compiler behavior.<\/p>\n<p>The Solidity team has assigned a medium severity rating to the issue. Because the bug emits no compiler warnings and does not cause transactions to revert at runtime, any manifestation results in silent state or value corruption rather than an immediate failure. However, projects maintaining robust automated test suites executed with the <code>--via-ir<\/code> flag prior to deployment are exceptionally well-positioned to catch such anomalous behaviors during the development lifecycle. Developers utilizing the IR pipeline are strongly encouraged to update their toolchains to Solidity 0.8.36 immediately and review any contracts utilizing complex recursive patterns.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Solidity development team has released version 0.8.36 of the popular Ethereum smart contract programming language, addressing a medium-severity bug discovered in the Yul optimizer\u2019s call graph analysis. The vulnerability, which affects the intermediate representation (IR) compilation pipeline, could under very specific circumstances cause mutually recursive functions to be incorrectly classified as non-recursive. This misclassification<\/p>\n","protected":false},"author":10,"featured_media":4289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[2987,401,949,2279,2015,5,2280,400,402,1051],"class_list":["post-4290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-advisory","tag-auditing","tag-discovered","tag-medium","tag-optimizer","tag-security","tag-severity","tag-smart-contracts","tag-solidity","tag-versions"],"_links":{"self":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/4290","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\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4290"}],"version-history":[{"count":0,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/4290\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/media\/4289"}],"wp:attachment":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}