{"id":1422,"date":"2026-10-12T14:15:20","date_gmt":"2026-10-12T14:15:20","guid":{"rendered":"https:\/\/smartcryptosecurity.com\/?p=1422"},"modified":"2026-10-12T14:15:20","modified_gmt":"2026-10-12T14:15:20","slug":"critical-memory-corruption-bug-discovered-in-solidity-code-generator-affecting-versions-up-to-0-8-37-5","status":"publish","type":"post","link":"https:\/\/smartcryptosecurity.com\/?p=1422","title":{"rendered":"Critical Memory Corruption Bug Discovered in Solidity Code Generator Affecting Versions up to 0.8.37"},"content":{"rendered":"<p>A significant vulnerability has been uncovered within the Solidity code generator, affecting all versions of the prominent Ethereum smart contract programming language up to and including version 0.8.36. The flaw, which deals with memory management and byte array operations, causes unintended data corruption by improperly clearing 32 full bytes of memory instead of a single target byte when utilizing the <code>delete<\/code> operator on specific elements of in-memory <code>bytes<\/code> arrays. <\/p>\n<p>Discovered on August 14, 2026, by researcher Shaheen Fazim through the Ethereum Foundation\u2019s bug bounty program, the defect resides within the older, default <code>evmasm<\/code> compilation pipeline. While the vulnerability carries profound implications for smart contract integrity under specific conditions, developers have been reassured that a fix is already live in Solidity 0.8.37, and a comprehensive database scan indicates that no deployed production contracts are known to be actively compromised.<\/p>\n<h2>Understanding the Vulnerability<\/h2>\n<p>To comprehend the nature of the bug, one must examine how Solidity handles data structures in memory. Unlike most values in Ethereum Virtual Machine (EVM) memory that cleanly occupy full 32-byte words, packed byte arrays\u2014namely <code>bytes<\/code> and <code>string<\/code> types\u2014are structured differently. They consist of a 32-byte length descriptor followed immediately by raw data packed back-to-back without internal gaps. <\/p>\n<p>Normally, when a developer wishes to clear a specific element within a byte array, they can either assign a zero value via <code>b[i] = 0<\/code> or apply the native <code>delete<\/code> keyword via <code>delete b[i]<\/code>. While both programming constructs are logically intended to perform the exact same operation, they take fundamentally different paths in the compiler&#8217;s <code>evmasm<\/code> code generator. <\/p>\n<p>The standard assignment path correctly utilizes a single-byte store operation (<code>mstore8<\/code>), ensuring that only the designated byte index is overwritten with zeros. However, the legacy <code>delete<\/code> code path inadvertently invokes a full 32-byte memory write. Because this write operation initiates at the target element&#8217;s exact memory offset rather than aligning with a standard 32-byte word boundary, it stretches far beyond the intended index. Consequently, it wipes out up to 31 subsequent bytes either further down within the same array or spilled over into whatever memory space happens to be allocated immediately afterward.<\/p>\n<p>Crucially, the array&#8217;s internal length field remains untouched by this stray write. Because the length parameter does not change, subsequent operations\u2014such as computing cryptographic hashes via <code>keccak256<\/code>, performing ABI encoding routines, or returning data to external callers\u2014will unwittingly process the silently corrupted data. <\/p>\n<h2>Scope and Affected Pipeline Characteristics<\/h2>\n<p>The Solidity development team has assigned this vulnerability a severity rating of low-to-medium on their internal scale. Several precise conditions must align for a smart contract to be vulnerable. First, the contract must be compiled using the default <code>evmasm<\/code> pipeline. The modern IR (Intermediate Representation) pipeline is completely unaffected by the defect, as it handles the <code>delete<\/code> instruction through the correct single-byte storage route. Additionally, the use of the Solidity optimizer does not trigger, mitigate, or alter the bug; the fault lies fundamentally in the raw code emission stage.<\/p>\n<p>Furthermore, the vulnerability is strictly confined to memory allocations. Byte arrays stored in persistent blockchain storage utilize an entirely separate, unaffected code path, and the <code>delete<\/code> operator cannot be applied to <code>calldata<\/code> arrays at all. Arrays whose elements occupy full, uncompressed words\u2014such as <code>bytes1[] memory<\/code>\u2014remain completely safe because they do not utilize packed data storage. <\/p>\n<p>Only dynamic <code>bytes<\/code> arrays and UTF-8 <code>string<\/code> memory values (when explicitly cast to <code>bytes<\/code> via <code>bytes(s)[i]<\/code>) are susceptible. Standard fixed-size byte arrays like <code>bytes32<\/code> are similarly immune because index access on those types returns an isolated copy of the byte rather than a mutable reference to the underlying memory location.<\/p>\n<figure class=\"article-inline-figure\"><img decoding=\"async\" src=\"https:\/\/soliditylang.org\/assets\/logo-og-image.png\" alt=\"Memory Byte Array Element Delete Clears Whole Word Bug | Solidity Programming Language\" class=\"article-inline-img\" loading=\"lazy\" \/><\/figure>\n<h2>Technical Mechanics of Memory Overwriting<\/h2>\n<p>The extent of the damage caused by the <code>delete<\/code> instruction depends heavily on the array&#8217;s structural layout and its placement within memory. Solidity manages memory by continuously advancing a free memory pointer, meaning consecutive variable declarations sit flush against one another. <\/p>\n<p>When dealing with padded arrays\u2014such as those created via <code>new bytes(n)<\/code> or literal definitions\u2014the compiler appends up to 31 zero bytes of padding at the end of the array to ensure subsequent memory allocations cleanly start on a fresh 32-byte word boundary. When a developer applies <code>delete<\/code> to an element near the beginning or middle of a padded array, the 32-byte zero write swallows up to 31 subsequent elements internally. If the delete operation targets one of the final elements near the end of the array, the overflow write can breach the array boundary entirely and spill over into whatever variable was allocated directly after it.<\/p>\n<p>The situation is even more pronounced with unpadded arrays. Pipelines generated by operations like <code>bytes.concat<\/code>, <code>string.concat<\/code>, and the various <code>abi.encode<\/code> functions do not include trailing padding. Consequently, for unpadded arrays, deleting any of the final 31 elements will invariably corrupt the subsequent memory allocation, regardless of the array&#8217;s overall length. For small unpadded arrays comprising 31 bytes or fewer, this includes every single index, right down to the very first element.<\/p>\n<h2>Empirical Impact and Assessment<\/h2>\n<p>To measure the real-world exposure of this long-standing defect\u2014which predates the very first official release of Solidity\u2014developers conducted an extensive security scan. Researchers analyzed the Sourcify database, encompassing approximately 870,000 verified smart contract compilations, searching specifically for the problematic source code pattern.<\/p>\n<p>The scan revealed that the vulnerable pattern appeared in a mere 17 total compilations, accounting for only two distinct functions across the entire dataset. Further analysis of those specific functions confirmed that neither was actually vulnerable in practice. In both instances, the bytes cleared within the array were either immediately discarded or written over anyway, while the overflow memory corruption landed either in safely bounded array lengths or in entirely unallocated memory spaces.<\/p>\n<p>Despite these reassuring findings, diagnosing the bug in custom codebases can be challenging. The compiler emits no warnings during compilation, and affected contracts do not trigger EVM reverts at runtime. Instead, the defect manifests silently as incorrect mathematical computations, corrupted string data, or altered state logic, making thorough unit testing and compiler version auditing vital for development teams.<\/p>\n<h2>Remediation and Recommended Actions<\/h2>\n<p>The discovery prompted the immediate release of Solidity version 0.8.37. The core patch rectifies the underlying discrepancy in the compiler backend by forcing the <code>delete<\/code> instruction path to consult the element&#8217;s actual width. By routing <code>delete b[i]<\/code> through the same single-byte store mechanism (<code>mstore8<\/code>) already utilized by standard array assignments, the fix ensures absolute behavioral consistency between both pipelines.<\/p>\n<p>Smart contract developers utilizing legacy versions up to 0.8.36 are strongly encouraged to upgrade their compiler toolchains to version 0.8.37 or later. Projects relying on the default <code>evmasm<\/code> compilation pipeline should audit their codebase for any instances where the <code>delete<\/code> operator is applied to indexed elements of in-memory <code>bytes<\/code> or <code>string<\/code> arrays, substituting them with explicit zero-assignments or migrating compilation workflows to the IR pipeline where appropriate. <\/p>\n<p>The Ethereum Foundation and the Solidity core team expressed their gratitude to security researcher Shaheen Fazim for responsibly disclosing the vulnerability through the official bug bounty program and providing a clear, reproducible test case.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A significant vulnerability has been uncovered within the Solidity code generator, affecting all versions of&#8230;<\/p>\n","protected":false},"author":23,"featured_media":1421,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[869,401,406,961,201,962,407,960,5,400,402,964],"class_list":["post-1422","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-contract-auditing","tag-affecting","tag-auditing","tag-code","tag-corruption","tag-critical","tag-discovered","tag-generator","tag-memory","tag-security","tag-smart-contracts","tag-solidity","tag-versions"],"_links":{"self":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/1422","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\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1422"}],"version-history":[{"count":0,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/1422\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=\/wp\/v2\/media\/1421"}],"wp:attachment":[{"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartcryptosecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}