Fix incorrect-modifier false positive on revert("msg") and custom-error reverts#3035
Open
MarkLee131 wants to merge 2 commits into
Open
Fix incorrect-modifier false positive on revert("msg") and custom-error reverts#3035MarkLee131 wants to merge 2 commits into
MarkLee131 wants to merge 2 commits into
Conversation
…or reverts
is_revert checked ir.function.name in ["revert()", "revert(string"], where
the second literal is missing the closing paren. The real SolidityFunction
name for revert("msg") is "revert(string)" (see solidity_variables.py:55),
so the membership check never matched. Custom-error reverts are also missed
because SolidityCustomRevert builds its name as "revert " + signature.
Switch to explicit checks for "revert()" and "revert(string)" plus a
startswith("revert ") branch that covers any SolidityCustomRevert.name.
Adds tests/e2e/detectors/test_data/incorrect-modifier/0.8.20/modifier_revert_variants.sol
covering revert(), revert("msg"), revert MyError(), revert MyError(args)
and one negative case that should still fire.
Generated via: python tests/e2e/detectors/test_detectors.py --compile pytest -k ModifierDefaultDetection-0.8.20-modifier_revert_variants --insta update All 5 ModifierDefaultDetection test cases (0.4.25, 0.5.16, 0.6.11, 0.7.6, 0.8.20) pass with the fix applied.
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
Fixes #3034:
incorrect-modifierwas flagging modifiers ending inrevert("msg")orrevert MyError()as "does not always execute_;or revert."Root Cause
is_revertinslither/detectors/functions/modifier.py:"revert(string"is missing the closing paren. The actualSolidityFunction.nameforrevert("msg")is"revert(string)"(seesolidity_variables.py:55), so the membership check never matches.Custom-error reverts are represented by
SolidityCustomRevertwithname = "revert " + signature. Also not in the kill set, sorevert MyError()is missed too.Fix
startswith("revert ")(trailing space) covers anySolidityCustomRevert.name, since they're all built as"revert " + signature.Tests
Added
tests/e2e/detectors/test_data/incorrect-modifier/0.8.20/modifier_revert_variants.sol. Coversrevert(),revert("msg"),revert MyError(),revert MyError(args), plus one negative case that should still fire. After the fix only the negative case is reported.The existing
modifier_default.solfixture (0.4.25 / 0.5.16 / 0.6.11 / 0.7.6) only uses barerevert(), which still matches exactly. Existing assertions unchanged.