Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article summarizes the changes in Solidity 0.8.22, based on the official release announcement.
Changes
Solidity 0.8.22 introduces:
- Unchecked loop increments.
- Yul optimizer adjustments.
- JSON import support for EVM assembly.
- File-level event definitions.
Unchecked Loop Increments
Previously, developers used unchecked blocks around for-loop counter increments to avoid overflow checks and save gas.
for (uint i = 0; i < array.length;) {
acc += array[i];
unchecked { i++; } // i gets incremented without overflow checks -- less gas used
}This was verbose, so Solidity 0.8.22 automatically removes the increment check under specific conditions while keeping code simple.
- The loop condition has the form
i < ..., where i is the loop counter. - The type of the right-hand operand is implicitly convertible to the counter's type without changing the counter's type for the comparison.
- The counter uses a built-in Solidity integer type.
- The increment expression is i++ or ++i.
- The counter is not modified by the loop condition or body.
The following code qualifies for optimization.
for (uint i = 0; i < array.length; ++i) {
acc += array[i]; // i はループ本体で変更されません
}The following does not qualify because i is converted to uint16 for the comparison.
for (uint8 i = 0; i < uint16(1000); ++i) {
// ループ本体
}Additional constraints and configuration options apply.
- Only the built-in less-than operator is supported, not operators such as less-than-or-equal or user-defined overloads.
- The optimization is enabled even when other optimizer settings are disabled.
- To disable it, set settings.optimizer.details.simpleCounterForLoopUncheckedIncrement to false.
Yul Optimizer Adjustments
The PUSH0 opcode, supported since Solidity 0.8.20, pushes zero onto the stack at a low gas cost.
The Rematerialiser optimization step was extended to rematerialize zero literals rather than keeping variable references to them. The original article attributes this change to version 0.8.24 within its discussion of 0.8.22; consult the linked release announcement for the exact version history.
Rematerializing zero lets the compiler use PUSH0 instead of more expensive DUP instructions and reduces gas costs overall.
Previously a zero literal was stored in a variable and referenced using DUP. The new approach regenerates zero literals so that PUSH0 can be used.
Two steps were added to the default optimization sequence.
- Rematerialiser: rematerializes zero literals.
- UnusedPruner: removes unused variables.
JSON Import Support for EVM Assembly
Experimental EVM assembly import support allows external tools to optimize assembly before bytecode generation.
The intended workflow is:
- Export EVM assembly generated by the compiler.
- Modify the exported assembly using external tools.
- Reimport the modified assembly and resume normal compilation.
The feature is experimental and was not recommended for production use at the time of release.
File-level Event Definitions
Events may now be defined at file scope. This makes code easier to organize without placing events inside libraries merely to share their definitions.
The update allows events to be declared outside contracts and emitted from them.
event E(); // ファイルレベルでのイベント定義
contract D {
function f() public {
emit E(); // ファイルレベルで定義されたイベントの発行
}
}Solidity 0.8.21 had a bug causing an error during NatSpec generation when events defined in other contracts or interfaces were emitted. The bug was fixed so that external events could be emitted correctly.
NatSpec is Solidity's standard documentation format, using comments to describe contracts and functions and generate documentation. Emitting events defined in other contracts or interfaces previously could compile successfully while producing an internal error during NatSpec generation.
interface I {
event ForeignEvent(); // インターフェースで定義されたイベント
}
contract C {
event ForeignEvent(); // コントラクトで定義されたイベント
}
contract D {
function f() public {
emit I.ForeignEvent(); // インターフェースで定義されたイベントの発行
emit C.ForeignEvent(); // コントラクトで定義されたイベントの発行
emit E(); // ファイルレベルで定義されたイベントの発行
}
}Other Changes
For additional fixes, see the official release announcement.
Conclusion
Solidity 0.8.22 improves loop increment efficiency, the Yul optimizer, assembly tooling, and event organization.
Further reading and author links:





