Home / Smart Contract Auditing / Solidity Team Discovers and Patches Medium-Severity Compiler Bug Affecting Inheritance and Storage Layouts

Solidity Team Discovers and Patches Medium-Severity Compiler Bug Affecting Inheritance and Storage Layouts

On June 8, 2026, developer clonker from the core Solidity team identified a critical vulnerability residing within the analysis phase of the Solidity compiler. The bug, which has been assigned a medium severity rating on the team’s internal scale, is triggered when the compiler issues Warning 3495—a diagnostic alert designed to notify developers when a custom storage layout is positioned perilously close to the absolute maximum limit of the Ethereum Virtual Machine’s storage space.

The underlying mechanism responsible for emitting this warning was found to unintentionally mutate the internal C3-linearized list of base contracts associated with the contract being checked. Because this linearization serves as the foundational roadmap driving inheritance-dependent decisions throughout subsequent phases of the compiler, the accidental mutation can trigger cascading issues, ranging from silent miscompilations to severe internal compiler errors.

The discovery highlights the intricate challenges of modern compiler design, particularly when balancing language safety features, optimization passes, and complex object-oriented inheritance hierarchies in smart contract development.

Which Contracts Are Affected?

To understand the scope of potential exposure, the Solidity team performed a rigorous technical analysis of the conditions required for the bug to manifest. A smart contract is only vulnerable if it satisfies a specific combination of criteria during the compilation process. First, the contract must utilize a custom storage layout via the layout-at clause, and that layout must be positioned within the final range of storage slots. Second, the contract must involve an inheritance hierarchy, as single, standalone contracts without base contracts do not rely on C3 linearization lists.

Despite the theoretical implications of inheritance corruption, empirical data suggests that real-world exposure is virtually non-existent. A comprehensive GitHub search looking for Foundry configuration files suppressing Warning 3495 returned zero results, indicating that developers do not intentionally place persistent storage variables at extraordinarily high memory addresses. This finding was further reinforced by a broad scan conducted across Sourcify, a leading smart contract verification repository, which yielded no affected contracts in the wild.

Custom storage layouts placed near the extreme end of the storage spectrum remain exceptionally rare. Because the Solidity compiler actively warns developers against adopting this architectural pattern, the specific

combination of traits required to trigger the bug is widely considered an unusual edge case in professional development environments. Developers whose smart contracts do not rely on custom storage layouts or complex inheritance patterns can rest assured that their code remains entirely unaffected.

Technical Details and Root Cause Analysis

A deeper examination into the compiler’s codebase reveals the implementation-level root cause behind the error. The storage-end warning feature was originally introduced to the language in Solidity version 0.8.29. The auxiliary helper function responsible for scanning storage positions has remained unchanged since that release, meaning that every compiler version from 0.8.29 through 0.8.35 is susceptible to the flaw. Because the vulnerability resides strictly within the language frontend’s analysis phase, it operates independently of the chosen compilation pipeline. Both the IR generation pipeline and the legacy evmasm pipeline are equally affected. Pure Yul code and transient storage implementations remain untouched, as custom storage layouts are restricted exclusively to persistent storage.

The technical genesis of the bug lies in how the compiler handles AST (Abstract Syntax Tree) annotations. The linearizedBaseContracts annotation encodes the C3 linearization of a contract’s inheritance tree, a sequence that must remain immutable to guarantee predictable behavior across compilation phases. The function tasked with issuing Warning 3495 attempts to walk this list in reverse order to identify which specific state variable sits closest to the storage boundary.

Instead of generating a safe, isolated copy of the list for analysis, the function inadvertently invoked the actions::reverse helper function from the external ranges-v3 library. Unlike views::reverse, which merely projects a reversed iterator over a container without altering the underlying data, the actions::reverse variant performs an in-place mutation of the underlying container. Because both utilities share identical signatures, the C3-linearized list stored within the AST annotation was permanently reversed in memory.

Compounding the issue is an architectural aspect of Solidity’s internal annotation system: annotations are traditionally designed to be mutable, violating strict standards of const-correctness. Consequently, the C++ compiler failed to flag the invocation of actions::reverse as an illegal operation, allowing the bug to slip past code reviews undetected until clonker’s recent audit.

Effect on the Rest of the Compiler

When the linearizedBaseContracts annotation is corrupted by inversion, any subsequent compiler resolution relying on inheritance order is bound to fail. The C3 linearization dictates how state variables are initialized, how constructors are invoked in multi-contract setups, and how virtual functions, modifiers, fallbacks, and receive functions resolve their targets.

With the list reversed, the compiler executes these critical operations in the exact opposite order intended by the developer. Furthermore, the reversed order is propagated directly into AST JSON exports, complicating external tooling analysis. While some of these failures manifest as silent miscompilations where variables receive unexpected default values during deployment, others immediately trigger internal compiler errors or produce invalid intermediate representation (IR) code that halts the build process entirely.

Practical Example and Manifestation

To demonstrate how the bug alters deployment behavior, the Solidity team provided a minimal reproduction contract. Consider a scenario featuring three contracts where contract A defines a public uint variable x initialized to 1 within its constructor, contract B inherits from A and multiplies x by 10, and contract C inherits from B while introducing a custom layout clause near the upper boundary of storage:

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;  

Under normal execution, the inheritance chain flows left to right as A, then B, and finally C, meaning constructor execution order should evaluate the math such that deploying C results in x equaling 15. However, when the layout-at clause triggers Warning 3495, the inheritance-order reversal bug activates. The compiler processes the inheritance list backward, running constructors out of sequence. Consequently, deploying contract C yields an unexpected value of x equal to 5. Removing the layout clause—and thereby avoiding the warning—causes the exact same code to compile correctly and yield 15.

Severity Assessment and Remediation

While the theoretical impact of a reversed inheritance hierarchy is severe, the practical risk is mitigated by several factors. The bug only activates under conditions that the compiler explicitly discourages: utilizing a custom storage layout that overlaps with the final $2^64$ slots of the addressable storage space. Empirical scans confirm that this layout strategy is virtually nonexistent among verified smart contracts.

Furthermore, in complex production environments featuring super-calls, constructor arguments, and intricate state dependencies, a reversed inheritance order rarely results in a silent miscompilation. Instead, it frequently triggers an internal compiler error or generates invalid IR, providing immediate feedback during the compilation phase rather than allowing flawed bytecode to reach production networks.

The core development team has addressed the issue in Solidity version 0.8.36. The fix replaces the mutating ranges::actions::reverse utility with the non-mutating ranges::views::reverse helper, ensuring that diagnostic warnings can inspect data structures safely without altering the underlying AST annotations. Developers currently utilizing any version from 0.8.29 through 0.8.35 are strongly encouraged to upgrade their compiler toolchains to version 0.8.36 to eliminate any potential exposure.

Tagged: