{"id":3595,"date":"2026-11-08T07:50:02","date_gmt":"2026-11-08T07:50:02","guid":{"rendered":"https:\/\/wyominginvest.com\/?p=3595"},"modified":"2026-11-08T07:50:02","modified_gmt":"2026-11-08T07:50:02","slug":"solidity-security-advisory-critical-yul-optimizer-bug-discovered-in-versions-0-8-19-through-0-8-37","status":"publish","type":"post","link":"https:\/\/wyominginvest.com\/?p=3595","title":{"rendered":"Solidity Security Advisory: Critical Yul Optimizer Bug Discovered in Versions 0.8.19 through 0.8.37"},"content":{"rendered":"<p>The Ethereum Foundation and the core Solidity development team have issued an essential security advisory regarding a compiler bug located within the Yul optimizer. Originally uncovered late in the summer of 2026, the vulnerability impacts a wide range of Solidity compiler versions and poses potential risks to smart contract memory and storage operations under specific, highly specialized conditions. Although extensive database scans indicate that the bug manifests very rarely in deployed production code, the development team has strongly urged all developers utilizing affected versions to upgrade their toolchains immediately.<\/p>\n<p>The discovery of the bug unfolded in two distinct phases through the Ethereum Foundation\u2019s bug bounty program. On August 17, 2026, security researcher Daniel Boye submitted the initial bug report, demonstrating that flaws in the Yul optimizer could cause the compiler to treat two distinct memory or storage locations as separate even when they actually coincide during runtime execution. Because of this faulty tracking mechanism, a memory load instruction can be erroneously replaced with an outdated value, or alternatively, a necessary storage write operation can be entirely eliminated by the compiler. Weeks later, on September 28, 2026, a second independent report submitted by Surya Prakash Akula revealed that this vulnerability was not merely an edge case confined to low-level assembly blocks; it could be triggered directly from plain, high-level Solidity code without utilizing any inline assembly whatsoever.<\/p>\n<p>Upon internal evaluation, the Solidity team assigned the vulnerability a severity rating of low, largely due to the fragile and highly restrictive set of prerequisites required to trigger it. The issue is exclusively present in code compiled with the Yul optimizer enabled. However, the introduction of modern compilation pipelines broadens the scope significantly. When compiling with the modern <code>--via-ir<\/code> command-line flag\u2014or equivalently via <code>settings.viaIR<\/code> in Standard JSON configurations\u2014any code can theoretically be affected, including pure Solidity contracts devoid of inline assembly. The same broad exposure applies to raw Yul source code compiled directly with <code>--strict-assembly<\/code> or via the matching Standard JSON language designation. Conversely, projects relying on the legacy default <code>evmasm<\/code> pipeline face a much narrower risk profile, as only compiler-generated Yul utility functions and specific inline assembly blocks that omit references to external Solidity variables or functions are potentially vulnerable.<\/p>\n<p>Tracing the lineage of the defect reveals that the flaw was accidentally introduced alongside architectural compiler updates in Solidity version 0.8.19. Consequently, every subsequent release spanning from 0.8.19 up through version 0.8.37 is affected by the optimizer defect. To resolve the issue, the core team released Solidity version 0.8.38, which incorporates a robust and permanent fix for the underlying compiler logic. <\/p>\n<p>To gauge the real-world prevalence of the bug among deployed decentralized applications, the development team executed an extensive scan of the Sourcify verified contract database. Researchers rebuilt hundreds of thousands of verified contracts using a specialized development build of the compiler, compiling each source base twice\u2014once with the vulnerable optimizer behavior and once with the applied fix. This comprehensive audit covered roughly 283,000 verified compilations utilizing the modern <code>--via-ir<\/code> pipeline alongside approximately 607,000 compilations processed through the legacy <code>evmasm<\/code> pipeline. Notably, none of the tested contracts produced differing bytecode between the two compiler states. While this empirical result provides strong reassurance that the bug is exceptionally rare in practice, developers are reminded that such scans cannot provide an absolute guarantee for every custom contract implementation.<\/p>\n<p>Which Contracts Are Affected?<\/p>\n<p>Determining whether a specific smart contract is vulnerable requires meeting a precise conjunction of compiler settings and internal code structures. Fundamentally, a contract is only impacted if the Yul optimizer is active during compilation, if the intermediate representation pipeline or strict assembly mode is utilized, and if the internal optimizer components encounter specific code patterns involving variable reassignment across loops or conditional branches. <\/p>\n<p>Because conditions regarding intermediate Yul code generation cannot be reliably verified through Solidity source code inspection alone, assessing risk manually remains challenging. The intermediate Yul text that feeds into the affected optimizer stages depends heavily on the specific compiler version, the sequence of optimization passes configured by the developer, and the surrounding block context. Nevertheless, analysis of known code reproducers utilizing the default optimizer sequence highlights a recurring structural pattern. Typically, this involves a local variable used for address calculation that is modified within a loop or branch structure, both before and after an initial address is derived from it. When a subsequent value is stored into the same physical slot through an address derived from the updated variable value, the optimizer can become confused. Notably, the target EVM version chosen for deployment does not influence whether the bug manifests; the core issue remains strictly tied to the compilation phase. If a contract is compiled with the Yul optimizer completely disabled, it remains entirely immune to the vulnerability.<\/p>\n<p>Technical Details<\/p>\n<p>Understanding why the compiler misbehaves requires examining the internal architecture of the Yul optimizer, particularly how it tracks memory and storage contents during compilation passes. The optimization pipeline relies heavily on specific analyzer components to optimize data flow and eliminate redundant operations.<\/p>\n<p>The component known as <code>LoadResolver<\/code> is responsible for replacing memory load (<code>mload<\/code>), storage load (<code>sload<\/code>), and hashing (<code>keccak256<\/code>) instructions with previously cached values when it recognizes that the target location has already been written to. Simultaneously, another component called <code>EqualStoreEliminator<\/code> strips away redundant store instructions if it knows the target location already holds the target value. Both of these optimization mechanisms rely on a shared bookkeeping ledger that tracks the known contents of memory and storage at any given point in the program execution flow.<\/p>\n<p>However, when the optimizer encounters a store instruction where the exact destination address cannot be statically determined with absolute certainty, it must conservatively invalidate its knowledge regarding every memory or storage location that the store might potentially overwrite. To determine which locations fall into this danger zone, the optimizer queries the <code>KnowledgeBase<\/code>, an internal subsystem dedicated to answering relational questions about variables.<\/p>\n<p>Addresses as Offsets from a Base Variable<\/p>\n<p>The <code>KnowledgeBase<\/code> represents variables symbolically as a constant offset derived from an underlying base variable. If a variable resolves to a static constant value, the base is evaluated as zero. If the value cannot be expressed neatly as a constant offset from a known base, the variable is treated as an unknown entity, effectively acting as its own base with an offset of zero. For instance, if a contract snippet executes code equivalent to defining a base via calldata loading and subsequently derives a pointer by adding a small integer offset, the base variable remains its own foundation while the pointer is symbolically represented as the base plus the specified offset.<\/p>\n<p>Within this system, two distinct addresses sharing the same base variable are recognized as non-overlapping if their constant offsets differ sufficiently\u2014specifically, if they are separated by at least 32 bytes in memory or represent different storage slots. When this condition is met, the optimizer safely assumes that writing to one location does not invalidate what it knows about the contents of the other location. <\/p>\n<p>The mechanism responsible for caching these symbolic representations per variable was introduced alongside other optimizations in Solidity 0.8.19. Prior to this version, the <code>KnowledgeBase<\/code> computed address offsets dynamically on the fly from current variable values during every evaluation, avoiding persistent state assumptions.<\/p>\n<p>Stale Cache Entries<\/p>\n<p>In compiler design, treating an unknown value as safe is standard practice because it merely restricts aggressive optimizations rather than altering execution semantics. Conversely, relying on stale or outdated cached assumptions can produce catastrophically incorrect compiled code. A cached entry in the optimizer becomes invalid the moment the underlying value of its associated variable changes. <\/p>\n<p>In the vulnerable compiler versions, cache invalidation was handled lazily. Whenever the <code>KnowledgeBase<\/code> performed a variable lookup, it compared the current value expression of the variable against the expression recorded during the previous encounter. If a discrepancy was detected, the cached entry was reset. However, this lazy verification check could fail to detect a reassignment under specific control-flow conditions.<\/p>\n<p>When such a failure occurred, two different memory or storage addresses might be represented as offsets originating from the same base variable, even though one address was derived from the base value prior to a reassignment and the other was derived from the base value after the reassignment. The optimizer incorrectly treated both offsets as relative to a single, unchanging value, leading it to conclude that the two target locations were completely distinct. Consequently, it preserved its cached assumptions about the first location across a store operation targeting the second location. If those two locations happened to coincide during runtime execution, subsequent load operations from the first location were incorrectly replaced with outdated cached values, necessary store operations were omitted, or hashing operations were performed on obsolete data.<\/p>\n<p>Example<\/p>\n<p>To illustrate how this compiler behavior manifests in practice, security analysts examined a simplified smart contract written in plain Solidity, devoid of any inline assembly constructs. The example contract features a static array of structs where each struct contains a single unsigned integer member, aligning storage slots directly with array indices.<\/p>\n<p>When compiling and executing functions that feature repetitive loop structures modifying index variables before and after address derivation, the optimizer can lose track of program state. In test scenarios evaluated by the core team, executing specific parameter combinations resulted in the function returning an outdated value written during an earlier loop iteration rather than the final updated value intended by the logic. In the generated Yul code, slot calculations derived from loop index variables before and after modification were incorrectly treated by the <code>KnowledgeBase<\/code> as non-conflicting, causing the compiler to replace a final memory load instruction with an older parameter value.<\/p>\n<p>Severity Assessment<\/p>\n<p>The practical risk of encountering this bug in real-world deployments remains exceptionally low due to the stringent combination of intermediate Yul code patterns required to trigger the flaw. Furthermore, the two affected memory or storage locations must physically coincide at runtime for an observable error to occur. However, in contracts where address offsets are derived directly from external call arguments, sophisticated callers might theoretically craft specific transaction inputs designed to force overlapping locations.<\/p>\n<p>Because the compiler emits no warning when this optimization flaw occurs and the resulting bytecode does not necessarily trigger an immediate runtime revert, developers must rely on preventative version control. The Sourcify database audit confirmed that existing verified contracts showed no outward signs of altered bytecode, though the fact that historical compilations utilized varying precursor optimization passes means the scan cannot serve as an absolute universal warranty.<\/p>\n<p>The Fix<\/p>\n<p>To eliminate the vulnerability permanently, the Solidity engineering team refactored the internal tracking logic within the <code>KnowledgeBase<\/code>. The updated compiler architecture replaces the fragile lazy invalidation scheme with explicit variable versioning. Every variable tracked within the <code>KnowledgeBase<\/code> now maintains an explicit version counter that increments automatically whenever the optimizer records a modification to the variable&#8217;s value. Cached symbolic representations are now stored uniquely per variable and version pair. Consequently, whenever a variable is reassigned, it is treated as an entirely fresh entity within the system, ensuring that existing cache entries can never become stale or misaligned across program branches.<\/p>\n<p>Recommended Actions<\/p>\n<p>All developers utilizing Solidity compiler versions 0.8.19 through 0.8.37 are strongly advised to upgrade their development environments to Solidity 0.8.38 or any later patched release. Projects utilizing the Yul optimizer, the <code>--via-ir<\/code> compilation pipeline, or strict Yul assembly modes should recompile their smart contract suites immediately to ensure complete protection against potential optimizer misbehavior.<\/p>\n<p>Acknowledgements<\/p>\n<p>The Ethereum Foundation and the Solidity core team expressed their gratitude to the security research community for identifying and responsibly disclosing the vulnerability. Special recognition was extended to Daniel Boye for submitting the initial bug report through the official Ethereum Foundation bug bounty program, as well as to Surya Prakash Akula for providing the subsequent report demonstrating that the vulnerability could be reached directly through plain, high-level Solidity source code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ethereum Foundation and the core Solidity development team have issued an essential security advisory regarding a compiler bug located within the Yul optimizer. Originally uncovered late in the summer of 2026, the vulnerability impacts a wide range of Solidity compiler versions and poses potential risks to smart contract memory and storage operations under specific,<\/p>\n","protected":false},"author":26,"featured_media":3594,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[2987,401,201,949,2015,5,400,402,1051],"class_list":["post-3595","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-advisory","tag-auditing","tag-critical","tag-discovered","tag-optimizer","tag-security","tag-smart-contracts","tag-solidity","tag-versions"],"_links":{"self":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/3595","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\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3595"}],"version-history":[{"count":0,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/posts\/3595\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=\/wp\/v2\/media\/3594"}],"wp:attachment":[{"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyominginvest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}