18 Nov 2026, Wed

Critical Yul Optimizer Bug Discovered in Solidity Compiler Versions 0.8.19 through 0.8.37

The Ethereum Foundation and the Solidity core development team have officially released Solidity version 0.8.38, bringing with it a vital patch for a low-severity optimizer bug that affected a wide range of previous compiler iterations. Originally uncovered through the Ethereum Foundation’s bug bounty program, the vulnerability exposes a flaw deep within the Yul optimizer’s internal memory and storage tracking logic. While extensive automated scans indicate that the issue is exceedingly rare in real-world deployments, the bug has underscored the delicate complexities involved in modern smart contract optimization and intermediate representation compilation.

The discovery unfolded in two distinct phases over the late summer and early autumn. On August 17, 2026, security researcher Daniel Boye formally reported a bug in the Yul optimizer through the Ethereum Foundation. Boye’s initial findings revealed that under specific conditions, the compiler’s optimizer could incorrectly determine that two distinct memory or storage locations were entirely separate, even when those locations actually coincided at runtime. This faulty deduction meant that the compiler could dangerously replace a memory or storage load operation with an outdated, cached value, or erroneously strip out a store operation that the contract logic fundamentally required to execute properly.

Following that initial disclosure, a second, complementary report was submitted on September 28, 2026, by Surya Prakash Akula. Akula’s findings provided crucial additional context, demonstrating that the underlying optimization bug could be successfully triggered straight from plain, high-level Solidity code, entirely without the need for any manual inline assembly blocks. The combined insights from both researchers allowed the Solidity team to trace the root cause back to a cache invalidation flaw that was originally introduced years prior in Solidity 0.8.19. Consequently, every compiler version released between 0.8.19 and 0.8.37 inclusive is affected by the flaw.

Which Contracts Are Affected and How the Bug Manifests

The core development team has assigned a severity rating of low to the vulnerability, primarily due to the narrow set of strict conditions required for the bug to manifest in production bytecode. Most importantly, smart contracts are completely unaffected if they are compiled with the Yul optimizer disabled. However, when the optimizer is active, the vulnerability’s reach depends heavily on the compilation pipeline being utilized.

When developers compile code using the --via-ir flag or settings.viaIR in Standard JSON, any code can theoretically be impacted, including standard contracts devoid of inline assembly. Similarly, contracts compiled directly as pure Yul via --strict-assembly or "language": "Yul" in Standard JSON fall into the affected category. Conversely, projects relying on the legacy default evmasm pipeline face a much narrower exposure window. Under the default pipeline, only compiler-generated Yul utility functions and isolated inline assembly blocks that omit any direct references to surrounding Solidity variables or functions can potentially be affected.

Understanding whether a specific smart contract contains the necessary vulnerable patterns is exceptionally difficult by merely reviewing the high-level Solidity or Yul source code. This uncertainty stems from the fact that the intermediate Yul representation that feeds directly into the vulnerable optimizer passes is heavily dictated by the specific compiler version used, the exact ordering of optimizer steps, and the surrounding context of the codebase.

Despite this complexity, known reproduction cases sharing the default optimizer sequence typically follow a specific pattern. Usually, a local variable utilized for address calculation is modified within a loop or conditional branch, both before and after the initial address is derived from it. Subsequently, an entirely different value is written to that same location via an address derived from the updated value. Furthermore, the target Ethereum Virtual Machine (EVM) version does not influence whether the bug ultimately manifests in the compiled artifact.

Technical Details Behind the Optimizer Flaw

To comprehend why the vulnerability occurs, it is necessary to examine the internal architecture of the Yul optimizer components responsible for tracking memory and storage states. The system relies heavily on a mechanism known as LoadResolver, which actively optimizes performance by replacing repetitive mload, sload, and keccak256 instructions with pre-existing values the compiler already knows. Working in tandem, the EqualStoreEliminator removes redundant storage or memory writes if it determines that the target location already holds the exact value being written. Both of these optimization subsystems depend on a shared bookkeeping structure that maps the known contents of memory and storage.

When the optimizer encounters a store operation where it cannot precisely determine the exact memory or storage location being modified, it must play it safe by clearing out everything it previously recorded about every location that the store might possibly overwrite. To decide which locations fall into this danger zone, the optimizer consults the KnowledgeBase, an internal component dedicated to evaluating mathematical and logical relationships between different variables.

Historically, the KnowledgeBase represents variables symbolically as constant offsets originating from a base variable. If a variable holds a flat constant value, its base is treated as zero. If its value cannot be neatly expressed as a constant offset, it is treated as an independent unknown, with the variable acting as its own base and an offset of zero. For example, after executing instructions that establish a base address from calldata and subsequently adding an offset, the optimizer tracks them accordingly. Two addresses sharing the same base were historically deemed distinct if their calculated offsets differed by at least 32 bytes for memory operations, or simply differed at all for storage slots. Once deemed distinct, the optimizer would safely preserve its knowledge of one location even when a write operation targeted the other.

The vulnerability itself was born from an optimization introduced in Solidity 0.8.19, which added a caching layer to store these variable representations. Prior to this version, the KnowledgeBase calculated offsets dynamically on the fly from the current values of the variables. While treating an unknown value as safe is standard practice because it merely restricts aggressive optimizations, relying on stale or outdated cached data can lead directly to incorrect code generation.

The caching system relied on a lazy invalidation scheme. Whenever the KnowledgeBase performed a variable lookup, it compared the variable’s current value expression against the expression it recorded during the previous interaction. If a discrepancy was found, the system would reset the cached entry. However, this lazy check could fail to catch reassignments under specific conditions. When missed, two separate addresses could end up being represented as offsets from the same base variable, even though one address was derived from the base value prior to a reassignment and the other from the value after it.

Because the optimizer mistakenly treated both offsets as relative to one single, unchanging value, it incorrectly concluded that the two memory or storage locations were mutually distinct. This false assumption allowed the optimizer to retain outdated assumptions across store operations. Consequently, a subsequent load from the first location could be erroneously replaced with an outdated value, a necessary store could be stripped away entirely, or a keccak256 hashing operation could end up processing stale data.

Practical Examples and Real-World Risk Assessment

The real-world danger of this optimizer flaw can be observed through minimal Solidity constructs. Consider a contract managing a static storage array where structure members map directly to sequential storage slots. If a function utilizes a loop counter to compute array indices, modifies that counter across multiple loops, and performs successive writes to computed indices, the lazy caching mechanism can fail to recognize that the underlying base variable has shifted.

In a documented test case analyzed by the core team, compiling a contract with --via-ir and the optimizer enabled resulted in a function returning an outdated parameter value (0xaaaa) instead of the newly written state (0xbbbb). The compiler’s KnowledgeBase failed to record that the variable used for address derivation had changed between writes, falsely concluding that the second write could not possibly overwrite the storage slot of the first. This caused the final load operation to pull the obsolete value straight from the compiler’s faulty assumptions.

Despite the severity of the theoretical flaw, the Ethereum Foundation and the Solidity team emphasize that the practical likelihood of encountering this bug in production smart contracts is remarkably low. The prerequisites for the bug to trigger require a fragile alignment of intermediate Yul code patterns combined with runtime address collision. Furthermore, a comprehensive scan of the Sourcify database—involving roughly 283,000 verified compilations utilizing --via-ir and over 607,000 using the legacy evmasm pipeline rebuilt with development compilers—produced zero instances of differing output bytecode. While this scan provides strong confidence that the bug is exceptionally rare, the core team notes it does not serve as an absolute guarantee for every custom deployment.

The Permanent Fix and Recommended Actions

To permanently resolve the issue, the Solidity development team completely replaced the flawed lazy invalidation strategy with a rigorous explicit versioning system within the KnowledgeBase. Every variable tracked by the optimizer now carries an explicit version number that automatically increments whenever the compiler records a modification to that variable’s underlying value. Consequently, cached representations are now stored uniquely per variable and version. Following any variable reassignment, the system treats the variable as an entirely new entity, ensuring that legacy cache entries can never become stale or trigger incorrect assumptions.

All developers utilizing Solidity versions 0.8.19 through 0.8.37 are strongly advised to upgrade their compiler toolchains immediately to Solidity 0.8.38 or any later secure release. For projects unable to upgrade immediately, disabling the Yul optimizer entirely will eliminate exposure to the vulnerability, though at the cost of increased gas consumption. The Ethereum Foundation has expressed its gratitude to security researchers Daniel Boye and Surya Prakash Akula for their diligent reporting through the official bug bounty program, which ultimately safeguarded the broader decentralized ecosystem from potential silent compilation failures.

Leave a Reply

Your email address will not be published. Required fields are marked *