Skip to content

fix: classify using-for library calls as internal (#2073)#3010

Open
MycCellium420 wants to merge 2 commits intocrytic:masterfrom
MycCellium420:fix/false-positive-external-calls-dot
Open

fix: classify using-for library calls as internal (#2073)#3010
MycCellium420 wants to merge 2 commits intocrytic:masterfrom
MycCellium420:fix/false-positive-external-calls-dot

Conversation

@MycCellium420
Copy link
Copy Markdown

@MycCellium420 MycCellium420 commented Apr 19, 2026

Summary

Fixes #2073

addr.sendValue(amount) via using Address for address was incorrectly reported as an external call in the function-summary printer. Root cause: classify_calls ran during analyze_expressionsbefore _analyze_using_for had parsed the using … for directives.

Changes

slither/visitors/expression/call_classification.py

  • New _is_using_for_library_call() helper checks if a variable's type has a matching library function via using for
  • classify_calls() gains an optional using_for parameter

slither/solc_parsing/slither_compilation_unit_solc.py

  • Re-classifies node calls at the end of _analyze_using_for, after directives are available

slither/solc_parsing/cfg/node.py

  • Comment update only (initial classification still runs without using-for)

tests/unit/core/test_external_calls_classification.py

  • 16 new unit tests (mock-based, no compiler needed)

Verified with real Solidity (solc 0.8.24)

using Address for address payable;
using SafeMath for uint256;

function testUsingFor(address payable r) external { r.sendValue(1 ether); }
function testUsingForUint(uint256 a, uint256 b) external pure { return a.add(b); }
function testExternal(address to, uint256 amt) external { token.transfer(to, amt); }
Function Before After
r.sendValue() (using-for) external (false positive) internal
a.add(b) (using-for) external (false positive) internal
token.transfer() (real) external external

Test plan

  • 16/16 unit tests pass (TestClassifyCalls + TestUsingForClassification)
  • slither test.sol --print function-summary verified with solc 0.8.24 on Linux
  • abi.encode, direct library calls, this.foo() all still classified correctly

🤖 Generated with Claude Code

Add TestClassifyCalls covering the false-positive cases reported in crytic#2073:
- abi.encode() and other SolidityVariable member calls → internal
- direct library calls (MyLib.foo()) → internal
- this.foo() → external
- state/local variable member calls → external
- is_external_identifier predicate override
- empty list and mixed-call scenarios

Tests run without a Solidity compiler, using mock Expression objects
so they are fast and environment-independent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MycCellium420 MycCellium420 requested a review from smonicas as a code owner April 19, 2026 20:29
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 19, 2026

CLA assistant check
All committers have signed the CLA.

`addr.sendValue(amount)` via `using Address for address` was
incorrectly reported as an external call in the function-summary
printer because classify_calls ran before using-for directives were
parsed.

Changes:
- Add `_is_using_for_library_call` helper that checks whether a
  variable's type has a matching library function in the using-for map
- Add optional `using_for` parameter to `classify_calls`
- Re-classify calls in `_analyze_using_for` after directives are
  available, fixing the timing issue
- Add 16 unit tests covering all classification scenarios

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MycCellium420 MycCellium420 force-pushed the fix/false-positive-external-calls-dot branch from 19f9ed0 to 28fabd4 Compare April 20, 2026 08:16
@MycCellium420 MycCellium420 changed the title test: add unit tests for classify_calls (issue #2073) fix: classify using-for library calls as internal (#2073) Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: all statements with . are reported as external calls

2 participants