19 Oct 2026, Mon

Critical Memory Corruption Bug Discovered in Solidity Code Generator Affecting Versions up to 0.8.37

A critical security vulnerability has been uncovered within the Solidity code generator, impacting all historical versions of the Ethereum smart contract language up to and including version 0.8.36. The flaw, which involves the improper handling of the delete operator on elements of memory-based bytes and string arrays, can result in unexpected memory corruption, altering data both within the targeted array and potentially overwriting adjacent memory allocations.

Discovered on August 14, 2026, by researcher Shaheen Fazim through the Ethereum Foundation’s bug bounty program, the vulnerability has been classified with a "low/medium" severity rating on the internal scale maintained by the Solidity development team. The issue is strictly confined to the default evmasm compilation pipeline, leaving the newer IR (Intermediate Representation) pipeline entirely unaffected. Furthermore, the activation of the optimizer is not required for the bug to manifest, as the core flaw originates directly in the code generation stage.

Understanding the Vulnerability and Impact

The root of the issue lies in how the evmasm code generator implements the delete keyword when it is applied to specific indices of packed byte arrays located in memory. In Solidity, standard values in memory occupy full 32-byte words. However, bytes and string types are exceptions because their elements are packed back-to-back without gaps to optimize space.

When a developer applies the assignment operation b[i] = 0 to a memory byte array, the compiler correctly issues a single-byte store operation (mstore8), ensuring that precisely one byte is cleared. In contrast, the internal code path triggered by delete b[i] historically executed a full 32-byte zero-word write starting directly at the location of the targeted element. Because this write begins at the specific index rather than aligning with a natural word boundary, it stretches forward across the array, clearing up to 31 subsequent bytes.

This unintended extensive zeroing causes two distinct types of corruption depending on where the deleted element resides. The first type is internal corruption, where elements immediately following the deleted index inside the same array are wiped out. The second and more severe type involves corruption beyond the array boundaries. When an element near the end of a memory array is deleted, the 32-byte write can spill past the array’s allocation and directly overwrite whatever data sits immediately afterward in memory, such as adjacent variables or structs.

Scope, Affected Contracts, and Compiler Pipelines

The affected code path has a deep lineage within the compiler codebase, predating the very first official release version of Solidity. Consequently, every version released prior to the patch is vulnerable. The Solidity development team addressed the vulnerability in version 0.8.37 by updating the delete code path to correctly reference the element width, aligning its behavior with standard assignments and ensuring that single-byte stores are used across both compilation pipelines.

To gauge the real-world impact of the bug, developers and researchers scanned the Sourcify database, which contains approximately 870,000 verified smart contract compilations, searching specifically for the vulnerable source code pattern. The scan revealed that the pattern appeared in a mere 17 compilations, encompassing only two distinct functions. Upon closer security assessment, neither of those functions was found to be genuinely vulnerable; in one instance, the corrupted bytes were discarded immediately, while in the other, the memory following the array was completely unused at the time of execution. To date, no deployed production contracts are known to have suffered malicious exploitation or unintended failures due to this defect.

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

For a contract to be considered vulnerable, a precise set of conditions must be met simultaneously. Crucially, the contract must utilize the default evmasm pipeline rather than the IR pipeline, and it must explicitly apply the delete operator to an element of a bytes or string array residing in memory. Contracts that never invoke delete on individual elements of memory byte arrays remain entirely safe.

It is also worth noting that byte arrays stored in permanent blockchain storage (storage) are managed through a completely separate code path and are completely unaffected by this bug. Similarly, calldata arrays and arrays whose individual elements already occupy full 32-byte words—such as bytes1[] memory—do not experience the issue, as only variable-length packed byte arrays pack their constituent elements tightly together.

Technical Demonstration and Developer Guidance

To illustrate how the bug manifests in practice, security analysts constructed a simple demonstration contract featuring memory layout interactions. In a test function named clearElement, a five-byte memory array is initialized, and delete d[0] is executed. While developers would expect only the initial byte to reset to zero, leaving the subsequent four bytes intact, the buggy code generator overwrites all five bytes with zeroes.

In another test function named clearLastElement, a 32-byte memory array is allocated immediately adjacent to a uint256 variable initialized to its maximum possible value. Applying delete b[31] to the final element of the array causes the 32-byte zero write to spill 31 bytes past the array boundary and into the adjacent storage slot in memory. Because integers are stored with their most significant bytes first, the overwrite zeroes out the 31 most significant bytes of the neighboring variable, fundamentally altering its numeric value and returning an unexpected result.

Because the compiler emits no warnings and the Ethereum Virtual Machine does not trigger a runtime revert when the memory corruption occurs, detecting the bug relies heavily on thorough unit testing and code review. The vulnerability presents itself purely as corrupted data or altered program logic, making it difficult to diagnose post-deployment if tests do not explicitly check the integrity of neighboring memory values.

The Ethereum Foundation and Solidity core developers recommend that all projects utilizing affected compiler versions update their toolchains to Solidity 0.8.37 or later. Developers who cannot upgrade immediately are advised to audit their codebases for instances where the delete keyword is applied to elements of memory bytes or string arrays, replacing those operations with explicit assignments where necessary or migrating compilation workflows to the IR pipeline.

The discovery and responsible disclosure of this memory management flaw underscore the ongoing importance of rigorous bug bounty programs and community-driven security reviews in maintaining the safety of the broader decentralized ecosystem.

Leave a Reply

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