Skip to content

feat(forge-lint): add UnsafeTypecast lint #11029

@0xClandestine

Description

@0xClandestine

Component

Forge

Describe the feature you would like

I'd like to propose a new lint rule called UnsafeTypecast for forge lint. This rule should flag any downcast or semantically unsafe typecast as unsafe by default.

This includes:

  • Numeric downcasts (e.g., uint128uint64, int256int8, uint256int256)
  • Non-numeric downcasts (e.g., bytesbytes32)

These casts can lead to data loss, overflow, or incorrect interpretation and should always be treated with caution.

The expected usage is that developers disable the lint explicitly using // forge-lint: disable-next-line(UnsafeTypecast), and include a separate explanatory comment justifying why the cast is safe.

For example:

if (a > type(uint32).max) revert TypecastOverflow();

// ...

// forge-lint: disable-next-line(UnsafeTypecast)
uint32 b = uint32(a); // We ensure `a` can fit in 32 bits above.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions