25 Nov 2026, Wed

Smart contract developers using the Ethereum ecosystem have been put on alert following the disclosure of a long-standing code generation bug in Solidity, the primary programming language for Ethereum smart contracts. Disclosed on August 14, 2026, the vulnerability affects how the Solidity compiler handles the deletion of individual elements within memory-based byte arrays. Although the flaw has existed within the compiler’s codebase since before Solidity’s very first official release, thorough ecosystem scans suggest that active exploitation in the wild is unlikely.

The bug was brought to light by security researcher Shaheen Fazim, who responsibly reported the flaw through the official Ethereum Foundation bug bounty program and supplied a reliable code reproducer. Following the report, the Solidity development team quickly conducted an internal investigation, assigned the issue a low-to-medium severity rating, and engineered a definitive patch released in version 0.8.37.

At the heart of the issue is a discrepancy in how the Solidity compiler generates bytecode for memory-based data structures. When a developer applies the delete keyword to an individual element of a dynamic bytes or string array residing in memory—such as executing delete b[i]—the generated code mistakenly performs a full 32-byte zero write starting directly at the target element’s memory address. This behavior deviates sharply from the correct semantic intent, which is to clear only a single byte, mirroring the execution of the standard assignment b[i] = 0.

Because a 32-byte write begins at the specific index of the deleted element rather than aligning to a standard 32-byte memory word boundary, it inevitably cascades forward. This erroneous write wipes out up to 31 subsequent bytes. Depending on where the deleted element sits within the array, this unintended data wipe can manifest in one of two ways: internal array corruption or memory corruption bleeding past the boundary of the array entirely into whatever variable or structure happens to be allocated next in EVM memory.

The development team clarified that the vulnerability is strictly confined to the default evmasm compilation pipeline. Contracts compiled using the modern IR (Intermediate Representation) pipeline remain entirely unaffected. Furthermore, invoking the Solidity optimizer is not required to trigger the bug, as the defect resides inherently within the foundational code generation logic. The bug impacts every single version of Solidity up to and including version 0.8.36.

To gauge the real-world impact of the vulnerability, security analysts turned to Sourcify, an open-source smart contract verification repository. Investigators scanned roughly 870,000 verified compilations looking for the precise source code pattern capable of triggering the bug. The search yielded only 17 matching compilations involving just two distinct functions. Upon closer inspection, security experts confirmed that neither of the deployed functions was actually vulnerable in practice. In one instance, the corrupted bytes were subsequently discarded or overwritten anyway, while the other involved an array length that never grew large enough to reach adjacent memory, meaning no active, deployed smart contracts are known to have suffered from the flaw.

Which Contracts Are Affected?

Understanding whether a smart contract is vulnerable requires evaluating specific architectural conditions of the codebase. A contract is only exposed to this particular memory corruption risk if several precise technical factors align during compilation and execution.

First and foremost, the codebase must be compiled using an affected version of Solidity—any release up to version 0.8.36—while utilizing the standard evmasm pipeline. Second, the logic of the contract must actively apply the delete keyword to an element index within a memory-based bytes or string array. If a contract never performs element-level deletions on memory byte arrays or strings, it is completely immune to the issue, regardless of the compiler version used.

Crucially, whole-array deletions—such as calling delete b on an entire array—follow an entirely separate code path within the compiler and execute safely. Similarly, byte arrays stored in permanent contract storage are handled via distinct compilation routines and remain unaffected, while calldata arrays cannot have the delete operator applied to them at all. Furthermore, arrays whose elements each occupy a full 32-byte word in memory, such as bytes1[] memory, are completely unaffected because their elements are not packed tightly. The vulnerability is strictly isolated to data types like bytes and string that pack multiple elements tightly back-to-back without word gaps.

While standard string variables do not natively allow direct index deletion like delete s[i], developers frequently convert strings into byte arrays to manipulate individual characters. Executing delete bytes(s)[i] on a converted string bypasses normal type restrictions and triggers the exact same underlying memory corruption bug.

Technical Details and Memory Layout

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

To understand why the bug occurs at the machine level, it is helpful to examine how Solidity manages memory allocations. Most data types in Ethereum Virtual Machine memory occupy full 32-byte words. Dynamic byte arrays are a notable exception, consisting of an initial 32-byte length header followed immediately by the raw byte data packed tightly back-to-back without internal padding.

Solidity allocates memory sequentially by advancing a free memory pointer, meaning consecutive variable declarations sit flush against one another. To maintain clean word boundaries, the compiler typically appends up to 31 zero bytes of padding to the end of certain allocations. These are referred to as padded arrays. Such padding is automatically applied to arrays created via new bytes(n) or initialized from literal values.

However, certain language constructs produce unpadded arrays where data ends precisely where the next memory allocation begins. These unpadded structures are generated by functions such as bytes.concat, string.concat, and the entire suite of abi.encode functions, including abi.encodePacked, abi.encodeWithSelector, abi.encodeWithSignature, and abi.encodeCall. Relying on the presence or absence of memory padding is discouraged, as internal compiler behaviors can shift across pipelines and future updates.

The core root cause of the vulnerability lies in a divergence between standard element assignments and element deletions within the evmasm code generator. When a developer writes b[i] = 0, the compiler correctly consults the element width and issues a single-byte store instruction (mstore8), ensuring that only the specific byte at index i is cleared. Conversely, when the compiler processes delete b[i], it fails to account for the single-byte nature of packed array elements. Instead of executing an mstore8 instruction, the compiler emits a full 32-byte word store (mstore) starting directly at the byte index.

This 32-byte zero write overwrites the targeted element and cascades forward by another 31 bytes. Because the array’s 32-byte length header precedes the data array and remains untouched, the array maintains its original length value. Consequently, any subsequent operations that read the array—such as computing a keccak256 hash, performing ABI encoding, or returning the array data to an external caller—silently process the corrupted, zeroed-out memory bytes.

The extent of the damage depends heavily on the array’s length, its padding status, and the index of the deleted element. For padded arrays, the trailing padding bytes can absorb a portion of the write if an element near the end of the array is deleted. For instance, an array of length 40 contains 24 bytes of padding, meaning that deleting any of the final seven elements will cause the 32-byte write to spill past the array’s allocation by up to seven bytes. For unpadded arrays, deleting any of the final 31 elements will always spill over into the subsequent memory allocation. If the array itself is 31 bytes or shorter, every single index—including the very first element—will overflow into adjacent memory.

Real-World Demonstration and Manifestation

A conceptual contract illustrating the dual nature of this bug demonstrates how internal array corruption and cross-allocation memory bleeding occur in practice. Consider a contract containing a function that allocates a short byte array with a literal value, executes a delete operation on the first element, and returns the array. Under vulnerable compiler versions, executing delete d[0] on a five-byte array does not simply clear the initial byte; the subsequent 32-byte write sweeps through the entire allocation, clearing all remaining bytes in the array as well.

In a second scenario involving a 32-byte unpadded array immediately followed in memory by a complex data structure or integer variable—such as a uint256 initialized to its maximum possible value—deleting the final element of the array causes the 32-byte zero write to bleed directly into the adjacent variable. Because integers in EVM memory are stored with their most significant bytes first, the 31 overwritten bytes effectively obliterate the high-order data of the adjacent variable, drastically altering its numerical value. Replacing the delete statement with a standard assignment successfully avoids the corruption entirely.

Because the compiler emits no warnings and the EVM does not revert execution when this memory corruption occurs, detecting the bug can be challenging. The issue manifests purely as unexpected computational results or altered data states. Fortunately, thorough automated testing suites that inspect array contents after executing delete operations on memory byte arrays will typically surface internal array corruption during the development phase.

The Fix and Recommended Actions

The resolution implemented by the Solidity core team in version 0.8.37 directly addresses the root cause of the discrepancy. The patch modifies the compiler’s delete code path so that it properly consults the element width of the target data structure. When clearing an element within a packed byte array, the compiler now correctly emits a single-byte store instruction rather than a full-word memory write, bringing the behavior of delete b[i] into alignment with standard element assignments across all compilation pipelines.

Developers maintaining smart contracts written in Solidity are strongly advised to audit their codebases for instances where the delete keyword is applied to elements of memory-based bytes or string arrays. Project maintainers running vulnerable compiler versions up to 0.8.36 should upgrade their toolchains to Solidity 0.8.37 or later. For codebases unable to immediately upgrade their compiler version, developers should review any memory-based byte array manipulations and replace element-level deletions with explicit byte assignments where appropriate to ensure reliable and predictable contract behavior.

By Muslim

Leave a Reply

Your email address will not be published. Required fields are marked *