Home / Smart Contract Auditing / Solidity Vulnerability Disclosed: Memory Byte Array Element Deletion Bug Affects Versions Up to 0.8.37

Solidity Vulnerability Disclosed: Memory Byte Array Element Deletion Bug Affects Versions Up to 0.8.37

A critical compiler vulnerability affecting the Solidity code generator has been officially disclosed following a discovery by security researcher Shaheen Fazim. Reported on August 14, 2026, via the Ethereum Foundation’s bug bounty program, the flaw resides in how the default evmasm compilation pipeline handles the delete operator when it is applied to specific elements of dynamic bytes or string arrays residing in memory. Under specific conditions, executing a deletion operation on an array element triggers a 32-byte zero-write that overwrites adjacent memory spaces, causing unintended data corruption both within the target array and potentially in neighboring memory allocations.

The vulnerability impacts all historical versions of Solidity up to and including version 0.8.36, with the underlying code path predating the very first official release of the language. Fortunately, the Ethereum Foundation and the Solidity development team moved swiftly to address the issue, issuing a complete patch in Solidity 0.8.37. Security audits and database scans conducted on platforms like Sourcify indicate that while the vulnerability is severe in principle, its real-world impact on deployed smart contracts is remarkably limited, though developers are strongly urged to update their compiler versions and review codebase memory interactions.

Understanding the Core Defect

To fully grasp the nature of the vulnerability, developers must examine how Solidity manages memory allocation compared to storage. Most values within Ethereum Virtual Machine (EVM) memory occupy a full 32-byte word. Dynamic byte arrays (bytes) represent a notable exception, consisting of a 32-byte length header followed immediately by back-to-back packed byte data without internal padding gaps.

When developers wish to clear a specific index within a memory array, they can utilize either an explicit assignment—such as setting b[i] = 0—or the delete keyword, as in delete b[i]. Logically, both instructions are intended to achieve the exact same outcome: zeroing out the targeted byte. However, the evmasm compiler pipeline utilizes distinct code generation paths for these two operations.

While assignment operations correctly invoke a single-byte store instruction (mstore8) when the element width is known, the vulnerable delete code path executes a full 32-byte word write (mstore) starting directly at the memory address of the targeted element. Because the deletion target rarely aligns perfectly with a 32-byte word boundary, the zero-write spills over, clearing up to 31 additional bytes following the designated index.

This unintended spillover causes two distinct categories of data corruption: internal array corruption and external memory corruption. Inside the array itself, up to 31 subsequent elements are wiped out. Beyond the array, the spillover can cross allocation boundaries and overwrite adjacent variables residing in the active memory scope.

Scope, Pipeline Restrictions, and Affected Code Paths

The vulnerability is strictly isolated to the default evmasm compilation pipeline. Contracts compiled using the alternative Intermediate Representation (IR) pipeline are entirely immune to the defect because the IR pipeline correctly routes delete instructions through the appropriate element-width store logic. Furthermore, utilizing the Solidity optimizer neither triggers nor prevents the bug; the faulty instruction semantics are baked directly into the initial code generation phase, and optimization passes preserve the corrupted output.

Several nuanced conditions must align for a smart contract to be vulnerable. First, the bug exclusively affects element-level deletions. Deleting an entire array via delete b executes through a completely separate code path and functions correctly. Second, the target array must reside in memory. Byte arrays stored in persistent blockchain storage (storage) are managed via entirely separate mechanisms and remain unaffected, while calldata arrays do not support the delete operator at all. Additionally, fixed-size byte arrays or arrays whose elements each occupy a full 32-byte word—such as bytes1[] memory—are unaffected, as only packed types like bytes and string cluster their elements adjacently.

Strings are similarly impacted due to their underlying representation. While direct index deletion like delete s[i] is not permitted for string memory types, developers frequently convert strings into byte arrays to manipulate them in memory, writing expressions such as delete bytes(s)[i]. These conversions expose strings to the exact same memory corruption vulnerabilities as native bytes arrays.

Memory Layout and Overflow Dynamics

The extent of the memory corruption depends heavily on the array’s allocation structure and the index chosen for deletion. Memory allocations in Solidity are managed by advancing a free memory pointer, meaning consecutive variable declarations sit flush against one another.

Memory Byte Array Element Delete Clears Whole Word Bug | Solidity Programming Language

Arrays created via literals or expressions like new bytes(n) are typically padded with up to 31 zero bytes at the end so that subsequent memory allocations begin cleanly on a word boundary. Conversely, unpadded arrays—such as those produced by bytes.concat, string.concat, and ABI encoding functions—end precisely where the next allocation begins, leaving zero buffer room.

When a developer deletes an element near the end of a padded array, the trailing padding absorbs part of the 32-byte zero-write. However, if the array lacks sufficient padding—such as arrays whose lengths are exact multiples of 32, or unpadded arrays produced by concatenation functions—the zero-write reaches past the array boundary and directly overwrites whatever data happens to be allocated next in memory.

The consequences of this overflow depend on the data type residing in the adjacent memory slot. For left-aligned types, the most significant bytes are wiped clean. For right-aligned variables such as integer counters, memory pointers, or Ethereum addresses, the impact varies based on the size of the target type and the number of spilled zero bytes. A minor spillover might leave a standard address untouched, whereas a maximum 31-byte write will obliterate all high-order bits, transforming maximum possible integer values into negligible numbers.

Practical Demonstration and Real-World Risk Assessment

To illustrate the mechanics of the bug, consider a contract containing auxiliary memory structures. If a developer allocates a dynamic bytes array, declares a adjacent variable or struct in memory, and subsequently deletes an element near the tail of the array, the resulting state divergence becomes immediately apparent. In testing environments, executing delete b[31] on a 32-byte memory array immediately preceding a maximum-value integer variable causes the integer’s upper bytes to be zeroed out, fundamentally altering runtime logic without triggering any compiler warnings or runtime execution reverts.

Despite the technical severity of the flaw, a comprehensive security analysis suggests that the practical risk to deployed decentralized applications is low. Investigators scanned the Sourcify database, encompassing approximately 870,000 verified smart contract compilations, searching specifically for the source code patterns capable of triggering the vulnerability. The pattern appeared in a mere 17 compilations, resolving to only two distinct deployed functions. Further manual inspection revealed that neither of those functions was actually exploitable in practice, as the corrupted bytes were either immediately discarded or written into unallocated memory spaces.

The Solidity core team assigned a severity rating of low-to-medium to the vulnerability. Because the bug manifests as silent data corruption rather than an explicit transaction revert, it can prove challenging to diagnose during routine debugging. However, comprehensive automated test suites exercising array deletion paths under the evmasm pipeline will readily expose unexpected state changes.

Resolution and Recommended Actions

The vulnerability has been fully resolved in Solidity version 0.8.37. The engineering fix ensures that the code generator’s deletion path correctly queries element widths, forcing the compiler to emit single-byte store instructions (mstore8) rather than sweeping word-level stores when clearing packed byte array elements. Consequently, delete b[i] and b[i] = 0 now exhibit identical, correct behavioral semantics across both compilation pipelines.

Developers maintaining active codebases utilizing Solidity versions 0.8.36 or earlier are strongly advised to audit their code for element-level deletions on memory bytes and string arrays. Projects should immediately upgrade their compiler toolchains to Solidity 0.8.37 or later. Alternatively, teams unable to upgrade immediately can mitigate the risk by refactoring their code to use explicit element assignments (b[i] = 0) instead of the delete operator, or by migrating their compilation targets to the IR pipeline.

The Ethereum Foundation expressed its gratitude to security researcher Shaheen Fazim for identifying the vulnerability through the official bug bounty program and supplying a comprehensive reproduction case, ensuring the issue was safely and efficiently remediated before causing widespread disruption across the Ethereum ecosystem.

Tagged: