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 covers the changes introduced in Solidity 0.8.31, based on the official release announcement below.

Changes

Solidity 0.8.31 adds support for Ethereum's upcoming Fusaka network upgrade, extends storage layout functionality, and improves the release process.

The main changes are:

  • Fusaka support (osaka by Default, CLZ opcode)
  • Support for constants in storage layout specifiers
  • New deprecation warnings (features scheduled for removal in 0.9.0)
  • Release process changes (ARM Linux support, prereleases, and removal of PPAs)

Fusaka support

osaka by Default

With Fusaka scheduled for mainnet deployment, the compiler's default EVM target has changed to osaka. Unless --evm-version or settings.evmVersion is specified explicitly, compilation now uses Fusaka features automatically. Older EVM versions can still be selected.

CLZ opcode

Solidity 0.8.31 adds support for the CLZ (Count Leading Zeros) opcode introduced by EIP-7939.

This opcode counts the consecutive zero bits at the beginning of a 256-bit word.

Consider the following value.

text
0x0000000000000000000000000000000000000000000000000000000000000010

In this example, the original article gives the count as 252 leading zero bits (10 is 0001 0000, so the first three bits are zero).

CLZ is useful in bit manipulation, compression algorithms, and certain data structures. At present, the compiler has limited opportunities to use this opcode internally, but its use in future optimizations is being considered.

At the application level, the benefits are more substantial. The following libraries already provide their own implementations, which could potentially be replaced more efficiently using the CLZ opcode:

  • Libraries such as solady
  • OpenZeppelin's Math.clz()

Usage in Yul

The CLZ opcode is available as a built-in Yul function:

solidity
assembly {
    let leadingZeros := clz(x)
}

clz(x) returns the number of consecutive leading zero bits in the 256-bit word x.

Support for constants in storage layout specifiers

Solidity 0.8.31 allows constant variables to be used in base slot expressions in storage layout specifiers. This makes storage placement more flexible and easier to read.

Example

solidity
uint constant OFFSET = 0x10 + 1;

contract C layout at 0xAAAA + OFFSET {
    uint[3] x; // スロット 0xAABB..0xAABD を占有
}

The constant OFFSET can now be used to calculate the base slot.

Limitations

Solidity's compile-time expression evaluation is still evolving, and there are clear restrictions on the expressions it can handle. These restrictions matter when calculating the base slot of a storage layout or writing an initializer for a constant.

Compile-time evaluation handles only arithmetic expressions using rational number literals

Solidity's compile-time evaluation can evaluate only arithmetic expressions using rational number literals.

A rational number literal here refers to a numeric value written directly in source code, such as:

  • 10
  • 3.5
  • 1_000
  • 0x20

An arithmetic expression using rational number literals is a simple expression combining those values with operators such as +, -, *, and /.

solidity
// OK: すべて有理数リテラルのみを使用
uint constant A = 10 + 5;
uint constant B = 3 * (2 + 7);
uint constant C = 1000 - 250;

Solidity can safely evaluate expressions of this form at compile time.

Types of expressions not permitted in compile-time evaluation

Expressions composed entirely of rational number literals are accepted, but expressions containing other elements fall outside the scope of compile-time evaluation and cause compilation errors.

Expressions containing explicit type conversions

An explicit type conversion, or cast, converts a value to a specific type, as in uint256(x).

solidity
uint8 x = 10;

// NG: 型変換が混ざるとコンパイル時計算は不可
uint constant BAD = uint256(x) + 1;

Compile-time arithmetic uses arbitrary precision, while integer types have finite bit widths. There is currently no mechanism for safely evaluating expressions containing such type conversions in this context, so compilation fails.

Use of certain built-in functions

Built-in functions are special functions provided by Solidity or the compiler. These include functions that return type information or retrieve internal data.

At this stage of compile-time evaluation, expressions containing function calls are outside the scope of evaluation.

solidity
// NG の例(説明用)
uint constant BAD = someBuiltin(10) + 3;

However simple a function may appear, the presence of a function call prevents compile-time evaluation.

Use of the ternary operator

The ternary operator selects one of two values according to a condition:

text
条件 ? 値1 : 値2

Even if the condition is known at compile time, the expression is treated as containing a branch and cannot be evaluated in this context.

solidity
// NG: 条件が定数でも三項演算子が含まれている時点で評価不可
uint constant BAD = (true ? 1 : 2) + 5;

The restrictions also apply to constant initializers

This update allows a constant to appear in a storage layout's base slot expression, but the expression assigned to that constant is subject to the same restrictions.

  • Using a complex expression in a constant initializer results in a compilation error.
  • A storage layout specifier using that constant is subject to the same restrictions.

Planned improvements

Future releases are expected to:

  • Broaden the range of expressions supported by compile-time evaluation.
  • Add dedicated built-in functions to handle common expressions safely.

More flexible compile-time evaluation requires a new evaluation system beyond the current simplified mechanism, so support is expected to expand gradually.

Deprecated features (scheduled for removal in 0.9.0)

Solidity 0.9.0 is planned to remove older features to streamline the compiler. Starting in 0.8.31, deprecation warnings are emitted for features scheduled for removal.

Removal of <address>.send() and <address>.transfer()

These functions were originally introduced for simple Ether transfers. They restricted gas to 2300 so that the recipient contract could not execute complex operations.

At the time, this 2300 gas allowance was just enough for:

  • Reading storage
  • Emitting events

However, writes and recursive calls were considered impossible.

This design had a significant problem:

  • The assumption that opcode gas costs would remain constant no longer held.
  • Changes to gas costs, such as those introduced by EIP-150, created cases where 2300 gas was insufficient.

For more on EIP-150, see the following article.

Using send() and transfer() is therefore widely regarded as an antipattern today. The recommended alternative is <address>.call() with an empty payload.

solidity
// 推奨される方法
(bool success, ) = recipient.call{value: amount}("");
require(success, "Transfer failed");

However, call() does not impose a gas limit by default, so it does not provide protection against reentrancy attacks.

One of the following safeguards is therefore needed:

  • Implement a reentrancy guard using transient storage.
  • Structure the code using the Checks-Effects-Interactions pattern.

An EVM-level solution such as EIP-5920: PAY opcode could be introduced in the future and might then be exposed as <address>.pay().

Removal of ABI Coder V1

ABI Coder v2 was introduced as an experimental feature in Solidity 0.4.19.

Initially, it had to be enabled explicitly with an experimental pragma. It was considered stable during the 0.7 release cycle and became the default in 0.8.0.

Advantages of ABI Coder v2

ABI Coder v2 is a full superset of v1 and adds the following capabilities:

  • Support for structs
  • Support for arbitrarily nested arrays
  • Stricter input validation

Why v1 is being removed

ABI Coder v1 is obsolete for the following reasons:

  • The IR pipeline (intermediate representation pipeline) requires v2.
  • v1 is available only in the legacy evmasm pipeline.
  • Compilation with --via-ir always uses v2, regardless of the pragma.
  • v2 was implemented in Yul from the beginning and works in both pipelines.

ABI Coder v1 is therefore scheduled for removal in 0.9.0.

Removal of virtual modifiers

Like functions, modifiers in Solidity can be declared virtual and overridden in derived contracts.

solidity
contract Base {
    modifier onlyOwner() virtual {
        require(msg.sender == owner, "Not owner");
        _;
    }
}

contract Derived is Base {
    modifier onlyOwner() override {
        require(msg.sender == admin, "Not admin");
        _;
    }
}

However, this feature is being removed for the following reasons:

  • It can easily cause unexpected behavior for users.
  • It creates complex corner cases in the compiler implementation.
  • Inheritance is already a major source of language complexity, and removing nonessential features reduces that complexity.

Calling virtual functions from within a modifier will remain supported.

solidity
modifier onlyOwner() {
    require(isOwner(), "Not owner"); // isOwner()は仮想関数でOK
    _;
}

Removal of contract comparison operators

A variable of a Contract type in Solidity is internally treated as a wrapper around an address. Historically, most operations permitted on addresses could therefore also be applied directly to contract types.

Until Solidity 0.5.0, all members of address types were available on Contract types as well, and there was little distinction between how the two were treated.

As the language evolved, address types and Contract types came to be treated as distinct concepts. Their capabilities and behavior were gradually separated, but comparison operators remained an exception.

Problems with comparisons on Contract types

In current Solidity, comparisons using operators such as < and > can be written directly on a Contract type.

solidity
contract A {}
contract B {}

A a;
B b;

bool result = a < b; // これは何を比較している?

At first glance, this may look as though it compares some property of the contracts themselves. In reality, it simply compares their underlying address values.

However, a Contract type is also used syntactically in a way that resembles a struct. A reader could mistakenly think the comparison concerns the contents of the contracts. This ambiguity was considered a problem in the language specification.

Explicit address conversion required from 0.9.0

To avoid this confusion, Solidity 0.9.0 will remove comparison operators on Contract types. Comparisons will require explicit conversion using address().

solidity
bool result = address(a) < address(b); // これなら「アドレスを比較している」と明確

This has several benefits:

  • It makes clear what is being compared.
  • It clarifies the distinction between Contract and address types.
  • It avoids misunderstandings and makes the code easier to read and its intent clearer.

Removal of the special memory-safe-assembly comment

Inline assembly can use memory in ways that are incompatible with Solidity's memory model. As a result, certain memory optimizations are globally disabled if an assembly block accesses memory or assigns to Solidity variables stored in memory. To avoid this, programmers can declare an assembly block to be entirely memory-safe.

solidity
assembly ("memory-safe") {
    ...
}

A special NatSpec comment was also provided as a temporary backward-compatible mechanism for use with compiler versions predating this feature.

solidity
/// @solidity memory-safe-assembly
assembly {
    ...
}

Because Solidity 0.9.0 breaks backward compatibility, this alternative mechanism is no longer needed and will be removed.

Release process changes

Solidity 0.8.31 also brings several improvements to the release process.

Linux ARM support

Starting with this release, official Linux binaries are available for the ARM architecture.

This benefits:

  • Developers who use Linux as their primary operating system on ARM hardware.
  • Users who run the compiler in Linux containers (such as Docker) on ARM hardware.

ARM support itself is not new.

  • Binaries were already available for ARM-based Macs.
  • It was already possible to build from source on Linux.

The important change is that official binaries are now integrated into the CI and release infrastructure.

This offers the following benefits:

  • Binaries are provided from the same source as on other platforms.
  • They go through the complete testing process.
  • The generated bytecode and metadata are verified to be identical across all platforms.

Introduction of prereleases

Previously, Solidity provided only two types of builds:

  • Official releases
  • Nightly builds (development builds)

To share experimental features earlier, prereleases were introduced as a lighter-weight process. The original article dates the publication of v0.8.31-pre.1 to October 2024; some of the features included in this release, such as CLZ opcode support, were already available in that prerelease.

Removal of PPA releases

The Solidity compiler distributes binaries through multiple channels, and there are plans to retire those that are rarely used. Starting with this release, the Ubuntu PPA (Personal Package Archive) has officially been discontinued as a binary distribution channel. Docker releases are scheduled to continue for at least one more release, but may also be discontinued if usage remains low.

Docker releases have moved from Docker Hub to GitHub's container registry, where new binaries will also be published.

Other changes

Solidity 0.8.31 includes several additional features and bug fixes.

Compiler features

Change the default EVM version to osaka

As discussed above, the default EVM version has changed to osaka.

ethdebug: experimental support for instructions and source locations in EOF

Experimental support has been added for emitting instruction and source location information for EOF (EVM Object Format) in the ethdebug format. This makes it easier to develop future EOF-based debugging tools.

Bug fixes

Fix a type width issue in subassembly ID assignment

IDs assigned to subassemblies nested two or more levels deep did not use fixed-width types. This caused inconsistent --asm-json output across target architectures. The issue has been fixed.

Fix invalid Yul code generated by ExpressionSimplifier

An edge case in which the Yul optimizer's ExpressionSimplifier substituted expressions containing out-of-scope variables and generated invalid Yul code has been fixed.

Build system changes

Test and release support for Linux arm64 binaries

As noted earlier, ARM Linux binaries have been integrated into the testing and release process.

Updated minimum version requirements

The minimum versions of the following toolchain components have been updated:

  • Boost: 1.83.0 (non-Windows environments)
  • GCC: 13.3
  • Clang: 18.1.3

This resolves an infinite recursion problem during boost::rational comparisons when using GCC versions below 14 together with Boost versions below 1.75.

Conclusion

This article covered the changes in Solidity 0.8.31.

I also publish on the following platforms. Feel free to explore them for other articles.

https://chaldene.net/