Skip to content

Adding support for CLZ opcode (upcoming Osaka hardfork) #2822

@Syzygy106

Description

@Syzygy106

Describe the desired feature

Motivation

While auditing the Ekubo codebase, I noticed that Slither does not currently handle the new Yul builtin clz, which maps to the opcode introduced in the upcoming Osaka hardfork.

Since clz is being added specifically to support more accurate and efficient implementations of common mathematical models — such as MSB/log2 computations, normalization routines, and other bit-level operations — its semantics matter for correctness. The fact that clz(0) = 256 in particular can affect a number of invariants these patterns rely on.

Because Slither cannot yet interpret clz, there is a possibility that certain issues may go undetected, especially in codebases that adopt Osaka-related arithmetic patterns.

These include arithmetic mistakes around the 256 edge case, unsafe narrowing of the clz result, and logic that still assumes legacy MSB implementations.

Proposal

Add support for parsing and evaluating the clz Yul builtin so that Slither can:

understand expressions that make use of clz in Yul or inline assembly,

take its semantics and edge cases into account,

and enable detectors that catch arithmetic issues, invalid casts, and other correctness problems related to clz.

This would help Slither provide accurate analysis for projects targeting Osaka and beginning to rely on the new opcode.

I also have some preliminary work prepared. If the maintainers agree that this feature would be valuable, I’d be happy to implement it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions