Skip to content

feat(lint): add missing-zero-check#14460

Open
stevencartavia wants to merge 6 commits intomasterfrom
steven/missing-zero-check-lint
Open

feat(lint): add missing-zero-check#14460
stevencartavia wants to merge 6 commits intomasterfrom
steven/missing-zero-check-lint

Conversation

@stevencartavia
Copy link
Copy Markdown
Collaborator

Adds a missing-zero-check lint that flags address parameters of externally-callable functions and constructors used in state writes or value transfers (call/delegatecall/staticcall/transfer/send) without a prior require/assert/if check.

Testing

cargo run -p forge -- lint crates/lint/testdata/MissingZeroCheck.sol

Comment thread crates/lint/src/sol/info/missing_zero_check.rs Outdated
Comment thread crates/lint/src/sol/info/missing_zero_check.rs
Comment on lines +193 to +201
StmtKind::If(cond, then, else_) => {
self.guard_depth += 1;
let _ = self.visit_expr(cond);
self.guard_depth -= 1;
let _ = self.visit_stmt(then);
if let Some(e) = else_ {
let _ = self.visit_stmt(e);
}
return ControlFlow::Continue(());
Copy link
Copy Markdown
Collaborator

@mablr mablr Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard is not path sensitive, idk if there's a simple way to fix it, at least we should document this limitation.

This should trigger a warning, but it doesn't

function guardOnOneBranch(address a, bool flag) external {
    if (flag) {
        require(a != address(0)); // only guards when flag==true
    }
    owner = a; // sink reachable unchecked when flag==false
}

Copy link
Copy Markdown
Collaborator

@mablr mablr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants