-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
Cmd-forge-lintCommand: forge lintCommand: forge lintT-featureType: featureType: featurefirst issueA good way to start contributingA good way to start contributing
Description
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.,
uint128
→uint64
,int256
→int8
,uint256
→int256
) - Non-numeric downcasts (e.g.,
bytes
→bytes32
)
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
grandizzy, 0xrusowsky, mablr and TropicalDog17
Metadata
Metadata
Assignees
Labels
Cmd-forge-lintCommand: forge lintCommand: forge lintT-featureType: featureType: featurefirst issueA good way to start contributingA good way to start contributing
Type
Projects
Status
Backlog