{"id":4854,"date":"2026-11-30T15:15:15","date_gmt":"2026-11-30T15:15:15","guid":{"rendered":"https:\/\/smartcryptosecurity.com\/?p=4854"},"modified":"2026-11-30T15:15:15","modified_gmt":"2026-11-30T15:15:15","slug":"solidity-compiler-bug-discovered-in-yul-optimizer-prompts-urgent-security-update-to-version-0-8-38","status":"publish","type":"post","link":"https:\/\/smartcryptosecurity.com\/?p=4854","title":{"rendered":"Solidity Compiler Bug Discovered in Yul Optimizer Prompts Urgent Security Update to Version 0.8.38"},"content":{"rendered":"<p>The Ethereum Foundation has released Solidity version 0.8.38, featuring a critical bug fix for a flaw discovered within the Yul intermediate representation optimizer. The vulnerability, which affects a wide range of compiler versions spanning over several years, could theoretically cause smart contracts to load outdated memory or storage values, or improperly eliminate necessary write operations. While security analysts have rated the issue as having a &quot;low&quot; overall severity due to the extremely specific and fragile conditions required for exploitation, developers utilizing the affected compiler versions are strongly urged to update their toolchains immediately.<\/p>\n<p>The discovery of the optimization flaw unfolded across two independent reports submitted through the Ethereum Foundation\u2019s official bug bounty program. The first report was filed on August 17, 2026, by researcher Daniel Boye, who initially identified suspicious behavior within the Yul optimizer. Boye\u2019s analysis demonstrated that the optimizer could occasionally treat two distinct memory or storage locations as separate even when they actually coincided at runtime. Consequently, this flawed logic could lead the compiler to replace a required data load with an obsolete value or optimize away a critical storage write. <\/p>\n<p>Several weeks later, a second crucial report was received on September 28, 2026, from researcher Surya Prakash Akula. Akula\u2019s findings significantly widened the scope of concern by proving that the bug was not merely an edge-case issue isolated to low-level assembly, but could be triggered directly from plain, high-level Solidity code without the use of any inline assembly blocks. <\/p>\n<p>According to the core Solidity development team, the bug was originally introduced into the compiler in version 0.8.19. All subsequent versions ranging from 0.8.19 through 0.8.37 are affected when specific compilation settings are used. The issue has been fully resolved in version 0.8.38.<\/p>\n<p><strong>Which Contracts Are Affected and How the Bug Manifests<\/strong><\/p>\n<p>The vulnerability is tightly bound to how the compiler&#8217;s Yul optimizer processes variable relationships and memory tracking. Code compiled with the Yul optimizer entirely disabled remains completely safe and is not affected by the flaw. However, projects utilizing the <code>--via-ir<\/code> command-line flag\u2014or the corresponding <code>settings.viaIR<\/code> parameter in Standard JSON inputs\u2014may be vulnerable, including standard contracts written entirely without inline assembly. The same risk applies to Yul files compiled directly with <code>--strict-assembly<\/code> or <code>\"language\": \"Yul\"<\/code> in Standard JSON. Under the default <code>evmasm<\/code> compilation pipeline, the vulnerability is restricted solely to compiler-generated Yul utility functions and inline assembly blocks that do not reference any underlying Solidity variables or functions.<\/p>\n<p>Determining whether a specific smart contract is vulnerable purely by inspecting its high-level source code presents a significant challenge. Conditions governing the intermediate Yul code that feed into the faulty optimizer steps depend heavily on the precise compiler version, the sequence of optimizer passes, and the surrounding context of the code. All known reproduction test cases sharing the default optimizer sequence follow a distinct pattern: a local variable utilized for calculating memory or storage addresses is modified inside a loop or conditional branch, both before and after the initial address is derived from it. A different value is subsequently stored at the target location using an address derived from the updated variable. Notably, the target Ethereum Virtual Machine (EVM) version does not influence whether the vulnerability manifests.<\/p>\n<p><strong>Technical Details of the Yul Optimizer Flaw<\/strong><\/p>\n<p>To understand the root cause of the bug, developers must examine the internal mechanisms of the Yul optimizer, specifically the components responsible for tracking state. The <code>LoadResolver<\/code> component is designed to optimize performance by replacing <code>mload<\/code>, <code>sload<\/code>, and <code>keccak256<\/code> instructions with known values it has tracked previously, thereby reusing data written by an earlier store operation to the same location. Simultaneously, the <code>EqualStoreEliminator<\/code> removes redundant storage writes if the location is already known to contain the identical value. Both components depend on shared bookkeeping regarding the known contents of memory and storage.<\/p>\n<p>When the optimizer encounters a store operation where the exact target location cannot be definitively determined, it must clear its memory of any stored knowledge concerning locations that the write might potentially overwrite. To determine which locations are affected, the system consults the <code>KnowledgeBase<\/code>, an internal component that evaluates mathematical relationships and offsets between different variables.<\/p>\n<p>The <code>KnowledgeBase<\/code> traditionally represents variables symbolically as constant offsets originating from a base variable. If a variable holds a static constant, its base is treated as zero. If the offset cannot be expressed as a constant, the variable serves as its own base with a zero offset. For instance, after executing instructions like <code>let base := calldataload(0)<\/code> and <code>let ptr := add(base, 2)<\/code>, <code>base<\/code> acts as its own base while <code>ptr<\/code> is symbolically represented as <code>base + 2<\/code>. <\/p>\n<p>Two addresses sharing the same base variable are considered distinct by the optimizer if their offsets differ for storage locations, or if they maintain a distance of at least 32 bytes apart for memory locations. When these conditions are met, the optimizer preserves its tracking data for one location even when a write operation occurs on the other. <\/p>\n<p>The mechanism responsible for caching these symbolic representations per variable was introduced in Solidity 0.8.19. Prior to that update, the <code>KnowledgeBase<\/code> calculated offsets dynamically on the fly from current variable values. Under the new caching system, optimization safety relies entirely on ensuring cache entries do not become stale when variable values change. <\/p>\n<p>Because the cache was previously invalidated lazily\u2014meaning the <code>KnowledgeBase<\/code> only checked a variable&#8217;s current value expression against its last recorded state upon a lookup\u2014certain reassignments could bypass detection. Specifically, if a reassignment went unnoticed, two addresses could be represented as offsets originating from the same base variable, even though one was derived prior to the base variable&#8217;s reassignment and the other derived afterward. The optimizer incorrectly treated both offsets as relative to a single, unchanging value, erroneously concluding that the two memory or storage locations were completely distinct. If those locations happened to coincide during execution at runtime, subsequent reads could fetch outdated data, and necessary writes could be incorrectly discarded.<\/p>\n<p><strong>Demonstrating the Vulnerability Through Example<\/strong><\/p>\n<p>The Solidity team provided a concrete contract example to illustrate how the vulnerability can manifest without any inline assembly when compiled via the intermediate representation pipeline:<\/p>\n<pre><code class=\"language-solidity\">contract C \n    struct S  uint256 v; \n    S[20] public a;\n\n    function g(uint256 max1, uint256 max2, uint256 aaaa, uint256 bbbb) external returns (uint256) \n        uint256 i;\n        for (uint256 j; j &lt; max1; j++) i++;\n        uint256 k = i + 2;\n        a[k].v = aaaa;\n        for (uint256 j; j &lt; max2; j++) i++;\n        a[i].v = bbbb;\n        return a[k].v;\n    \n<\/code><\/pre>\n<p>In this contract, <code>a<\/code> is a static array whose storage begins at slot zero. Since the struct <code>S<\/code> contains a single value-type member, each element occupies exactly one storage slot, aligning each element&#8217;s slot directly with its index. When invoking the function <code>g(0, 2, 0xaaaa, 0xbbbb)<\/code>, the first loop does not execute, leaving <code>k<\/code> equal to <code>2<\/code> and writing <code>0xaaaa<\/code> to <code>a[2].v<\/code>. The second loop runs twice, incrementing <code>i<\/code> to <code>2<\/code>, which then writes <code>0xbbbb<\/code> to the exact same storage location. Logically, the function should return <code>0xbbbb<\/code>. <\/p>\n<p>However, under affected compiler versions with the optimizer enabled via <code>--via-ir<\/code>, the generated Yul code derives the storage slot for <code>a[k].v<\/code> from <code>i<\/code> before the second loop, and the slot for <code>a[i].v<\/code> from <code>i<\/code> after the second loop. Because the optimizer tracks no specific value for <code>i<\/code> at these points, it treats <code>i<\/code> as its own base and represents the two slots as <code>i + 2<\/code> and <code>i<\/code>. The <code>KnowledgeBase<\/code> fails to recognize that these expressions reflect different temporal states of <code>i<\/code>, incorrectly determining that the two write operations must target separate slots. As a result, the final load from <code>a[k].v<\/code> is replaced with the obsolete parameter value <code>aaaa<\/code>, causing the function to return <code>0xaaaa<\/code> instead of <code>0xbbbb<\/code>.<\/p>\n<p><strong>Severity Assessment and Ecosystem Scanning<\/strong><\/p>\n<p>The compiler emits no warnings when this bug is triggered, and the generated bytecode does not necessarily cause transactions to revert at runtime. The primary symptoms are silent data corruption, where loads return stale values or writes are lost entirely. <\/p>\n<p>Despite the underlying complexity of the flaw, the probability of encountering the bug in real-world smart contracts is considered very low. The conditions required within the intermediate Yul code are highly fragile, and the affected memory or storage locations must actively coincide during runtime execution. Nevertheless, if target addresses are derived directly from external call arguments, sophisticated callers might theoretically craft specific transaction inputs to force collisions.<\/p>\n<p>To gauge the prevalence of the issue across deployed decentralized applications, the development team conducted an extensive scan of the Sourcify database. By rebuilding approximately 283,000 verified compilations utilizing <code>--via-ir<\/code> and roughly 607,000 compilations using the default <code>evmasm<\/code> pipeline\u2014comparing outputs from a development compiler build with and without the fix\u2014the team found that none of the scanned contracts produced differing bytecode. While this empirical check provides strong confidence that the bug is exceptionally rare, developers should note that the scan cannot categorically rule out the existence of vulnerable contracts, as historical compilation environments and prior optimizer passes varied across versions.<\/p>\n<p><strong>Implementing the Fix and Recommended Actions<\/strong><\/p>\n<p>To eliminate the root cause of stale cache entries, the core team redesigned the <code>KnowledgeBase<\/code> architecture. The updated implementation replaces lazy cache invalidation with an explicit variable versioning system. Every variable tracked within the <code>KnowledgeBase<\/code> now maintains an internal version counter that increments automatically whenever the optimizer records any modification to its value. Cached representations are subsequently stored in association with both the specific variable and its precise version. Consequently, whenever a variable undergoes reassignment, it is treated as an entirely new entity, preventing existing cache entries from ever becoming stale.<\/p>\n<p>Smart contract developers and project maintainers are strongly advised to upgrade their Solidity compiler toolchains to version 0.8.38 immediately. Projects relying on automated build scripts, continuous integration pipelines, or framework configurations such as Hardhat, Foundry, or Truffle should verify that their compiler version constraints are updated to prevent accidental deployment using vulnerable intermediate representation settings. <\/p>\n<p>The Ethereum Foundation expressed gratitude to security researchers Daniel Boye and Surya Prakash Akula for their independent vulnerability reports submitted through the official bug bounty initiative, which enabled the rapid identification and resolution of the compiler defect.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ethereum Foundation has released Solidity version 0.8.38, featuring a critical bug fix for a&#8230;<\/p>\n","protected":false},"author":16,"featured_media":4853,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[401,1230,962,2002,593,5,400,402,1229,1341],"class_list":["post-4854","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-auditing","tag-compiler","tag-discovered","tag-optimizer","tag-prompts","tag-security","tag-smart-contracts","tag-solidity","tag-urgent","tag-version"],"_links":{"self":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/4854","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\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4854"}],"version-history":[{"count":0,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/4854\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/media\/4853"}],"wp:attachment":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}