Add detector for unused custom error definitions#2902
Add detector for unused custom error definitions#2902ep0chzer0 wants to merge 5 commits intocrytic:masterfrom
Conversation
80e1b7b to
204452f
Compare
|
Hi maintainers, could someone please approve the CI workflow runs when you get a chance? This PR is ready for review. Thanks! |
|
Note: I noticed there's an existing PR #2565 for similar functionality. However, this PR addresses the review feedback given on #2565:
Happy to close this if maintainers prefer to continue with #2565, or this could serve as an alternative implementation addressing the review concerns. |
43e7743 to
4ab2e28
Compare
4ab2e28 to
2bd1306
Compare
Implements a new detector (unused-error) that identifies custom error definitions that are declared but never used in revert statements. Features: - Detects unused contract-level custom errors - Detects unused top-level custom errors - Handles errors with and without parameters - Skips interface contracts (signature-only) Fixes crytic#2587
2bd1306 to
2a8ebe0
Compare
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)
Summary
Implements a new detector (
unused-error) that identifies custom error definitions that are declared but never used inrevertstatements.Fixes #2587
Features
Example
The detector will report:
Unauthorized is declared but never used in VendingMachineTest
Added test case in
tests/e2e/detectors/test_data/unused-error/0.8.4/unused_custom_error.solcovering:Checklist
all_detectors.py🤖 Generated with Claude Code