The Ethereum Foundation and the Solidity development team have officially disclosed a critical low-severity bug residing within the Yul optimizer, affecting an extensive range of compiler versions from Solidity 0.8.19 up to 0.8.37. The vulnerability, which centers around memory and storage location tracking, can under rare and specific conditions cause the optimizer to incorrectly treat two distinct storage or memory slots as identical or, conversely, distinct when they coincide at runtime. This faulty assumption can lead to critical execution flaws, including the replacement of active memory loads with outdated cached values or the improper removal of essential storage write operations.
The issue was initially brought to light through the Ethereum Foundation’s bug bounty program by researcher Daniel Boye on August 17, 2026. Boye’s initial report exposed foundational flaws in how the Yul optimizer evaluates variable relationships. Subsequently, a second vital report submitted by Surya Prakash Akula on September 28, 2026, demonstrated that this deeply technical compiler defect could be triggered directly from plain, high-level Solidity code without requiring any explicit use of inline assembly. Following these disclosures, the core Solidity team conducted extensive internal investigations, confirmed the root cause, and released Solidity 0.8.38 to permanently resolve the issue.
Understanding the Scope and Severity of the Vulnerability
The Solidity development team has assigned a "low" severity rating to the bug on their internal evaluation scale. This assessment stems primarily from the exceptionally narrow and fragile set of preconditions required for the bug to manifest in a production environment. Crucially, contracts are completely unaffected if they are compiled with the Yul optimizer disabled. However, when the optimizer is active, the exact impact depends heavily on the compilation pipeline being utilized.
Under the modern --via-ir compilation pipeline—or when using settings.viaIR in Standard JSON configurations—any smart contract code can theoretically be affected, including pure Solidity code devoid of inline assembly. The same risk profile applies to Yul code compiled directly with the --strict-assembly flag or "language": "Yul" standard JSON parameters. Conversely, projects relying on the traditional, default legacy evmasm pipeline face a much more restricted exposure window. Within the default pipeline, only compiler-generated Yul utility functions and specific inline assembly blocks that do not reference any surrounding Solidity variables or functions are subject to potential anomalies.
To gauge the real-world prevalence of the defect, the development team performed an extensive automated scan of the Sourcify database. By rebuilding a vast corpus of verified smart contracts using a development build of the compiler—compiling them once with the vulnerable code path and once with the applied fix—researchers analyzed roughly 283,000 verified compilations utilizing the --via-ir pipeline alongside another 607,000 compilations processed via the legacy evmasm pipeline. Remarkably, none of these builds produced differing bytecode. While this empirical test instills strong confidence that the practical occurrence of the bug in the wild is extremely rare, the team emphasizes that it does not provide an absolute guarantee for every conceivable contract structure.
Which Contracts Are Affected?
Pinpointing vulnerable smart contracts solely by inspecting high-level Solidity or Yul source code presents a significant challenge. This difficulty arises because the intermediate Yul code that ultimately feeds into the compromised optimizer steps is dynamic. It relies heavily on a combination of the specific compiler version used, the exact optimizer sequence configured, and the surrounding structural context of the codebase.
All known reproducible test cases utilizing the default optimizer sequence follow a distinct structural pattern. Typically, a local variable utilized for calculating memory or storage addresses undergoes modification within a loop or conditional branch, both prior to and following the initial derivation of an address from it. Subsequently, a different value is committed to the exact same physical location through an address derived from this updated variable state. Notably, the target Ethereum Virtual Machine (EVM) version—whether targeting older network upgrades or modern execution environments—does not influence whether the bug manifests during code generation.
Technical Details: Tracking Memory and Storage Contents
To fully grasp the mechanics of the bug, one must examine the internal architecture of the Yul optimizer. The optimizer relies on specialized components designed to track and optimize read and write operations across memory and storage. Among these, the LoadResolver component is responsible for replacing memory loads (mload), storage loads (sload), and cryptographic hashes (keccak256) with pre-calculated values that the compiler already knows. This allows the optimizer to reuse data written by earlier store operations rather than executing redundant retrieval instructions. Working in tandem, the EqualStoreEliminator removes subsequent store instructions if it determines that the target location already holds the exact target value. Both systems rely on a shared bookkeeping mechanism that maintains an ongoing record of the known contents of memory and storage.
When the optimizer encounters a store operation where it cannot definitively determine the precise target address, it must act conservatively by erasing its internal knowledge of every location that the write might potentially overwrite. To determine which specific locations fall into this danger zone, the optimizer queries the KnowledgeBase, an internal subsystem dedicated to resolving mathematical and logical relations between variables.
Within the KnowledgeBase, variables are represented symbolically as a constant offset calculated from a designated base variable. If a variable’s value evaluates to a static constant, the base variable is treated as zero. If the value cannot be simplified into a constant offset, the variable is treated as its own independent base with an offset of zero. For example, following a sequence 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.
The optimizer determines that two addresses sharing the same base are distinct if their calculated offsets differ by a sufficient margin—specifically, differing for storage or remaining at least 32 bytes apart for memory operations. When this distinction is established, writing to one location does not invalidate the compiler’s cached knowledge regarding the other location.
Stale Cache Entries and the Root Cause
To optimize performance, these symbolic representations and address relations were cached on a per-variable basis. This caching mechanism was originally introduced in Solidity version 0.8.19. Prior to this enhancement, the KnowledgeBase computed offsets dynamically on the fly from the current values of the variables during every analytical pass.
While treating an unknown value conservatively is always safe because it merely restricts aggressive optimizations, relying on an outdated cached value can lead to severely compromised and incorrect machine code. A cached entry becomes stale and obsolete whenever the underlying value of its associated variable changes during program execution. To manage this, the cache was previously maintained using a lazy invalidation strategy. Whenever the KnowledgeBase performed a variable lookup, it compared the variable’s current value expression against the expression it had recorded during the previous inspection. If a discrepancy was detected, the system would reset the corresponding cached entry.
However, this lazy evaluation check could fail to detect a variable reassignment under specific conditions. When such a check failed, two distinct memory or storage addresses could be erroneously represented as offsets derived from the same base variable. In reality, one address had been derived from the base variable’s value prior to its reassignment, while the other was derived from its value after the reassignment.
Because the optimizer mistakenly treated both offsets as relative to one and the same unchanging value, it concluded incorrectly that the two memory or storage locations were completely distinct. Consequently, it preserved its assumptions about one location across a store operation directed at the other. If those two locations happened to coincide during runtime execution, subsequent load operations from the first location would be incorrectly replaced with outdated, cached values. Similarly, necessary store instructions could be prematurely purged, or cryptographic operations like keccak256 hashes over those locations could be computed using stale, incorrect data.
Practical Example Demonstrating the Flaw
The vulnerability can be observed in standard Solidity code compiled with the via-IR pipeline and optimizer enabled, as illustrated by the following contract structure:
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 is a static array whose data storage begins at slot zero. Because structure S contains a single value-type member, every array element occupies exactly one storage slot, aligning each element’s storage slot directly with its numerical index.
When invoking the function with parameters g(0, 2, 0xaaaa, 0xbbbb), the initial loop does not execute, leaving k evaluated as 2, which causes the value 0xaaaa to be written to a[2].v. Subsequently, the second loop executes twice, incrementing i to 2, which results in the value 0xbbbb being written to the exact same storage location. Consequently, standard execution dictates that the function should return 0xbbbb.
However, under the influence of the bug, the generated Yul code derives the storage slot for a[k].v from the state of variable i prior to the second loop, while the slot for a[i].v is derived from i after the second loop. Because the optimizer tracks no specific value for i at these precise checkpoints, it treats i as its own base variable, representing the two slots symbolically as i + 2 and i.
The KnowledgeBase fails to record that these expressions refer to the state of i at fundamentally different points in program execution. As a result, it wrongly concludes that the two write operations must target storage slots separated by a fixed offset and that the store to a[i].v cannot possibly overwrite the contents of a[k].v. The final load instruction retrieving a[k].v is consequently optimized away and replaced with the input parameter aaaa, causing the function to erroneously return 0xaaaa instead of 0xbbbb.
Severity Assessment and Mitigation
When this optimization bug is successfully triggered, the Solidity compiler emits no warning or error message, and the resulting smart contract bytecode does not automatically revert at runtime. Instead, state variables may silently receive outdated values, or critical write operations to storage and memory may be completely omitted from execution.
Despite the theoretical severity of incorrect state modifications, the practical likelihood of encountering this issue in deployed contracts remains very low due to the fragile alignment conditions required within the intermediate Yul representation, coupled with the requirement that the affected addresses must physically collide during runtime execution. Nevertheless, in scenarios where address offsets are derived directly from external call arguments, sophisticated callers might theoretically craft specific inputs to force such collisions.
To permanently eradicate this vulnerability, the Solidity core development team implemented a robust structural fix. The updated compiler architecture abandons the legacy lazy cache invalidation strategy in favor of explicit variable versioning. Every individual variable tracked within the KnowledgeBase now maintains an explicit version identifier that is automatically incremented whenever the optimizer 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 a distinct new entity, ensuring that legacy cache entries can never become stale or cause cross-contamination across execution paths.
Developers utilizing any version of Solidity from 0.8.19 through 0.8.37 are strongly advised to upgrade their compiler toolchain immediately to version 0.8.38 or later to ensure complete protection against potential optimizer anomalies.






