Skip to content

feat(lint): add reentrancy-unlimited-gas#15768

Open
mattsse wants to merge 6 commits into
foundry-rs:masterfrom
mattsse:mattsse/reentrancy-unlimited-gas-lint
Open

feat(lint): add reentrancy-unlimited-gas#15768
mattsse wants to merge 6 commits into
foundry-rs:masterfrom
mattsse:mattsse/reentrancy-unlimited-gas-lint

Conversation

@mattsse

@mattsse mattsse commented Jul 15, 2026

Copy link
Copy Markdown
Member

This adds the info-severity reentrancy-unlimited-gas lint from #14381. It reports Solidity's built-in transfer and send when a persistent state write or event emission remains reachable after a successful interaction, without treating the fixed stipend as a reentrancy boundary.

The flow analysis resolves builtins semantically and follows helpers, modifiers, inheritance, branches, loops, storage aliases, and Yul effects. Stored send results are tracked as must-facts across assignments and joins, invalidated by overwrites and repeated static spans, and used to prune failed-only paths. Rollback-only siblings, non-returning paths, and failed sends do not report; do-while continue transitions and Yul sstore, tstore, logs, switches, helpers, and loop posts are modeled explicitly. Fresh-context reviews added regressions for every corrected path and found no remaining issues.

The user documentation is in foundry-rs/book#1983, with the review-aligned flow follow-up in foundry-rs/book#1996.

Prepared with assistance from OpenAI Codex.

Comment thread crates/lint/src/sol/high/reentrancy.rs Outdated
"state read before external call is written after the call"
);

declare_forge_lint!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

solc 0.8.31 already warns on every built-in send/transfer and recommends call, so this duplicates a recent compiler diagnostic while adding flow-analysis false positives. per #14381, can we omit this detector?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I kept the detector because #14381 explicitly tracks it and Foundry linting also serves projects on older compiler versions or with compiler diagnostics configured differently. The reviewed implementation is path-aware and now excludes failed sends, rollback-only effects, and other false-positive shapes. I am leaving this policy thread open for maintainer preference.

Comment thread crates/lint/src/sol/high/reentrancy.rs
Comment thread crates/lint/src/sol/high/reentrancy.rs
Comment thread crates/lint/src/sol/high/reentrancy.rs
mattsse added 3 commits July 16, 2026 17:17
Detect resolved transfer and send builtins followed by reachable state writes or event emissions. Reuse the existing reentrancy path analysis while excluding custom same-named contract members.
Resolve transfer and send through Solar's exact builtins and conservatively follow reachable effects through expressions, internal calls, storage aliases, modifiers, and loop backedges. Exclude failed-send and non-returning continuations, and preserve existing reentrancy lint behavior.
Track stored send outcomes through control flow while invalidating overwritten results. Model do-while and Yul loop transitions, preserve successful halt effects, discard rollback-only unordered paths, and recognize Yul storage and log effects.
@mattsse
mattsse force-pushed the mattsse/reentrancy-unlimited-gas-lint branch from 1a1ab01 to 915e068 Compare July 16, 2026 16:19
Comment thread crates/lint/src/sol/high/reentrancy.rs Outdated
Comment thread crates/lint/src/sol/high/reentrancy.rs
Track tuple slots and internal helper return sources so failed-only send paths are pruned without hiding success or unknown-path reentrancy warnings.
@mattsse
mattsse requested a review from mablr July 16, 2026 20:25
Comment thread crates/lint/src/sol/high/reentrancy.rs Outdated
Align tuple assignment structure recursively and apply result writes in Solidity order. Preserve holes, sibling isolation, stale-source clearing, and duplicate-variable overwrite semantics.
@mattsse
mattsse requested a review from mablr July 16, 2026 23:06
Comment thread crates/lint/src/sol/high/reentrancy.rs
Keep send success correlated through composed boolean expressions so failure-only branches do not produce reentrancy warnings.
@mablr
mablr self-requested a review July 17, 2026 15:48
{
candidate_state.set_stored_call_results(expr.span, &return_sources);
returned_state.merge(&candidate_state);
any_returns = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Send-result correlation is lost when passed into an internal helper: bool ok = recipient.send(1); failedOnly(ok), with if (!ok) counter = 1, warns even though the write is failure-only. Please bind actual send-result sources to the callee parameters and retain a success-path control.

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.

4 participants