Home / Smart Contract Auditing / Solidity Version 0.8.38 Released to Patch Yul Optimizer Memory and Storage Bug

Solidity Version 0.8.38 Released to Patch Yul Optimizer Memory and Storage Bug

The Ethereum Foundation and the Solidity core development team have officially released Solidity version 0.8.38, introducing a crucial security patch to resolve an optimizer-related bug in the Yul intermediate language pipeline. Initially discovered through the Ethereum Foundation’s bug bounty program, the vulnerability affects a wide range of previous compiler versions and could, under specific and rare runtime conditions, cause smart contracts to load outdated values or erroneously omit essential memory and storage write operations.

The issue was first brought to light on August 17, 2026, when developer Daniel Boye submitted a bug report through the official Ethereum Foundation bug bounty initiative. Boye’s analysis highlighted a flaw within the Yul optimizer, a core component responsible for translating and streamlining contract bytecode for maximum efficiency. The initial finding demonstrated that the optimizer could occasionally treat two distinct memory or storage locations as entirely separate entities even when those locations happened to coincide during actual runtime execution.

A subsequent vulnerability report submitted on September 28, 2026, by researcher Surya Prakash Akula provided vital additional context to the development team. Akula’s findings proved that the bug was not restricted to low-level assembly blocks or specialized developer environments; rather, it could be successfully triggered directly from plain, standard Solidity code without utilizing any inline assembly whatsoever.

Following comprehensive analysis, the Solidity team assigned the vulnerability a severity rating of low on their internal scale. This classification stems from the intricate and narrow combination of programmatic conditions required to successfully reproduce the bug. Nevertheless, because smart contract integrity and precise state management are paramount within decentralized finance and blockchain architecture, developers utilizing affected compiler versions have been strongly urged to update their toolchains immediately.

Which Contracts Are Affected?

The newly patched vulnerability is closely tied to the activation of the Yul optimizer, meaning that any contract compiled with the optimizer disabled remains entirely unaffected by the issue. However, the scope of potential vulnerability broadens significantly depending on the specific compilation pathways and flags utilized during the build process.

When developers compile contracts using the modern --via-ir command-line flag or the equivalent settings.viaIR parameter in Standard JSON inputs, any code base can potentially be exposed, including those entirely devoid of inline assembly blocks. The same vulnerability characteristics apply to Yul code compiled directly using the --strict-assembly flag or the corresponding "language": "Yul" setting within Standard JSON configurations. Conversely, projects relying on the legacy default evmasm compilation pipeline face a much narrower exposure window. Under the default pipeline, only compiler-generated Yul utility functions and specific inline assembly blocks that omit any direct references to surrounding Solidity variables or functions are potentially susceptible.

The introduction of the underlying flaw dates back to the release of Solidity 0.8.19. Consequently, all compiler versions spanning continuously from 0.8.19 through 0.8.37 are affected by the optimization defect. The newly deployed Solidity 0.8.38 release permanently resolves the underlying logic error, closing the vulnerability window for all future deployments.

To gauge the real-world prevalence of the bug, the core development team conducted an extensive empirical scan of the Sourcify smart contract verification database. By rebuilding verified contracts using a specialized development build of the compiler—compiling each source once with the optimization bug present and once with the bug fix applied—the team analyzed approximately 283,000 verified compilations utilizing the --via-ir pipeline and roughly 607,000 compilations utilizing the legacy evmasm pipeline.

Remarkably, none of the nearly 900,000 evaluated compilations produced differing compiled bytecode outcomes. While this extensive testing provides strong empirical confidence that the practical manifestation of the bug is exceptionally rare in deployed production environments, developers are cautioned that empirical scarcity does not mathematically guarantee that every individual contract is immune. Furthermore, the targeted Ethereum Virtual Machine version configured for deployment does not alter or mitigate whether the bug can potentially manifest.

Technical Details

Understanding the root cause of the vulnerability requires diving deep into the internal architecture of the Solidity compiler and its intermediate representation framework, Yul. The Yul optimizer relies heavily on specialized internal components designed to streamline execution by tracking and optimizing memory and storage interactions.

Within the optimizer, a component designated as LoadResolver is responsible for replacing costly mload, sload, and keccak256 instructions with pre-existing values that the compiler already knows reside in a given location. This allows the compiler to safely reuse values written by preceding store instructions. Concurrently, an EqualStoreEliminator component works to strip away redundant storage or memory write operations if the target location is already known to contain the precise value being written. Both of these optimization subsystems rely entirely on a unified bookkeeping mechanism that monitors the presumed contents of memory and storage.

During optimization passes, the compiler occasionally encounters situations where it cannot determine with absolute certainty the exact location a specific store operation targets. When this ambiguity arises, the optimizer must conservatively invalidate and forget everything it previously recorded about every memory or storage location that the ambiguous store might potentially overwrite. To accurately determine which locations fall into this danger zone, the optimizer consults the KnowledgeBase, an internal subsystem designed to deduce logical mathematical relationships between various program variables.

The KnowledgeBase represents variables symbolically as constant offsets originating from a designated base variable. If a variable’s value equates to a static constant, its base is recorded as zero. If the value cannot be simplified into a constant offset, the variable is treated as its own independent base possessing an offset of zero. For example, following operational statements such as let base := calldataload(0) and let ptr := add(base, 2), the variable base acts as its own foundational base, while ptr is symbolically represented as base + 2.

Under normal operational rules, two distinct addresses sharing the same base variable are deemed independent and safe if their respective offsets differ by adequate margins—specifically, differing for storage slots or maintaining at least a 32-byte separation for memory allocations. When these criteria are met, the optimizer preserves its knowledge base regarding one location even when a write operation targets the other.

To enhance performance, these symbolic representations were cached on a per-variable basis, a caching optimization introduced initially in Solidity 0.8.19. Prior to this version, the KnowledgeBase calculated variable offsets dynamically on the fly from current variable values during each evaluation pass.

Stale Cache Entries and Invalidation Failures

While treating an unknown value with extreme conservatism is inherently safe because it merely restricts aggressive optimization opportunities, relying on an outdated or stale cached value poses severe risks to code correctness. A cached symbolic entry transitions from valid to stale whenever the underlying value of the associated variable changes during program execution.

Historically, the compiler handled cache invalidation through a lazy evaluation strategy. Whenever the KnowledgeBase performed a variable lookup, it compared the variable’s current value expression against the expression recorded during the previous interaction. If the expressions diverged, the system was designed to reset the stale cache entry. However, under certain intricate programming patterns, this lazy validation check failed to detect critical variable reassignments.

These tracking oversights resulted in scenarios where two distinct memory or storage addresses were improperly represented as constant offsets derived 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 subsequent to the change. The optimizer erroneously treated both offsets as relative to a single, unchanging value, concluding incorrectly that the two target locations were mutually distinct.

Consequently, the optimization engine preserved its assumptions about one location across store operations affecting the other. If those distinct locations happened to coincide during actual runtime execution, subsequent load instructions pulling from the first location were incorrectly substituted with outdated values. Furthermore, necessary store operations involving those outdated values could be prematurely purged, or keccak256 cryptographic hashing operations over the locations could inadvertently process obsolete data.

Practical Example and Manifestation

The Solidity development team provided a clear, illustrative contract example demonstrating how the vulnerability can manifest entirely within plain Solidity code when compiled via the IR pipeline with optimization enabled:

contract C 
    struct S  uint256 v; 
    S[20] public a;

    function g(uint256 max1, uint256 max2, uint256 aaaa, uint256 bbbb) external returns (uint256) 
        uint256 i;
        for (uint256 j; j < max1; j++) i++;
        uint256 k = i + 2;
        a[k].v = aaaa;
        for (uint256 j; j < max2; j++) i++;
        a[i].v = bbbb;
        return a[k].v;
    

In this contract, a represents a static storage array whose data begins at storage slot zero. Because structure S contains a single primitive value type member, each array element occupies precisely one storage slot, aligning each slot index directly with the array index.

When invoking function g with parameters g(0, 2, 0xaaaa, 0xbbbb), the initial loop executing up to max1 does not run, leaving i at zero, resulting in k = 2. Consequently, the hex value 0xaaaa is written to storage location a[2].v. Subsequently, the second loop runs twice based on max2, incrementing i to 2, which directs the write of 0xbbbb to the exact same storage location. Logic dictates that calling this function should ultimately return 0xbbbb.

However, under the influence of the optimization bug, the generated Yul intermediate code derives the storage slot for a[k].v from the variable i prior to the second loop, while the slot for a[i].v is derived from i after the loop completes. Because the optimizer tracks no active value for i at these specific junctures, it treats i as its own base, representing the two target slots symbolically as i + 2 and i.

The flawed KnowledgeBase fails to record that these expressions reflect variable states at entirely different execution epochs. It falsely concludes that the two write operations must target locations separated by two slots, erroneously assuming the store to a[i].v cannot possibly overwrite a[k].v. As a result, the final load instruction retrieving a[k].v is improperly optimized and replaced with the earlier parameter value aaaa, causing the function to incorrectly return 0xaaaa instead of 0xbbbb.

Severity Assessment and Resolution

The compiler emits no warning when this optimization anomaly occurs, and the resulting compiled bytecode does not inherently trigger runtime reverts. When triggered, the tangible impact is restricted to data corruption phenomena, such as a load operation returning stale historical data or a critical memory or storage write being silently lost.

While the probability of accidental occurrence in standard developer codebases remains exceptionally low due to the strict preconditions required in the intermediate Yul structure, malicious actors or sophisticated callers capable of carefully calibrating input parameters could potentially craft transaction arguments that intentionally force critical memory or storage collisions.

To permanently resolve the defect, the Solidity core team replaced the error-prone lazy cache invalidation mechanism with an explicit variable versioning architecture. Every variable tracked within the KnowledgeBase now maintains an explicit version number that automatically increments whenever the optimizer records any modification to the variable’s underlying value. Cached symbolic representations are now stored strictly on a per-variable and per-version basis. Following any variable reassignment, the system treats the updated variable as a brand-new entity, ensuring that existing cache entries can never become stale.

Developers maintaining projects utilizing Solidity versions 0.8.19 through 0.8.37 with the Yul optimizer enabled are advised to upgrade their compiler toolchains to version 0.8.38 immediately to ensure absolute compilation safety.

Tagged:

Leave a Reply

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