Skip to content

feat(lint): add protected-vars - #15766

Merged
mablr merged 6 commits into
foundry-rs:masterfrom
mattsse:mattsse/protected-vars-lint
Jul 22, 2026
Merged

feat(lint): add protected-vars#15766
mablr merged 6 commits into
foundry-rs:masterfrom
mattsse:mattsse/protected-vars-lint

Conversation

@mattsse

@mattsse mattsse commented Jul 15, 2026

Copy link
Copy Markdown
Member

This adds the high-severity protected-vars lint from #14381. It enforces Solidity's @custom:security write-protection annotations by tracing writes from externally callable leaf-contract entry points through reachable modifier continuations, resolved internal and library calls, storage aliases, returned storage locations, collection mutations, and resolvable assembly slots.

Protection is tracked as must-flow state at each write, so a guard must dominate that occurrence across branches, short-circuit expressions, loops, returns, and modifier expansion. The analysis also retargets Yul storage-pointer .slot assignments, distinguishes persistent sstore from transient tstore, and uses resolved Yul return summaries without contaminating results with unrelated argument roots. Exact overload signatures and virtual dispatch remain respected, while malformed or unresolved annotations stay unsatisfied.

The companion Book documentation is in foundry-rs/book#1982, with the dominance and Yul follow-up in foundry-rs/book#1995. This PR was implemented with Codex assistance across code, tests, and lint documentation, then independently reviewed and corrected by a fresh Codex context.

mattsse added 2 commits July 15, 2026 16:50
Honor @Custom:security write-protection annotations across inherited entry points, modifiers, and resolved internal call paths.

Report externally callable writes when the exact annotated function or modifier is not reachable.
Resolve typed calls and most-derived overrides, propagate storage aliases through control flow and assembly, and fail closed on invalid protections.
Comment thread crates/lint/src/sol/high/protected_vars.rs Outdated
Comment thread crates/lint/src/sol/high/protected_vars.rs Outdated
Comment thread crates/lint/src/sol/high/protected_vars.rs
Comment thread crates/lint/src/sol/high/protected_vars.rs Outdated
Comment thread crates/lint/src/sol/high/protected_vars.rs
Require protection calls to dominate every protected write and model modifier continuations at reachable placeholders. Correct Yul storage-pointer retargeting, persistent storage writes, and resolved call-return roots.
Comment thread crates/lint/src/sol/high/protected_vars.rs Outdated
Merge only reachable continuing try clauses and exhaustive switch arms so synthetic skip paths do not invalidate dominating guards or storage-pointer retargeting.
@mattsse
mattsse requested a review from mablr July 16, 2026 20:10
Comment thread crates/lint/src/sol/high/protected_vars.rs Outdated
Track normal completion across helper calls, recursive summaries, loop exits, and modifier continuations so unreachable protected writes are not reported.
@mablr
mablr self-requested a review July 17, 2026 15:48
Comment thread crates/lint/src/sol/high/protected_vars.rs
Keep each Yul tuple output's storage roots separate when binding declarations and assignments. This avoids attributing writes through an ordinary returned slot to unrelated protected outputs.

Amp-Thread-ID: https://ampcode.com/threads/T-019f896c-fd1a-745b-be37-de6016df1dbb
Co-authored-by: Amp <amp@ampcode.com>

@mablr mablr left a comment

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.

LGTM

@mablr
mablr enabled auto-merge (squash) July 22, 2026 11:54
@mablr
mablr merged commit 9c35aea into foundry-rs:master Jul 22, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Foundry Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants