Coin Brief ENDE

Solidity 0.8.39 fixes a bug that silently corrupted storage when copying recursive structs

The Solidity team released compiler version 0.8.39 on 19 November. Its main fix is for a bug the team rates as medium severity that could corrupt contract storage without any error. It appeared when a recursive struct - one that can contain values of its own type, such as a Node with an array of child Nodes - or an array of such structs was copied inside storage onto a location that contained the source, as in root = root.children[0]. The copy overwrote the area holding the source before it had finished reading it, so nested elements were lost and members declared after the array read back as zero.

The overlap is not always visible in the code: it can come through a storage pointer, a mapping key or an array index. Both the legacy evmasm pipeline and the IR pipeline are affected regardless of optimizer settings or EVM version, from 0.4.9 to 0.8.38 for evmasm and from 0.8.13 to 0.8.38 for IR. The fix adds a runtime check to every storage-to-storage copy of a recursive struct, which costs extra gas even when nothing overlaps and uses stack space; in one example compiled with --via-ir and the optimizer, the deepest possible copy fell from 252 to 126 levels. The team scanned verified contracts in the Sourcify database and found none that performs an affected copy. The report came from cyberthirst through the Ethereum Foundation bug bounty.

The release also fixes a miscompilation in which a nested tuple assignment containing a string literal could put values into the wrong variables in the evmasm pipeline, which the team does not treat as a security issue. With --evm-version amsterdam, the compiler now warns at the larger code size limits of EIP-7954, 64 KiB for contract code and 128 KiB for initcode. The announcement says 0.8.39 is likely the last 0.8 release; 0.9.0 will no longer be tied to making the IR pipeline the default, and the team plans smaller breaking releases more often.

Solidity 0.8.39 fixes a bug that silently corrupted storage when copying recursive structs
Solidity 0.8.39 fixes a bug that silently corrupted storage when copying recursive structs — Coin Brief

Why it matters

The bug needed an unusual pattern, and no deployed verified contract was found to use it, but it is the kind that produces wrong state with no revert to warn anyone. Projects that copy tree-like structures in storage should recompile with 0.8.39 and check that the added check's gas and stack cost still fit.