The Ethereum Foundation and the Solidity development team have released version 0.8.39 of the Solidity compiler to address a critical medium-severity vulnerability impacting smart contracts utilizing recursive structs. The bug, which can lead to silent storage corruption during specific struct and array copy operations, has been present in the compiler for over a decade, affecting multiple generations of smart contract deployments across the Ethereum ecosystem.
The issue was formally brought to light on April 22, 2026, when security researcher cyberthirst reported the flaw through the official Ethereum Foundation bug bounty program. Initial investigations and proof-of-concept exploits demonstrated that the defect allowed storage corruption to occur when a recursive struct was copied upward within a hierarchy, specifically when copied onto another struct containing it. During this process, the write operation would inadvertently overwrite the source’s own storage slots before the compiler had finished reading all of the source’s data, yielding corrupted values or entirely zeroed-out parameters without triggering any runtime errors or compilation warnings.
Further investigation by the Solidity team revealed that the vulnerability was not restricted to direct struct-to-struct copies. Array-to-array copies involving recursive structs were found to be similarly affected, expanding the potential attack surface for any decentralized applications maintaining hierarchical or tree-like data structures directly within blockchain storage.
Understanding the Vulnerability and Affected Contracts
To comprehend how the storage corruption manifests, consider a basic recursive struct definition in Solidity, such as a node containing a dynamic array of its own type alongside a standard data field:
struct Node
Node[] children;
uint256 data;
Node root;
Node[] roots;
According to the vulnerability disclosures, both struct-to-struct assignment patterns—such as copying a descendant onto an ancestor (root = root.children[i])—and array-to-array patterns—such as copying a nested array onto its enclosing array (roots = roots[i].children)—trigger the flawed behavior.
The root cause stems from the unique architecture of Ethereum’s storage layout. Unlike memory or calldata, storage utilizes a deterministic hash-based layout where dynamic arrays occupy a single storage slot containing their length, while their actual elements reside at locations determined by cryptographic hashing, such as keccak256(p). When a storage-to-storage copy operation walks through a struct member by member and an array element by element, copying a dynamic array resizes the target array and overwrites the physical region holding its elements.
In scenarios where the source and target overlap, copying an inner child array can overwrite the very storage area from which the source data is still being read. For instance, if the inner child array is copied first, it can shrink the target array and zero out adjacent elements. If a data field is situated after the array in storage, it is read after the overwrite occurs and returns a value of zero. Conversely, if the data field is placed before the array, it might survive the initial read, but deeper nested values within the subtree remain vulnerable to total loss. Because the exact shape of a copied subtree is frequently determined dynamically at runtime, predicting or mitigating these collisions manually within contract logic proves exceedingly difficult.
The Solidity core team noted that a contract is exclusively vulnerable if it incorporates a recursive struct, which can reference its own type either directly or via mutual recursion through another struct. Because storage structs cannot hold direct pointers and static arrays of the same type would require an infinite size, recursion in storage is strictly restricted to dynamic arrays or mappings. Since mappings cannot be copied, dynamic arrays represent the sole vector capable of triggering this specific storage overlap defect. Furthermore, operations like push() do not provoke the bug because they operate in the opposite direction—appending a new element and copying an argument into it, where the fresh element cannot possibly contain the source.
Technical Scope and Version History
The flaw affects an extensive range of Solidity compiler versions. According to the release notes and security advisories, the bug has been present since version 0.4.9, which was the first release to successfully compile recursive structs. Consequently, both the struct and array copy defects have existed for as long as recursive structs have been supported by the language.
In addition to the legacy evmasm code generator, the IR-based code generation pipeline (--via-ir) has been affected since version 0.8.13, which marked the first official release where the IR pipeline was no longer categorized as experimental. Although the bug existed within the experimental IR pipeline prior to that milestone, the development team tracks official susceptibility starting from version 0.8.13 through version 0.8.38. All affected copy patterns have been fully resolved in Solidity 0.8.39.
Severity Assessment and Ecosystem Impact
The Solidity team has assigned an internal severity rating of medium to the vulnerability, balancing a potentially severe impact against a low real-world likelihood of occurrence.
When triggered, fields read after a corrupted array copy—such as account balances, permission flags, ownership markers, or numerical thresholds used in conditional checks—can silently evaluate to zero. In a security-critical smart contract, this unexpected zeroing can transform a strict access control check or validation barrier into an unconditional pass. Because the copy operation executes silently without throwing exceptions or generating runtime reverts, the resulting state corruption can easily go unnoticed by developers and users alike.
Despite the gravity of these potential consequences, the core team believes the practical risk to deployed decentralized applications is low. Comprehensive scans of verified smart contracts across platforms like Sourcify revealed no instances of contracts actively performing this precise type of storage-to-storage overlapping copy with recursive structs. While developers frequently implement tree-like structures in storage to manage organizational hierarchies, routing graphs, or organizational charts, those who utilize recursive structs typically manage them entirely in-memory or design their storage update patterns to avoid target-contains-source assignments entirely. Moving large subtrees in storage is notoriously gas-intensive, making such patterns rare in production environments.
The Fix and Recommended Developer Actions
Solidity 0.8.39 introduces a comprehensive runtime check designed to eliminate storage-to-storage copy corruption for recursive structs. Before executing any storage-to-storage copy involving a recursive struct, the compiled bytecode now executes a safety check that walks the target’s subtree to determine whether it contains the source.
If an overlap is detected, the compiler automatically snapshots the source into temporary memory before performing the write operation. The copy operation then reads directly from this safe memory snapshot, ensuring that the source and target no longer occupy overlapping storage regions during the assignment. If no overlap is detected, the copy proceeds directly as before.
This architectural solution introduces a deliberate engineering trade-off. The safety check executes on every storage-to-storage copy of a recursive struct, even when no overlap exists, trading incremental gas efficiency for absolute memory safety. Consequently, developers may notice a slight increase in gas consumption for operations involving recursive structs, with the gas cost scaling linearly relative to the depth of the nested structs held by the target.
Additionally, because the overlap-detection check utilizes stack space during its recursive traversal, deep storage hierarchies can encounter stack-to-deep errors at shallower levels than in previous compiler versions. For instance, tests compiled via the IR pipeline with the optimizer enabled demonstrated a drop in maximum safe recursion depth from 252 levels down to 126 levels. The reverse scenario—where the source contains the target—remains unsupported and exhibits undefined behavior, as the fix does not evaluate overlap in that direction.
Developers maintaining smart contracts that utilize recursive structs are strongly encouraged to upgrade their compilation toolchain to Solidity 0.8.39 or later. Furthermore, teams whose codebases execute complex storage copy operations on hierarchical data structures should carefully review their historical storage states to verify that no silent corruption occurred prior to the compiler upgrade.
The discovery and responsible disclosure of the vulnerability were credited to security researcher cyberthirst, acting through the Ethereum Foundation’s established bug bounty initiative.

