3 Dec 2026, Thu

Critical Solidity Compiler Bug Discovered: Memory Byte Array delete Operations Causing Unintended Word-Wide Overwrites

The Ethereum Foundation and the Solidity core development team have released an urgent security advisory detailing a long-standing code generation defect discovered within the popular smart contract programming language. Identified through the Ethereum Foundation’s bug bounty program, the vulnerability exposes a flaw in how the default evmasm compilation pipeline handles memory-based bytes and string arrays. Specifically, applying the delete operator to a single element inside a dynamic memory byte array triggers a cascading 32-byte zero-write rather than selectively clearing the targeted index. This unexpected behavior risks corrupting adjacent memory layouts, potentially altering unrelated variables, altering contract states silently, and generating erratic execution outcomes across deployed protocols.

The issue was responsibly disclosed on August 14, 2026, by researcher Shaheen Fazim. According to technical assessments performed by the Solidity team, the underlying code path responsible for this defective behavior predates the very first publicly released version of the language. As a result, every single version of Solidity up to and including version 0.8.36 is affected. The vulnerability has been officially patched in Solidity 0.8.37, urging developers and protocol maintainers to upgrade their toolchains immediately.

Understanding the Vulnerability and Code Generation Mechanics

To comprehend the scope and nature of the bug, one must examine how Solidity manages data structures within the Ethereum Virtual Machine’s (EVM) memory space. In the EVM, most values allocated in memory occupy full 32-byte words, which are aligned to standard architectural boundaries. However, dynamic byte arrays (bytes) and text strings (string) serve as a prominent exception to this rule. These structures are stored as a 32-byte length header followed immediately by raw, tightly packed data bytes without internal gaps.

Memory allocation in Solidity relies on advancing a dynamic free memory pointer. Consecutive memory allocations sit flush against one another, meaning that any write operation running past the intended boundary of a specific variable will inadvertently bleed into the memory space allocated for the subsequent variable. For standard operations like new bytes(n) or static string literals, the compiler typically appends up to 31 bytes of trailing zero padding so that the next memory allocation begins cleanly on a word boundary. However, certain data-handling routines, such as bytes.concat, string.concat, and ABI-encoding functions like abi.encode and abi.encodePacked, generate unpadded byte arrays where data ends precisely where the next allocation starts.

When a developer intends to clear a specific element inside a byte array using the delete statement—such as invoking delete b[i]—the expected outcome is functionally identical to a direct element assignment like b[i] = 0. Both operations ultimately culminate in a write command to update the memory slot of the targeted element. Yet, within the default evmasm compilation pipeline, these two expressions follow entirely separate code paths.

While the direct assignment correctly executes a single-byte store (mstore8) targeting solely the exact index specified by the developer, the delete path erroneously issues a full 32-byte zero-write. Because this massive write initiates directly at the index of the deleted element rather than aligning to a standard 32-byte word boundary, it stretches forward by an entire EVM word. Consequently, the operation wipes out up to 31 subsequent bytes located further down the array or, if the deleted element resides near the array’s tail, spills past the boundary entirely to overwrite whatever data structures happen to reside in the subsequent memory allocation. Crucially, the array’s length header remains completely untouched throughout this process, meaning the data structure preserves its original length dimension while its internal contents are silently corrupted. Subsequent operations—such as calculating cryptographic hashes via keccak256, performing ABI encoding routines, or returning data to external callers—will read these corrupted bytes without triggering any runtime exceptions or compiler warnings.

Scope of Impact and Affected Contracts

The severity of the vulnerability has been internally rated as low-to-medium. This classification stems from several mitigating factors, most notably that the bug is strictly isolated to the default evmasm code generation pipeline. Contracts compiled using the alternative Intermediate Representation (IR) pipeline remain entirely unaffected. Furthermore, the activation of the Solidity optimizer is not required to trigger the bug, as the faulty semantics are inherently baked into the emitted bytecode by the code generator itself.

Several strict conditions must align simultaneously for a smart contract to be vulnerable. First, the contract must be compiled using an affected version of Solidity, specifically any release up to version 0.8.36. Second, the compilation process must utilize the default evmasm pipeline. Third, the source code must explicitly apply the delete operator to an element of a dynamic bytes or string array residing in memory.

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

The core team has clarified three critical nuances regarding these conditions. First, the bug exclusively affects element-level deletions. Applying the delete operator to an entire array (such as delete b) 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 separate implementation path and are completely immune, while calldata arrays do not permit delete operations whatsoever. Furthermore, fixed-width arrays whose elements each occupy a full 32-byte word in memory—such as bytes1[] memory—are unaffected because their elements are not tightly packed. Only dynamic bytes and string types pack elements densely enough to prompt the faulty full-word write. Third, while direct index deletion like delete s[i] is not permitted for standard string memory types, developers frequently cast strings to bytes via explicit conversions, writing expressions such as delete bytes(s)[i]. This pattern triggers the exact same underlying memory corruption vulnerability.

To gauge the real-world prevalence of the defect, the Solidity team conducted a comprehensive scan of the Sourcify verified compilation database, analyzing approximately 870,000 verified smart contract compilations for the triggering source code pattern. The investigation revealed that the vulnerable pattern appeared in only 17 distinct compilations across just two unique functions. Further manual analysis confirmed that neither of those deployed functions was actually compromised in practice; in both instances, the overwritten bytes were either immediately discarded or written into unallocated memory regions where no active state variables resided. As a result, no known deployed smart contracts have suffered malicious exploitation or unintended state corruption due to this bug.

Practical Manifestation and Technical Demonstration

To illustrate how the bug materializes during contract execution, the Solidity core team provided a reference test contract. The demonstration relies on the compiler’s sequential memory allocation behavior, where variables declared consecutively are placed flush against one another in memory.

contract C 
    struct S  uint256 x; 

    // Corruption inside the array.
    function clearElement() public pure returns (bytes memory) 
        bytes memory d = hex"0102030405";
        delete d[0];
        return d;
    

    // Corruption beyond the array.
    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 under standard default settings using the evmasm pipeline, these functions yield unexpected results. In the clearElement function, a short five-byte array is allocated within a single padded word. Executing delete d[0] erroneously clears the entire 32-byte word starting from index zero, wiping out the initial byte alongside the remaining four bytes of the array, returning a sequence of all zero bytes instead of selectively clearing only the first index.

In the clearLastElement function, a 32-byte array is allocated without trailing padding, sitting directly adjacent to a memory structure s containing a uint256 integer initialized to its maximum possible value. Deleting the final element at index 31 issues a 32-byte zero-write that spills over into the adjacent memory structure, overwriting the 31 most significant bytes of s.x. Because large integers are stored with their most significant bytes first, the overflow leaves only the single lowest byte intact, causing the function to return 255 instead of the expected maximum integer value. Replacing these delete statements with explicit element assignments like d[0] = 0 and b[31] = 0 produces the correct, expected behavior across all tested compiler versions.

The Fix and Recommended Actions

The root cause of the defect has been fully addressed in Solidity version 0.8.37. The core engineering team updated the compiler’s delete code path to correctly consult the element width in the same manner that standard assignment operations already do. When processing a deletion on a packed byte-array element, the compiler now correctly emits a single-byte store (mstore8) rather than a full-word store. This ensures that delete b[i] and b[i] = 0 share identical, safe semantic behavior across both compilation pipelines.

Developers and project maintainers are strongly encouraged to upgrade their development environments to Solidity 0.8.37 or later. Teams utilizing the default evmasm pipeline should review their codebases to verify whether delete statements are applied to elements of memory-based bytes or string arrays. For projects unable to upgrade immediately, developers can manually refactor vulnerable code patterns by replacing element deletions with explicit zero assignments, such as substituting delete b[i] with b[i] = 0, which remains unaffected by the bug regardless of the compiler version used.

Leave a Reply

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