feat: add detectors for unused events and unused modifiers#2970
Open
ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
Open
feat: add detectors for unused events and unused modifiers#2970ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
Conversation
Add two new informational detectors to identify dead code: - `unused-events`: Detects events declared but never emitted anywhere in the compilation unit. Skips interface contracts and dependencies. - `unused-modifiers`: Detects modifiers declared but never applied to any function. Handles inheritance correctly by skipping virtual modifiers that are overridden in child contracts. Both detectors include comprehensive test contracts covering: - Basic unused/used elements - Inheritance chains (base events emitted by children) - Virtual modifier override patterns - Interface event declarations Closes crytic#2782 (partial - errors covered by crytic#2902)
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.
Summary
Adds two new informational detectors for comprehensive dead code detection, addressing #2782:
unused-events— Detects events declared but never emitted anywhere in the compilation unitunused-modifiers— Detects modifiers declared but never applied to any functionTogether with the unused custom errors detector in #2902, this completes the dead code detection coverage for errors, events, and modifiers requested in #2782.
Detection Logic
Unused Events
EventCallIR operations to build a set of emitted event namesUnused Modifiers
function.modifiersacross all derived contractsoverridden_byand manual inheritance chain check)Test Coverage
Unused Events (6 contracts):
NeverEmitted,AlsoNeverEmitted,OrphanEvent(in base contract)Unused Modifiers (5 contracts):
neverUsed,alsoNeverUsed,unusedVirtualMod(virtual but not overridden)Files Changed
slither/detectors/functions/unused_events.py— New detectorslither/detectors/functions/unused_modifiers.py— New detectorslither/detectors/all_detectors.py— Register both detectorstests/e2e/detectors/test_detectors.py— Add test entriestests/e2e/detectors/test_data/unused-events/— Test contracts and artifactstests/e2e/detectors/test_data/unused-modifiers/— Test contracts and artifactstests/e2e/detectors/snapshots/— Expected output snapshotsAll 383 detector tests pass (381 existing + 2 new).
Closes #2782 (events + modifiers; errors covered by #2902)