Home / Smart Contract Auditing / Solidity Developers Urged to Update as Optimizer Bug Discovered Affecting Versions 0.8.19 Through 0.8.37

Solidity Developers Urged to Update as Optimizer Bug Discovered Affecting Versions 0.8.19 Through 0.8.37

The Ethereum Foundation has released a critical security advisory for the Solidity programming language, detailing a bug discovered within the Yul optimizer that could, under specific and narrow conditions, cause smart contracts to process incorrect data. The vulnerability impacts all compiler versions ranging from Solidity 0.8.19 up to and including version 0.8.37. Developers utilizing the affected versions have been strongly advised to upgrade their toolchains to Solidity 0.8.38, where a permanent patch has been implemented.

The issue was initially brought to light through the Ethereum Foundation’s bug bounty program on August 17, 2026, when developer Daniel Boye submitted a detailed report identifying a flaw in the Yul optimizer. According to Boye’s findings, the underlying bug causes the optimizer to incorrectly classify two separate memory or storage locations as distinct entities even when they coincide and overlap at runtime. Consequently, this faulty optimization can lead the compiler to replace a necessary memory load operation with an outdated value, or improperly eliminate a storage write operation that the contract relies upon to maintain state consistency.

A subsequent independent report submitted on September 28, 2026, by Surya Prakash Akula provided vital additional context to the vulnerability. Akula’s findings demonstrated that the bug is not strictly restricted to low-level inline assembly blocks; rather, it can be triggered directly from plain, high-level Solidity code under the right compiler settings. Following these discoveries, the Solidity development team evaluated the issue and assigned it a severity rating of low on their internal scale, owing to the highly fragile combination of circumstances required to successfully trigger the bug in production environments.

The vulnerability is strictly tied to the activation of the Yul optimizer. Code compiled with the optimizer disabled remains entirely unaffected by the flaw. However, when the --via-ir compilation pipeline is active—corresponding to settings.viaIR in Standard JSON configurations—any smart contract code may be vulnerable, regardless of whether it incorporates inline assembly. The same risk profile applies to Yul code compiled directly using the --strict-assembly flag or the "language": "Yul" setting in Standard JSON. Conversely, when utilizing the default legacy evmasm pipeline, the vulnerability is heavily constrained, potentially affecting only compiler-generated Yul utility functions and isolated inline assembly blocks that do not reference any external Solidity variables or functions.

To measure the real-world prevalence of the bug, the Solidity team conducted an extensive automated scan of the Sourcify verified contract database. Researchers rebuilt hundreds of thousands of verified contracts using a development build of the compiler, executing compilation runs both with and without the security fix applied. The analysis covered approximately 283,000 verified compilations utilizing the modern --via-ir pipeline and roughly 607,000 compilations utilizing the legacy evmasm pipeline. Interestingly, none of the scanned compilations produced differing bytecode between the patched and unpatched compiler states. While this empirical evidence suggests that the practical occurrence of the bug in deployed ecosystem contracts is exceedingly rare, developers have been cautioned that a lack of bytecode divergence in historical scans does not mathematically guarantee that every individual contract is safe.

Which Contracts Are Affected?

A smart contract is only considered vulnerable if a specific set of rigorous technical conditions are met simultaneously during the compilation process. Because conditions governing the intermediate Yul code depend heavily on the exact compiler version, the sequence of optimization steps, and the surrounding source architecture, they cannot be reliably diagnosed by simply inspecting raw Solidity or Yul source code. All known reproducing examples utilizing the default optimizer sequence follow a distinct structural pattern: a local variable used for address calculation is modified inside a loop or conditional branch both before and after an initial memory address is derived from it, followed by a secondary write operation to the exact same location using an address derived from the updated value. The target Ethereum Virtual Machine (EVM) version does not influence whether the vulnerability manifests.

Technical Details

To understand the root cause of the bug, it is necessary to examine the internal mechanisms of the Yul optimizer. The components known as LoadResolver and EqualStoreEliminator are responsible for optimizing memory and storage interactions. LoadResolver attempts to streamline execution by replacing mload, sload, and keccak256 instructions with known values from prior operations, while EqualStoreEliminator strips away redundant store instructions if the target location already holds the target value. Both components depend on a centralized bookkeeping system to track the known contents of memory and storage.

When the optimizer encounters a store instruction where the exact target location cannot be definitively resolved, it must conservatively invalidate its internal assumptions about every memory location that the store might potentially overwrite. To determine which locations are impacted, the compiler consults the KnowledgeBase, an internal subsystem designed to reason about mathematical relations and offsets between variables. The KnowledgeBase represents variables symbolically as constant offsets originating from a base variable. If a variable’s value is an absolute constant, its base is treated as zero; if it cannot be expressed as a simple constant offset, the variable serves as its own base with an offset of zero. For instance, after executing variable assignments such as let base := calldataload(0) and let ptr := add(base, 2), the variable base acts as its own base, whereas ptr is symbolically represented as base + 2.

Historically, two addresses sharing the same base variable were recognized as distinct if their respective offsets differed by any margin in storage, or by at least 32 bytes in memory. Under these assumptions, the optimizer would preserve its knowledge of one location even when a write operation was performed on the other. To optimize performance, these symbolic representations were cached on a per-variable basis—a caching mechanism introduced in Solidity 0.8.19. Prior to this version, the KnowledgeBase calculated offsets dynamically on the fly from current variable values during every evaluation pass.

Stale Cache Entries

While treating an unknown value conservatively is safe because it merely restricts aggressive optimization, relying on stale or outdated cached data can lead to incorrect instruction generation. A cached entry becomes invalid whenever the underlying value of its associated variable changes. In the vulnerable compiler versions, cache invalidation was handled lazily. When the KnowledgeBase performed a variable lookup, it compared the variable’s current value expression against the expression recorded during the previous lookup. If a discrepancy was detected, the cache entry was reset. However, this lazy check could fail to catch reassignments under specific control-flow conditions.

When a reassignment went undetected, two distinct addresses could end up being represented as offsets from the same base variable, even though one address was derived from the base’s pre-reassignment value and the other from its post-reassignment value. The optimizer incorrectly treated both offsets as relative to a single, static value, leading it to conclude that the two storage or memory locations were mutually distinct. As a result, the optimizer maintained its cached state for the first location across a write operation targeting the second location. If those two locations happened to coincide at runtime, subsequent load operations from the first location were erroneously replaced with outdated cached values, or necessary write operations were stripped away entirely.

Example

A concrete example of this behavior can be observed in a simple Solidity contract utilizing a static array structure. Consider a contract containing a storage array where each element occupies a single storage slot corresponding to its array index. When compiled with the --via-ir pipeline and the optimizer enabled, certain iterative patterns involving loop counters can cause the compiler to lose track of variable states across execution blocks. In test cases involving specific parameter inputs, a value intended to overwrite an existing array slot is mismanaged by the optimizer, causing a final load operation to return an outdated parameter value rather than the newly written state.

Severity Assessment

When this compiler bug is successfully triggered, the resulting binary execution does not typically trigger a runtime revert or throw an explicit compiler warning. Instead, the smart contract executes silently with corrupted internal logic, returning stale data from memory or failing to persist necessary state updates to storage. In everyday development, the probability of encountering this bug is exceptionally low due to the fragile alignment of intermediate Yul conditions required to manifest the flaw. Nonetheless, if critical address calculations depend on user-supplied call arguments, a malicious or accidental caller could potentially craft inputs designed to force memory and storage locations to coincide.

The Fix

The core engineering fix implemented in Solidity 0.8.38 replaces the fragile, lazy cache invalidation scheme with an explicit versioning architecture. Every variable tracked within the KnowledgeBase is now assigned an explicit version number that increments automatically whenever the optimizer records a modification to the variable’s underlying value. Cached symbolic representations are now stored uniquely per variable and version combination. Consequently, whenever a variable undergoes reassignment, it is treated as an entirely new entity, preventing existing cache entries from ever becoming stale.

Recommended Actions and Acknowledgements

Developers currently utilizing any version of Solidity between 0.8.19 and 0.8.37 are strongly encouraged to upgrade their compiler toolchain to version 0.8.38 or later immediately. Projects utilizing the Yul optimizer or compiling via the IR pipeline should run full test suites following the upgrade to verify contract correctness.

The Ethereum Foundation expressed its gratitude to the security researchers who responsibly disclosed the vulnerabilities. Special recognition was given to Daniel Boye for his initial bug report submitted through the official bug bounty program, and to Surya Prakash Akula for providing the subsequent research demonstrating that the bug could be triggered from standard, high-level Solidity code without the use of inline assembly.

Tagged: