Bug Discovered: Inheritance-Order Reversal Affects Versions 0.8.29 Through 0.8.35
On June 8, 2026, developer clonker from the core Solidity team discovered a critical bug within the analysis phase of the Solidity compiler. The flaw manifests specifically when the compiler emits Warning 3495, which alerts developers if a custom storage layout is positioned perilously close to the end of the available storage space. While the warning mechanism is designed to safeguard contract upgradability, its internal implementation inadvertently compromised the integrity of the contract’s base structure by reversing its C3-linearized inheritance list. Because this linearization underpins critical inheritance-dependent decisions throughout the compiler’s execution pipeline, the unintended reversal can trigger severe miscompilations and internal compiler errors.
The Solidity team has assigned this vulnerability a severity rating of medium on its internal scale. Because the bug resides deep within the language frontend’s analysis phase, it remains entirely independent of the chosen compilation pipeline, affecting both the intermediate representation (IR) and legacy evmasm code-generation pipelines. Pure Yul code and transient storage implementations remain completely unaffected, as custom storage layouts are strictly implemented for persistent storage variables.
The vulnerability was inadvertently introduced in Solidity version 0.8.29—the exact release that introduced the storage-end warning feature. Consequently, all subsequent versions spanning from 0.8.29 through 0.8.35 are impacted. The Solidity team acted swiftly to address the issue, resolving the bug in the newly released Solidity version 0.8.36.
To gauge the real-world exposure of this flaw, security analysts conducted automated searches across GitHub repositories for Foundry configuration files suppressing Warning 3495, which yielded no results. This absence strongly indicates that intentionally placing storage variables at exceptionally high memory addresses is virtually non-existent in normal development practices. Furthermore, a comprehensive scan of deployed and verified smart contracts via Sourcify for affected contract patterns returned no positive matches, confirming that the practical impact on live decentralized applications is extremely low.
Which Contracts Are Affected?
A smart contract is vulnerable to this bug only if a specific set of rare conditions occurs simultaneously. Specifically, the contract must utilize both an inheritance hierarchy and a custom storage layout, and that layout must be pushed so close to the upper limit of the storage space that it triggers Warning 3495.
Custom layouts placed near the absolute end of storage are exceedingly rare, and because the compiler actively warns developers against doing so, this precise architectural pattern is highly unusual in everyday Solidity development. As a primary rule of thumb for auditing codebases, if a smart contract does not make use of custom storage layouts or multiple inheritance, it is completely immune to this issue.
Technical Details
For developers and systems engineers interested in the implementation-level root cause behind the vulnerability, understanding the interaction between compiler warnings, AST annotations, and C3 linearization is essential. The storage-end warning was originally deployed in version 0.8.29 to help developers avoid limiting the future upgradability of their contracts. When a contract utilizes a layout clause to place its storage variables at a custom base slot, the compiler calculates whether the static portion of that layout leaves enough room for future expansion.
Solidity manages storage across a massive space consisting of $2^256$ individual slots. The compiler emits Warning 3495 whenever the number of free slots remaining after a custom layout drops to $2^64$ or fewer. Given that hash-based layout expressions such as those generated by ERC-7201 pattern libraries derive their storage locations from cryptographic hashing, the statistical probability of a layout naturally landing within this tiny upper window is virtually non-existent, comparable to a mapping element randomly targeting one specific slot out of the entire universe of available storage.
The core of the bug, however, lies in how the compiler handled the list of base contracts during the generation of this warning. The Solidity AST (Abstract Syntax Tree) relies on an annotation system to store the C3-linearized inheritance order of every contract, known as linearizedBaseContracts. The internal helper function responsible for scanning the contract to evaluate the variable closest to the storage end needed to traverse this list in reverse order.
Instead of generating a safe, read-only copy or utilizing a non-destructive view, the implementation unwittingly performed an in-place reversal of the underlying container. This permanent mutation altered the linearization data structures seen by the rest of the compiler for that compilation unit.
The implementation error stemmed from the accidental use of the actions::reverse helper from the external ranges-v3 library, rather than the intended views::reverse. While views::reverse simply produces a reversed iterator view over a container without altering it, the actions variant aggressively mutates the underlying container in place. Because both helper functions share nearly identical signatures, the C3-linearization container was mutated silently. This oversight was further enabled by the design of the compiler’s annotation system, where annotations are mutable by default to optimize performance, thereby bypassing strict const-correctness checks that would have otherwise caused the C++ compiler to flag the invalid action.
Because this helper function is invoked exclusively when Warning 3495 is triggered, the data corruption only occurs in contracts that provoke the warning. Nevertheless, once the linearizedBaseContracts annotation is inverted, any downstream compiler pass that relies on correct inheritance order will produce incorrect results. Confirmed cascading effects include reversed state-variable initialization order, incorrect constructor execution sequencing, broken resolution of super and virtual functions, malformed virtual modifier chains, and broken virtual resolution for fallback and receive functions. In some cases, this corruption also surfaces directly within AST JSON exports, sometimes manifesting as silent miscompilations and other times triggering internal compiler errors or invalid intermediate representations.
Example
To illustrate how this bug changes runtime behavior, the Solidity team provided a minimal reproducer contract that satisfies all the necessary trigger conditions:
contract A
uint public x;
constructor()
x = 1;
contract B is A
constructor()
x = x * 10;
contract C is B layout at 2**256 - 2**40
constructor()
x = x + 5;
In this inheritance hierarchy, the contracts inherit in the order A -> B -> C. Under normal execution, constructors run from left to right, meaning that deploying contract C should initialize x by taking the initial value from A (1), multiplying it by 10 in B (10), and finally adding 5 in C, resulting in a final value of 15. Furthermore, the inclusion of the layout at 2**256 - 2**40 clause pushes the storage layout into the restricted upper $2^64$ slots, successfully triggering Warning 3495 and activating the bug.
Under the influence of the bug, deploying contract C results in x evaluating to 5 instead of 15. This occurs because the corrupted linearization reverses the constructor execution order, causing logic intended for derived contracts to execute out of sequence. Without the storage layout clause—and therefore without the warning being emitted—the exact same contracts compile correctly and yield the expected value of 15.
Severity Assessment
While the hypothetical impact of a corrupted inheritance order is exceptionally high—potentially introducing subtle logical flaws into state initialization and constructor logic—the real-world probability of encountering this vulnerability remains extremely low.
The bug is strictly bounded by the conditions required to trigger Warning 3495. Because placing persistent storage variables within the final $2^64$ slots of the address space offers no practical utility for normal smart contract design, developers do not intentionally write code in this manner. External scans across verified contract repositories further reinforce that no production smart contracts are affected.
Moreover, when this bug does manifest in complex inheritance hierarchies involving super, explicit constructor arguments, or interdependent storage variables, it rarely results in a silent miscompilation. Instead, the broken inheritance sequence frequently triggers internal compiler errors or invalid IR generations during the compilation stage itself, halting the build process and preventing flawed code from ever being compiled or deployed.
The Fix
The fix implemented by the Solidity development team is direct and precise. The compiler source code has been updated to replace the destructive ranges::actions::reverse call with the safe, non-mutating ranges::views::reverse view adaptor. This ensures that helper functions can safely iterate over inheritance lists in reverse order without permanently modifying the core AST annotations.
Recommended Actions
Developers utilizing any Solidity compiler version from 0.8.29 up to and including 0.8.35 are strongly advised to upgrade their toolchains to Solidity 0.8.36 immediately. Teams managing complex codebases should review their compilation outputs and ensure that no custom storage layout expressions inadvertently push storage allocations into the upper limits of the storage space where Warning 3495 is triggered.
Acknowledgements
The Solidity core development team discovered, diagnosed, and resolved this compiler vulnerability entirely through internal code reviews and testing procedures.

