18 Nov 2026, Wed

Solidity Vulnerability Discovered: Memory Byte Array Element Deletion Bug Affects Versions up to 0.8.37

A critical compiler defect impacting the Ethereum ecosystem has been officially disclosed following a report submitted through the Ethereum Foundation’s bug bounty program. On August 14, 2026, security researcher Shaheen Fazim identified a code generation flaw in Solidity. The issue resides in how the compiler handles the delete operator when it is applied to specific memory-resident byte array elements. Rather than clearing solely the targeted index, the generated bytecode inadvertently executes a full 32-byte zero-write starting at that precise location. This unintended memory corruption can overwrite adjacent elements within the same array or spill over into subsequent memory allocations, creating unpredictable behaviors in smart contracts compiled under affected versions.

The discovery prompted an immediate security assessment by the Solidity development team. Evaluated at a low-to-medium severity level on their internal scale, the vulnerability specifically impacts the legacy default evmasm compilation pipeline. Contracts compiled using the modern IR (Intermediate Representation) pipeline remain entirely unaffected. Crucially, the activation of the Solidity optimizer is not required for the bug to manifest; the defect is natively embedded in the structural code generation phase itself. Historical analysis of the codebase reveals that the affected code path predates the very first official release of Solidity, meaning that every compiler version up to and including 0.8.37 carries the risk if specific programming patterns are utilized.

Which Contracts Are Affected?

To determine whether a deployed or under-development smart contract is exposed to this vulnerability, developers must understand that a specific sequence of conditions must align. The bug exclusively targets the evmasm pipeline while utilizing the delete operator on memory-located bytes or string arrays. If a smart contract never applies the delete operation to an individual element of a memory-based byte or string array, it remains entirely safe.

A thorough investigation clarifies three essential nuances regarding the scope of the bug. First, the defect is strictly limited to individual element deletions. Executing a delete statement on an entire array, such as delete b where b is the array itself, invokes a completely separate code path that functions correctly. Second, the array must reside in memory. Byte arrays stored in contract storage utilize an entirely distinct management mechanism and are unaffected, while calldata arrays cannot be targeted by the delete operator at all. Furthermore, arrays whose individual elements naturally occupy a full 32-word memory slot—such as bytes1[] memory—are untouched because only dynamically packed types like bytes and string tightly pack their elements without internal gaps.

Third, string values are impacted transitively. Although direct index deletion like delete s[i] is not permitted for a string memory variable in Solidity syntax, developers frequently cast strings to byte arrays via bytes(s). Executing delete bytes(s)[i] triggers the exact same faulty code path, modifying the underlying string memory directly in place.

Technical Details

To comprehend why this anomaly occurs, one must examine how Solidity manages memory allocation at the EVM (Ethereum Virtual Machine) level. Most data types in Ethereum memory consume a full 32-byte word. The bytes data type serves as a primary exception: a memory-based byte array consists of a 32-byte length header immediately followed by its sequential raw data, packed back-to-back without internal word-boundary padding.

Solidity allocates memory linearly by shifting the free memory pointer forward. Consequently, consecutive memory allocations sit flush against one another, separated only by calculated alignment padding. When an operation writes past the designated boundary of one variable, it immediately infiltrates the next memory slot.

Most memory byte arrays—such as those instantiated using new bytes(n) or initialized from literal values—are "padded" arrays. The compiler appends up to 31 zero bytes of padding at the end of the data so that the subsequent memory allocation initiates cleanly on a new 32-byte word boundary. However, the legacy evmasm pipeline leaves certain dynamic creations unpadded. Specifically, arrays generated via bytes.concat, string.concat, and the family of ABI encoding functions (abi.encode, abi.encodePacked, abi.encodeWithSelector, abi.encodeWithSignature, and abi.encodeCall) terminate their data precisely where the next allocation begins, creating unpadded arrays whose trailing edge leaves no margin for error.

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

The Delete Path and Memory Corruption

In standard Solidity semantics, executing delete x should assign the default zero value corresponding to the type of x. Therefore, applying delete b[i] to a byte array element ought to be logically identical to executing b[i] = 0. Both operations ultimately culminate in writing a zero value to the element’s memory address. However, within the legacy evmasm pipeline, these two operations diverge sharply in how their underlying store instructions are implemented.

While a direct assignment like b[i] = 0 correctly leverages a single-byte store instruction (mstore8) to clear exclusively the targeted byte, the delete path mistakenly emits a full 32-byte word store (mstore). Because this 32-byte zero-write originates from the index of the deleted element rather than a clean 32-byte word boundary, it spills forward, wiping out up to 31 subsequent bytes. The array’s length header, located prior to the data payload, remains untouched, meaning the array retains its original length value. Consequently, any subsequent operations relying on the array contents—such as computing cryptographic hashes via keccak256, performing ABI encoding, or returning data to an external caller—will process the silently corrupted byte sequence.

The extent of the damage depends heavily on the index of the deleted element and whether the array is padded. When corruption occurs entirely within the array, every subsequent element up to a distance of 31 bytes is overwritten with zeros. Unless those subsequent bytes were already zero, the data is permanently altered. When corruption reaches beyond the array, the overflow spills directly into whatever variable or data structure was allocated next in memory. Left-aligned types lose their most significant bytes, while right-aligned types—such as integers, addresses, and pointers—suffer truncation or complete data corruption depending on the precise width of the write.

Practical Demonstration

The mechanics of this vulnerability can be observed in a controlled contract environment that relies on adjacent memory allocations produced by the compiler:

contract C 
    struct S  uint256 x; 

    function clearElement() public pure returns (bytes memory) 
        bytes memory d = hex"0102030405";
        delete d[0];
        return d;
    

    function clearLastElement() public pure returns (uint256) 
        bytes memory b = new bytes(32);
        S memory s = S(type(uint256).max);
        delete b[31];
        return s.x;
    

When compiled using standard default settings under the vulnerable evmasm pipeline, executing clearElement returns a fully zeroed byte sequence instead of isolating the zeroing to the first index. Similarly, in clearLastElement, the 32-byte array sits adjacent to a struct containing a maximum-value integer. Deleting the final element of the byte array triggers a 31-byte overflow into the adjacent struct memory, stripping away the most significant bytes of the integer and fundamentally altering the function’s return value. Replacing these delete statements with direct assignments (d[0] = 0 and b[31] = 0) bypasses the flawed code path, producing the expected and correct results across all tested versions.

Severity Assessment and Remediation

Despite the potential for data corruption, extensive automated database scans of roughly 870,000 verified compilations on the Sourcify platform revealed that the triggering source pattern appeared in only a tiny fraction of compilations, with no known deployed mainnet contracts suffering adverse impacts. The bug’s low real-world frequency stems from the narrow set of coincidences required for an active memory overflow to alter critical execution paths.

The Solidity core team addressed the vulnerability by aligning the delete code path with the assignment code path. In the patched compiler version, clearing a packed byte array element correctly triggers the single-byte store instruction (mstore8) rather than a full-word store, ensuring that delete b[i] and b[i] = 0 share identical semantics across both compilation pipelines. Developers utilizing affected versions are strongly advised to update their toolchains and review codebases where memory-based byte or string element deletion is utilized.

Leave a Reply

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