{"id":4602,"date":"2026-11-26T15:15:14","date_gmt":"2026-11-26T15:15:14","guid":{"rendered":"https:\/\/smartcryptosecurity.com\/?p=4602"},"modified":"2026-11-26T15:15:14","modified_gmt":"2026-11-26T15:15:14","slug":"solidity-compiler","status":"publish","type":"post","link":"https:\/\/smartcryptosecurity.com\/?p=4602","title":{"rendered":"Solidity Compiler"},"content":{"rendered":"<p>Bug Discovered: Inheritance-Order Reversal Affects Versions 0.8.29 Through 0.8.35<\/p>\n<p>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&#8217;s base structure by reversing its C3-linearized inheritance list. Because this linearization underpins critical inheritance-dependent decisions throughout the compiler&#8217;s execution pipeline, the unintended reversal can trigger severe miscompilations and internal compiler errors.<\/p>\n<p>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&#8217;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.<\/p>\n<p>The vulnerability was inadvertently introduced in Solidity version 0.8.29\u2014the 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.<\/p>\n<p>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.<\/p>\n<h2>Which Contracts Are Affected?<\/h2>\n<p>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. <\/p>\n<p>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.<\/p>\n<h2>Technical Details<\/h2>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>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 <code>linearizedBaseContracts<\/code>. 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. <\/p>\n<p>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. <\/p>\n<p>The implementation error stemmed from the accidental use of the <code>actions::reverse<\/code> helper from the external <code>ranges-v3<\/code> library, rather than the intended <code>views::reverse<\/code>. While <code>views::reverse<\/code> simply produces a reversed iterator view over a container without altering it, the <code>actions<\/code> 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&#8217;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.<\/p>\n<p>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 <code>linearizedBaseContracts<\/code> 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 <code>super<\/code> and virtual functions, malformed virtual modifier chains, and broken virtual resolution for <code>fallback<\/code> and <code>receive<\/code> 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.<\/p>\n<h2>Example<\/h2>\n<p>To illustrate how this bug changes runtime behavior, the Solidity team provided a minimal reproducer contract that satisfies all the necessary trigger conditions:<\/p>\n<pre><code class=\"language-solidity\">contract A  \n    uint public x; \n    constructor()  \n        x = 1; \n     \n\n\ncontract B is A  \n    constructor()  \n        x = x * 10; \n     \n\n\ncontract C is B layout at 2**256 - 2**40  \n    constructor()  \n        x = x + 5; \n     \n<\/code><\/pre>\n<p>In this inheritance hierarchy, the contracts inherit in the order <code>A -&gt; B -&gt; C<\/code>. Under normal execution, constructors run from left to right, meaning that deploying contract <code>C<\/code> should initialize <code>x<\/code> by taking the initial value from <code>A<\/code> (<code>1<\/code>), multiplying it by <code>10<\/code> in <code>B<\/code> (<code>10<\/code>), and finally adding <code>5<\/code> in <code>C<\/code>, resulting in a final value of <code>15<\/code>. Furthermore, the inclusion of the <code>layout at 2**256 - 2**40<\/code> clause pushes the storage layout into the restricted upper $2^64$ slots, successfully triggering Warning 3495 and activating the bug.<\/p>\n<p>Under the influence of the bug, deploying contract <code>C<\/code> results in <code>x<\/code> evaluating to <code>5<\/code> instead of <code>15<\/code>. 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\u2014and therefore without the warning being emitted\u2014the exact same contracts compile correctly and yield the expected value of <code>15<\/code>.<\/p>\n<h2>Severity Assessment<\/h2>\n<p>While the hypothetical impact of a corrupted inheritance order is exceptionally high\u2014potentially introducing subtle logical flaws into state initialization and constructor logic\u2014the real-world probability of encountering this vulnerability remains extremely low. <\/p>\n<p>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.<\/p>\n<p>Moreover, when this bug does manifest in complex inheritance hierarchies involving <code>super<\/code>, 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.<\/p>\n<h2>The Fix<\/h2>\n<p>The fix implemented by the Solidity development team is direct and precise. The compiler source code has been updated to replace the destructive <code>ranges::actions::reverse<\/code> call with the safe, non-mutating <code>ranges::views::reverse<\/code> view adaptor. This ensures that helper functions can safely iterate over inheritance lists in reverse order without permanently modifying the core AST annotations.<\/p>\n<h2>Recommended Actions<\/h2>\n<p>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.<\/p>\n<h2>Acknowledgements<\/h2>\n<p>The Solidity core development team discovered, diagnosed, and resolved this compiler vulnerability entirely through internal code reviews and testing procedures.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bug Discovered: Inheritance-Order Reversal Affects Versions 0.8.29 Through 0.8.35 On June 8, 2026, developer clonker&#8230;<\/p>\n","protected":false},"author":22,"featured_media":4601,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[401,1230,5,400,402],"class_list":["post-4602","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-auditing","tag-compiler","tag-security","tag-smart-contracts","tag-solidity"],"_links":{"self":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/4602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4602"}],"version-history":[{"count":0,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/4602\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/media\/4601"}],"wp:attachment":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}