feat(lint): add mapping-deletion detector#15202
Merged
Merged
Conversation
Addresses foundry-rs#14381. delete on a value whose type contains a mapping zeroes the non-mapping members but cannot clear the mapping entries, leaving stale storage. Flags delete on a struct or array that reaches a mapping directly or through a nested struct or array.
figtracer
previously approved these changes
Jun 18, 2026
mablr
reviewed
Jun 20, 2026
mablr
left a comment
Member
There was a problem hiding this comment.
LGTM.
Don't forget to add lint to the Medium Severity list in crates/lint/README.md.
Contributor
Author
|
Added to the Medium severity list in the README. |
figtracer
reviewed
Jun 22, 2026
Add a self-referential struct (Tree with a Tree[] children field and a balances mapping) plus delete root, so the recursion guard in ty_contains_mapping stays covered.
stevencartavia
left a comment
Member
There was a problem hiding this comment.
it has another conflict :c
stevencartavia
approved these changes
Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Adds the
mapping-deletiondetector from theforge lintparity checklist in #14381.deleteon a value whose type contains amappingzeroes the non-mapping members but cannot enumerate the mapping's keys, so its entries are silently left in storage. The value looks reset while stale balances or flags remain reachable, which is a common accounting and access-control bug.solcdoes not warn on it.Solution
A
LateLintPass(med,mapping-deletion) that flagsdelete <expr>when the operand's type reaches amapping, directly or through a nested struct or array. It walks the semantic type (Mappingshort-circuits;Array/DynArray/Slicerecurse into the element;Structrecurses into the fields) with aseenguard against recursive struct definitions.This catches
delete s,delete nested,delete arr,delete m[id], anddelete arr[i], while leaving plain structs, scalar members, and single mapping-entry deletes (delete plainMap[k]) untouched.Test
crates/lint/testdata/MappingDeletion.solcovers the five triggering shapes (direct struct, nested struct, array of structs, mapping value, array element) and three non-triggering ones (plain struct, scalar member, plain mapping entry), with the blessed.stderr.cargo test -p forge --test uipasses.