Solidity Optimizer Bugs: How Compiler Passes Put Access Control at Risk

Solidity Optimizer Bugs: How Compiler Passes Put Access Control at Risk

EVM bytecode, optimizer bugs, Solidity compiler

Solidity optimizer bugs returned to the advisory list on October 22, 2026, when the Solidity team published SOL-2026-7, a defect in the Yul optimizer which lets compiled contracts read outdated storage values or lose storage writes they still need.

The advisory carries a low severity rating and describes no access control exploit, yet the defect shows how an audited source file can behave differently after the compiler rewrites it.

What the SOL-2026-7 advisory describes

Two Yul optimizer steps, LoadResolver and EqualStoreEliminator, track which values the code wrote to memory and storage. Each step describes an address as a constant offset from zero or from a base variable, and treats two addresses with the same base as distinct when their offsets differ.

The compiler cached the descriptions per variable. When code reassigned the base variable, the optimizer sometimes kept the old description and compared an address built from the old value with one built from the new value. The result was a stale storage address: a load returned an outdated value, or the optimizer deleted a store the slot still needed.

The bug affects Solidity 0.8.19 through 0.8.37, and the Solidity team fixed it in 0.8.38. Only builds with the Yul optimizer enabled carry the risk. With via-IR, any contract can trigger the defect, including contracts without inline assembly. With the default legacy pipeline, only compiler-generated Yul utility functions and inline assembly blocks without references to Solidity variables or functions qualify.

Compiling Sourcify’s verified contracts with 0.8.38 changed no bytecode, which points to a very rare trigger.

Why modifier checks depend on compiler correctness

A modifier is a source-level construct, because the compiler inlines its body at every call site. An onlyOwner check becomes a storage read, a comparison and a revert placed in front of the function body.

After inlining, the optimizer treats modifier code like any other statement and works on a flat sequence of sload, sstore and call instructions.

Diagram of Solidity optimizer bugs in the path from modifier source code to EVM bytecode
Figure 1. The Yul optimizer rewrites inlined modifier code before the chain executes it

The optimizer reorders or removes work whenever its analysis shows the change preserves behavior. Yul has no arbitrary jumps, so the optimizer computes the side effects of each function and uses them to move or drop calls. The method holds only when the model captures every side effect.

Bug #7411, present before version 0.5.12, swapped the evaluation order of two side-effecting functions through an algebraic rule proven correct with Z3, because the proof ignored side effects.

Solidity optimizer bugs documented to date change values, drop writes and swap evaluation order. None of the 14 optimizer-conditioned entries in the Solidity bug list describes a modifier running out of order.

The nearest documented case, SOL-2026-3, sits in the analysis stage: a warning routine reversed the inheritance order, and with it modifier resolution, in Solidity 0.8.29 through 0.8.35. The trigger requires a custom storage layout placed too close to the end of storage, which excludes nearly all contracts.

Documented bug classes that touch authorization state

Several Solidity optimizer bugs touch state which authorization code reads: owner slots, role mappings, pause flags and reentrancy locks. The first, storage write removal, carries a medium/high rating.

In Solidity 0.8.13 through 0.8.16, the Yul optimizer removed a storage write placed before a call to a Yul function which conditionally ended the transaction with return or stop. Differential fuzzing found the defect on September 5, 2022.

The FullInliner evaluation-order bug (SOL-2023-2) changed the order of arguments with side effects. Yul evaluates arguments right to left, and the inliner replaced the order when code was not in expression-split form.

OtterSec’s Robert Chen reported the defect on July 4, 2023. Only custom optimizer step sequences trigger it, which explains the low rating.

Memory writes disappeared in a similar way: in versions 0.8.13 and 0.8.14, the optimizer removed inline assembly memory writes which a later block read.

SOL-2026-1, rated high, affects Solidity 0.8.28 through 0.8.33 with via-IR and the Cancun EVM version or later, where a contract clearing persistent and transient storage in the same bytecode cleared only one location.

Table of Solidity optimizer bugs with affected compiler versions, severity and effect on bytecode
Figure 2. Five optimizer-conditioned advisories with a fix version in the official Solidity bug list

Research data on how often compilers miscompile

A July 2026 preprint from Ethereum Foundation researcher Bhargava Shastry reports 25 miscompilation bugs found by the SolSmith fuzzer over three years. Solidity optimizer bugs make up 17 of them, 14 in the Yul optimizer.

The most common root cause, with 11 bugs, is an insufficient safety check: a rewrite rule correct for most inputs and wrong for a few. The preprint also lists a Yul IR generator defect, issue #12061, which forwarded modifier input parameters incorrectly.

Bar chart of root causes behind 25 Solidity compiler miscompilation bugs
Figure 3. Insufficient safety checks cause 11 of 25 miscompilation bugs found by differential fuzzing

Solidity optimizer bugs stay hidden for long periods in the code base, and the median bug lived 134 days. Seven of the 22 traced bugs lasted over one year, and the legacy Keccak caching bug survived 2,148 days.

A 2024 ISSTA study of 533 compiler bugs explains why Solidity optimizer bugs fail silently: only 22.86% of optimizer defects crash the compiler, against 69.98% of all bugs, so most never trigger a compiler error message. Off-the-shelf fuzzers found 14 of 108 benchmark bugs.

25

Miscompilation bugs found by the SolSmith fuzzer in three years.

17 and 14

Bugs in optimizers, and the share located in the Yul optimizer.

11

Bugs caused by an insufficient safety check, the most common root cause.

Vyper 2023 shows how compiler faults void source guards

The best-known loss from a compiler fault involved Vyper rather than Solidity. Versions 0.2.15, 0.2.16 and 0.3.0 allocated named reentrancy locks incorrectly and gave each function its own lock regardless of the key, which allowed cross-function reentrancy.

Attackers exploited multiple Curve pools compiled with the affected versions on July 30, 2023, and the ISSTA study estimates losses near $73.5 million.

GitHub classifies advisory CVE-2023-39363 under CWE-863, incorrect authorization. The fault sat in storage allocation, not in Solidity optimizer bugs, yet the source showed a guard and the bytecode did not enforce it.

Verification steps for audit and release teams

Source review cannot catch compiler defects, because the divergence appears only after compilation.

Differential testing exposes Solidity optimizer bugs by comparing behavior instead of source: run one test suite against bytecode built with the optimizer disabled and enabled and against the legacy and IR pipelines, comparing reverts, return data and final storage under the exact compiler settings of the deployment.

Workflow comparing builds with the optimizer on and off to detect divergence in access-control logic
Figure 4. Identical transactions on two builds expose behavior that source review cannot show

Teams tracking Solidity optimizer bugs should pin the compiler to 0.8.38 or later and read every bug list entry whose conditions name the optimizer or via-IR. Foundry’s linter flags modifiers which can finish without running the function body, and long modifier logic copied into every call site.

OpenZeppelin’s Ownable keeps the check in the internal function _checkOwner(), so the inlined modifier stays small. Sourcify and Etherscan recompile submitted source with recorded compiler settings, which lets reviewers confirm the optimizer configuration behind a bytecode.

Negative tests for every privileged function and every role verify the result: each unauthorized caller must revert, and each authorized caller must leave storage as the source states. Solidity optimizer bugs change bytecode, so only tests run against the deployed bytecode confirm the access rules.

Step by step

  1. Pin the compiler to 0.8.38 or later and read every bug list entry whose conditions name the optimizer or via-IR.
  2. Build the contract twice: optimizer disabled (or legacy pipeline) and the exact deployment settings.
  3. Run one test suite against both builds with identical transactions and identical state.
  4. Compare revert status, return data, final storage and logs; treat any mismatch as a compiler defect candidate.
  5. Add negative tests for every privileged function and role: unauthorized callers revert, authorized callers leave storage as the source states.

FAQ

What are Solidity optimizer bugs?

Solidity optimizer bugs are defects in the compiler passes that rewrite code to make it smaller or cheaper. A faulty pass can remove a storage write, reuse a stale value or change evaluation order, so bytecode behaves differently from the audited source.

Does SOL-2026-7 break access control in deployed contracts?

The advisory describes no access-control exploit and carries a low severity rating. It affects Solidity 0.8.19 through 0.8.37 with the Yul optimizer enabled, and Sourcify contracts recompiled with 0.8.38 showed no bytecode change, which suggests a very rare trigger.

Does the Solidity bug list contain a modifier reordering bug in the optimizer?

No. None of the 14 optimizer-conditioned entries describes a modifier running out of order. The nearest case, SOL-2026-3, sits in the analysis stage and reversed modifier resolution in Solidity 0.8.29 through 0.8.35 under a rare storage layout.

How can a team detect optimizer-induced divergence?

Run one test suite against builds with the optimizer disabled and enabled, and against the legacy and IR pipelines. Compare reverts, return data and final storage. Add negative tests for every privileged function and every role.

Can a compiler fault void a source-level security guard?

Yes. Vyper 0.2.15, 0.2.16 and 0.3.0 allocated named reentrancy locks incorrectly, which allowed cross-function reentrancy and led to the July 30, 2023 Curve pool exploits. GitHub classifies CVE-2023-39363 under CWE-863, incorrect authorization.