20 Nov 2026, Fri

Solidity Vulnerability Disclosed: Critical Storage Corruption Bug in Recursive Structs Fixed in Version 0.8.39

The Ethereum Foundation and the Solidity core development team have released version 0.8.39 of the widely used smart contract programming language, addressing a significant medium-severity vulnerability that could lead to silent data corruption in blockchain storage. The flaw, which has existed across multiple generations of the compiler for over a decade, centers on how storage-to-storage assignments handle recursive structures and nested dynamic arrays.

The security issue was officially brought to light on April 22, 2026, when security researcher and auditor cyberthirst reported the bug through the Ethereum Foundation’s official bug bounty program. Initial investigations and proof-of-concept exploits submitted by the researcher demonstrated that copying recursive structs directly could result in unexpected behavior. Subsequent analysis by the Solidity team revealed that the issue was not isolated to direct struct-to-struct copying, but also affected array-to-array copy operations involving these specialized recursive data types.

Understanding the Vulnerability and Affected Contracts

To grasp the mechanics of the bug, developers must look at how Solidity manages memory and storage layout. A recursive struct typically defines a data type that references collections of its own type, either directly or through mutual recursion involving other structs. For example, a standard tree node implementation might incorporate a dynamic array of child nodes alongside standard value types such as a uint256 data field.

The flaw manifests during a storage-to-storage assignment where a descendant node is copied onto an ancestor, or where a nested dynamic array is assigned over its enclosing array. Under the hood, Solidity handles storage-to-storage copies by walking through members and array elements iteratively. Because dynamic arrays in Ethereum storage occupy a single slot containing their length, while their actual elements are stored at memory addresses derived from a keccak256 hash of that slot, overwriting a parent array can inadvertently overwrite the very storage area from which the source data is currently being read.

As a result, before the compiler finishes reading all the fields of the source struct, the target array copy overwrites them. This causes affected fields—such as numerical balances, identifiers, or critical permission flags—to be abruptly zeroed out. In practice, this could transform a restrictive conditional check within a smart contract into an unconditional pass, introducing severe logical flaws. Because the EVM executes these operations without throwing a runtime error or a revert, the resulting data corruption remains completely silent, making post-deployment auditing exceptionally difficult.

The vulnerability impacts both the legacy evmasm code generation pipeline and the newer Intermediate Representation (--via-ir) pipeline. According to the development team, every compiler release from version 0.4.9 up to version 0.8.38 is vulnerable. Version 0.4.9 was historically significant as the first release to support recursive structs, meaning the flaw has been embedded within the codebase since those structures became compilable. Meanwhile, the IR pipeline has been affected since version 0.8.13, when it graduated from experimental status.

Technical Scope and Limitations

Despite the broad version range, the practical attack surface for this bug is relatively narrow. Smart contracts that do not utilize recursive structs are entirely unaffected by the issue. Furthermore, the corruption strictly requires a storage-to-storage copy where the target structure contains the source structure. Operations utilizing the .push() method, for instance, cannot trigger the bug because they operate in the opposite direction—appending a new element and copying an argument into it, where a newly created element cannot possibly contain the source.

The Solidity team conducted an extensive scan of all verified smart contracts hosted on Sourcify to gauge the real-world prevalence of the issue. The analysis found no instances of contracts actively performing this specific type of overlapping storage-to-storage copy with recursive structures. While recursive structs are occasionally deployed to maintain tree-like hierarchies in storage, developers overwhelmingly prefer reference-based linking schemes or memory-bound structures that avoid expensive storage modifications. Consequently, the core team assigned the vulnerability a medium-severity rating, reflecting a scenario where the technical consequences could be severe, but the likelihood of accidental or malicious exploitation in existing deployments remains low.

The Fix and Implementation Trade-offs

Solidity 0.8.39 introduces a comprehensive runtime safety check for all storage-to-storage copies involving recursive structures. Prior to executing a copy operation, the compiled bytecode now performs a traversal of the target’s subtree to evaluate whether it contains the source.

When an overlap is detected, the compiler automatically creates an in-memory snapshot of the source data before initiating the write operation. The copy procedure then reads directly from this safe snapshot rather than the live storage slot, ensuring that source and target data do not collide during execution. If no overlap is found between the source and target, the copy proceeds normally without intervention.

This protective mechanism introduces important trade-offs for developers. Because the safety check executes on every storage-to-storage copy of a recursive struct—even when no overlap exists—it incurs an additional gas cost. This overhead scales linearly with the depth and number of nested structs maintained by the target.

Furthermore, the runtime traversal consumes additional stack space. As a direct consequence, smart contracts that copy data into deeply nested targets may encounter stack-too-deep errors or run out of stack space at shallower levels than was possible under previous compiler versions. For instance, in benchmark tests compiled via the IR pipeline with optimizations enabled, the maximum supported nesting depth decreased from 252 levels down to 126 levels.

The development team noted that the inverse scenario—where the source contains the target—remains unsupported and exhibits undefined behavior, as the patch does not introduce overlap checks for that specific direction. Developers attempting such operations should expect transactions to revert and are strongly advised to redesign their contract logic to avoid downward structural assignments.

Recommended Actions for Developers

Smart contract developers and protocol maintainers using any compiler version between 0.4.9 and 0.8.38 are urged to evaluate their codebases for the presence of recursive structs and storage copy patterns. Projects that incorporate these data structures should immediately upgrade their compilation toolchain to Solidity 0.8.39 or later.

Teams whose protocols have historically executed complex storage-to-storage tree manipulations should conduct a thorough state audit of their deployed contracts to verify that no critical data fields experienced silent corruption prior to the compiler patch.

The Ethereum Foundation and Solidity core contributors extended their gratitude to security researcher cyberthirst for identifying and responsibly disclosing the vulnerability through the official bug bounty ecosystem.

Leave a Reply

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