feat: add msg-value-in-nonpayable detector#2923
Conversation
Code Review: msg-value-in-nonpayable detectorThanks for implementing this detector! I've reviewed the changes against Slither's conventions and the project CLAUDE.md. Overall this is a well-structured implementation. Here are my findings: Critical Issues (90-100 confidence)1. Missing snapshot file (Confidence: 95)
Important Issues (80-89 confidence)2. Should use
3. Should check
4. Inconsistent
Suggestions (not blocking)5. Consider testing multiple Solidity versions
6. WIKI_DESCRIPTION could note the 0.8+ compiler behavior
7. Minor: Line length in
if isinstance(read, SolidityVariableComposed) and read.name == "msg.value":Positive Observations
SummaryThe detector implementation is solid and follows Slither patterns. The critical blocker is the missing snapshot file - tests will fail without it. The traversal pattern ( Once these issues are addressed, this looks ready for merge. |
Code Review - PR #2923: msg-value-in-nonpayable detectorSummaryI have reviewed this PR and made the following fixes to address the issues identified in the previous code review. Issues Fixed
Test Results
Verified BehaviorThe detector correctly:
Merge ReadinessThis PR is now ready for merge after these fixes. |
Implements crytic#2781. Detects uses of msg.value in functions that cannot be reached from any payable entry point. - Uses call graph analysis via all_reachable_from_functions - Properly formats output using Slither objects for JSON/SARIF - Includes test cases for internal function call chains - Limited to Solidity (LANGUAGE = "solidity") Note: Solidity 0.8+ prevents direct msg.value use in non-payable public/external functions at compile time. This detector catches internal functions that use msg.value but are only reachable from non-payable entry points.
e749f52 to
863217b
Compare
- Replace deprecated typing.List/Tuple with builtin list/tuple (ruff UP035/UP006) - Add from __future__ import annotations for PEP 604 support - Add missing test zip artifact and snapshot file
|
Thanks @ep0chzer0 and @dguido for taking forward the work from PR #2867, refining the detector and adding test coverage in #2923. Glad to see the final version merged ! |
Summary
Implements #2781. Adds a detector that identifies uses of
msg.valuein functions that cannot be reached from any payable entry point.Detection Logic
The detector:
msg.value(including via modifiers)all_reachable_from_functions) to find all entry pointsKey Features
LANGUAGE = "solidity")Note on Solidity 0.8+
Solidity 0.8+ prevents direct msg.value use in non-payable public/external functions at compile time. This detector primarily catches internal functions that use msg.value but are only reachable from non-payable entry points.
Example
Test Results
The detector correctly identifies:
_addBalance()- internal function only called from non-payablebad1()_helper()- internal function only called from non-payablebad2()via_middle()And correctly does NOT flag: