Skip to main content
Sigvex

Solc Storage Write Removal Bug (2022-09) Remediation

How to remediate the 0.8.13–0.8.16 Yul optimizer bug that dropped storage writes: recompile with 0.8.17+ and redeploy.

Solc Storage Write Removal Bug (2022-09) Remediation

Overview

Related Detector: Solc Storage Write Removal Bug (2022-09)

The Yul unused-store eliminator in Solidity 0.8.13 through 0.8.16 could delete an sstore that preceded a conditional return/stop reached through inline assembly or an inlined function — even though the terminating path meant the write was not actually dead. A missing storage write is a serious silent bug. Because it lives in the optimizer, the remediation is to rebuild with a fixed compiler and redeploy.

// Affected: solc 0.8.13–0.8.16 with the IR/Yul optimizer, pattern
//   x = 1; g(a); x = 2;  where g(a) may terminate execution.
// Fixed in: solc 0.8.17.

pragma solidity ^0.8.17;   // or later

Steps:

  1. Recompile with 0.8.17 or later.
  2. Redeploy affected contracts — recompilation does not change already-deployed bytecode.
  3. Confirm the storage write is present in the new bytecode (the detector flags its absence).

If you must stay on an affected version temporarily, disabling the Yul optimizer avoids this specific pass, but upgrading is the correct fix.

Common Mistakes

  • Adding a redundant re-write of the variable in source to “force” the store, which the same optimizer may again elide.
  • Upgrading the pragma but building with an affected local compiler.
  • Assuming the bug is theoretical — a dropped sstore can leave an access-control flag or balance unset.

References