{"id":2654,"date":"2026-10-24T22:16:18","date_gmt":"2026-10-24T22:16:18","guid":{"rendered":"https:\/\/smartcryptosecurity.com\/?p=2654"},"modified":"2026-10-24T22:16:18","modified_gmt":"2026-10-24T22:16:18","slug":"solidity-0-8-38-released-to-fix-critical-yul-optimizer-memory-and-storage-tracking-bug","status":"publish","type":"post","link":"https:\/\/smartcryptosecurity.com\/?p=2654","title":{"rendered":"Solidity 0.8.38 Released to Fix Critical Yul Optimizer Memory and Storage Tracking Bug"},"content":{"rendered":"<p>The Ethereum Foundation and the Solidity core development team have officially released Solidity version 0.8.38, addressing a low-severity yet complex compiler bug affecting the Yul optimizer. The vulnerability, which could lead to incorrect memory and storage operations under specific conditions, was uncovered through independent security disclosures submitted via the Ethereum Foundation\u2019s bug bounty program. While extensive database scans suggest that the real-world exploitation of the bug is exceptionally rare, the fix introduces a structural overhaul to the compiler&#8217;s knowledge tracking systems to guarantee absolute runtime safety.<\/p>\n<p>The issue stems from how the Yul optimizer manages data states, specifically concerning how it tracks distinct memory and storage locations. Under certain sequences of optimized code, the compiler can incorrectly deduce that two distinct variable-based locations are completely separate when, in fact, they coincide at runtime. Consequently, this flaw can cause the optimizer to substitute a read operation with an outdated value or, conversely, incorrectly eliminate a write operation that was necessary for proper contract execution.<\/p>\n<h2>Discovery and Initial Reports<\/h2>\n<p>The vulnerability came to light in late summer through two separate submissions to the Ethereum Foundation\u2019s bug bounty platform. On August 17, 2026, developer Daniel Boye submitted the initial bug report after identifying anomalies within the Yul optimizer&#8217;s internal handling of distinct memory and storage addresses. Boye&#8217;s findings demonstrated that the optimizer&#8217;s assumptions about variable offsets could occasionally break down, leading to corrupted data handling during execution.<\/p>\n<p>Weeks later, on September 28, 2026, a second independent report was filed by Surya Prakash Akula. While Boye\u2019s initial discovery highlighted complexities within Yul assembly structures, Akula\u2019s findings provided crucial additional context by proving that the bug could actually be triggered directly from plain, high-level Solidity code, entirely bypassing the need for explicit inline assembly blocks. This revelation expanded the potential surface area of the bug, prompting the Solidity team to conduct a comprehensive internal review and swiftly develop a permanent patch.<\/p>\n<h2>Which Contracts Are Affected?<\/h2>\n<p>The Solidity development team has assigned a severity rating of <em>low<\/em> to this vulnerability, noting that several strict conditions must simultaneously align for a contract to be impacted. First and foremost, any contract compiled with the Yul optimizer disabled remains entirely unaffected by the bug. <\/p>\n<p>However, when code is compiled using modern optimization pathways\u2014such as the <code>--via-ir<\/code> pipeline, which maps to <code>settings.viaIR<\/code> in Standard JSON\u2014virtually any code can be vulnerable, including standard Solidity code lacking inline assembly. Similarly, Yul code compiled directly with the <code>--strict-assembly<\/code> flag or <code>\"language\": \"Yul\"<\/code> in Standard JSON falls under the risk umbrella. Conversely, when utilizing the legacy <code>evmasm<\/code> pipeline, the vulnerability is typically restricted to compiler-generated Yul utility functions and isolated inline assembly blocks that do not reference external Solidity variables or functions.<\/p>\n<p>The introduction of the bug traces back to Solidity version 0.8.19, meaning that all subsequent compiler versions ranging from 0.8.19 through 0.8.37 are theoretically susceptible. The vulnerability has been fully eradicated in Solidity 0.8.38. Furthermore, the targeted Ethereum Virtual Machine (EVM) version does not influence whether the bug will manifest or remain dormant.<\/p>\n<h2>Assessing Real-World Risk and Sourcify Analysis<\/h2>\n<p>To gauge the practical risk posed to deployed decentralized applications, the Solidity team performed a broad empirical analysis. Researchers scanned the Sourcify database, rebuilding a massive corpus of verified smart contracts using a specialized development build of the compiler. This audit cycle tested roughly 283,000 verified compilations utilizing the <code>--via-ir<\/code> pipeline and over 607,000 compilations using the legacy <code>evmasm<\/code> pipeline, compiling each contract once with the vulnerable logic and once with the applied fix.<\/p>\n<p>Remarkably, none of the tested compilations produced different output bytecode between the flawed and patched compiler states. While this empirical evidence provides strong confidence that the bug is exceptionally rare in the wild, the core developers emphasize that it does not serve as an absolute guarantee that zero legacy contracts are affected. Because intermediate optimization steps and compiler environments vary widely, developers who deployed contracts using versions 0.8.19 through 0.8.37 with the optimizer enabled are encouraged to verify their compilation parameters.<\/p>\n<h2>Technical Details: Inside the Yul Optimizer<\/h2>\n<p>To understand how the vulnerability occurs at the implementation level, it is necessary to examine the inner workings of the Yul optimizer&#8217;s knowledge base. The optimization pipeline relies heavily on components such as <code>LoadResolver<\/code> and <code>EqualStoreEliminator<\/code> to streamline contract execution. <code>LoadResolver<\/code> is designed to substitute <code>mload<\/code>, <code>sload<\/code>, and <code>keccak256<\/code> instructions with known values that the compiler has already tracked, while <code>EqualStoreEliminator<\/code> strips away redundant storage writes if a location is already verified to hold the target value.<\/p>\n<p>Both components rely on a centralized bookkeeping framework called the <code>KnowledgeBase<\/code>, which evaluates relationships between variables. When the optimizer encounters a store instruction where the exact destination cannot be definitively predetermined, it is forced to clear out everything it assumes it knows about any memory or storage location that the write might potentially overwrite. To determine which specific locations are at risk, the <code>KnowledgeBase<\/code> treats variables symbolically as constant offsets derived from a base variable. <\/p>\n<p>For instance, if a base address is established from calldata and a pointer is created by adding a constant offset, the optimizer maps the pointer relative to that base variable. To optimize efficiency, a caching mechanism was introduced in Solidity 0.8.19 to store these variable representations, replacing the previous behavior of computing offsets dynamically on the fly.<\/p>\n<p>The root cause of the bug lies in how this cache handled lazy invalidation. The <code>KnowledgeBase<\/code> attempted to keep cache entries fresh by comparing a variable&#8217;s current value expression with the expression recorded during the previous lookup. If a mismatch was detected, the cache entry would be reset. However, this lazy validation check could occasionally fail to catch a variable reassignment under specific control-flow patterns, such as complex loops or conditional branches where a base variable was modified both before and after address derivation.<\/p>\n<p>When the validation check failed, two separate addresses could end up being represented as offsets from the same base variable, even though one address was derived from the base&#8217;s value <em>before<\/em> a reassignment and the other from its value <em>after<\/em> the change. The optimizer mistakenly treated both offsets as if they belonged to the exact same temporal state. Consequently, it deduced that the two memory or storage locations were distinct and preserved its assumptions about one location across a write operation targeting the other. If those two locations happened to coincide during runtime execution, subsequent load instructions would pull outdated values, or necessary store instructions would be incorrectly optimized away.<\/p>\n<h2>A Concrete Illustration<\/h2>\n<p>A practical example provided by the Solidity team demonstrates how a vulnerability can manifest in standard high-level code. Consider a contract featuring a static array of structs where each element occupies a predictable storage slot based on its index. Within a specialized function containing sequential loops that modify a shared index variable <code>i<\/code>, the compiler&#8217;s tracking mechanism can lose track of the variable&#8217;s state across iterations.<\/p>\n<p>When compiled with <code>--via-ir<\/code> and the optimizer enabled, the intermediate Yul code may derive the storage slots for array accesses from the variable <code>i<\/code> at different points in the program&#8217;s execution. Because the optimizer fails to recognize that <code>i<\/code> has been mutated between the two operations, it incorrectly concludes that a write operation to one array index cannot possibly overwrite the data at another index. As a result, a final load operation is incorrectly replaced with an outdated parameter value from earlier in the function, causing the contract to return stale data rather than the expected updated state.<\/p>\n<h2>The Fix and Recommended Actions<\/h2>\n<p>The core development team resolved the issue by completely replacing the flawed lazy invalidation strategy with an explicit variable versioning system within the <code>KnowledgeBase<\/code>. Under the new implementation in Solidity 0.8.38, every tracked variable carries an explicit version number that automatically increments whenever the optimizer registers a modification to its underlying value. <\/p>\n<p>Because cached representations are now stored uniquely per variable and per version, any subsequent reassignment treats the variable as an entirely new entity. This structural change ensures that stale cache entries can no longer persist across program states, eliminating the root cause of the incorrect distinctness assumptions.<\/p>\n<p>Security analysts and developers maintaining Ethereum smart contracts are advised to review their project dependencies and compiler configurations. Any projects currently utilizing Solidity versions 0.8.19 through 0.8.37 with the Yul optimizer enabled should promptly upgrade to Solidity 0.8.38 to ensure long-term code integrity and protection against unexpected optimization anomalies.<\/p>\n<p>The Ethereum Foundation and the Solidity core team expressed their gratitude to Daniel Boye and Surya Prakash Akula for their responsible disclosures through the official bug bounty program, which enabled the rapid identification and resolution of the flaw.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ethereum Foundation and the Solidity core development team have officially released Solidity version 0.8.38,&#8230;<\/p>\n","protected":false},"author":23,"featured_media":2653,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[401,201,960,2002,2001,5,400,402,517,322],"class_list":["post-2654","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-auditing","tag-critical","tag-memory","tag-optimizer","tag-released","tag-security","tag-smart-contracts","tag-solidity","tag-storage","tag-tracking"],"_links":{"self":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/2654","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\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2654"}],"version-history":[{"count":0,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/2654\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/media\/2653"}],"wp:attachment":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}