Skip to content

Conversation

@ep0chzer0
Copy link
Contributor

Summary

  • Fixes bug where library functions used via using X for Y syntax were incorrectly reported as dead code
  • Corrects type annotation and indexing error in dead-code detector

Details

The dead-code detector had a bug in how it tracked library function usage:

# Before (incorrect):
all_libs_called: list[tuple[Contract, Function]] = [
    item.function for sublist in all_libss_called for item in sublist
]
functions_used |= {
    lib[1].canonical_name for lib in all_libs_called if isinstance(lib, tuple)
}

# After (correct):
all_libs_called: list[Function] = [
    item.function for sublist in all_libss_called for item in sublist
]
functions_used |= {
    f.canonical_name for f in all_libs_called if isinstance(f, Function)
}

The issue was that all_library_calls() returns LibraryCall objects, and item.function extracts a Function object, not a tuple. The code was trying to index lib[1] on a Function object, which would fail.

Test plan

  • Added test case with library using using X for Y syntax
  • Test includes both used and unused library functions to verify correct detection

Fixes #1265

🤖 Generated with Claude Code

@ep0chzer0 ep0chzer0 requested a review from smonicas as a code owner January 16, 2026 11:14
@ep0chzer0
Copy link
Contributor Author

Hello maintainers! This fixes a bug in the dead-code detector where library functions used via using X for Y syntax were incorrectly flagged as dead code. The fix corrects a type annotation and indexing error. Could you please approve the CI workflows to run? Thank you!

@ep0chzer0 ep0chzer0 force-pushed the fix/dead-code-library-functions branch 3 times, most recently from 77acffb to b9d344c Compare January 16, 2026 23:27
@dguido
Copy link
Member

dguido commented Jan 20, 2026

Bulk PR Review Summary

Research Findings

  • Issue Fixed: [Bug]: Slither incorrectly reports internal library function as unused #1265 - Dead-code detector incorrectly flags library functions as unused when used via using X for Y syntax
  • Root Cause: Type annotation mismatch where all_libs_called was annotated as list[tuple[Contract, Function]] but actually contained Function objects, causing isinstance(lib, tuple) to always be False

Code Review

The fix is correct:

# Before (broken):
all_libs_called: list[tuple[Contract, Function]] = [...]
functions_used |= {lib[1].canonical_name for lib in all_libs_called if isinstance(lib, tuple)}

# After (fixed):
all_libs_called: list[Function] = [...]
functions_used |= {f.canonical_name for f in all_libs_called if isinstance(f, Function)}

Test Status

  • ✅ Merged with master (no conflicts)
  • ✅ Dead-code detector tests pass (2/2)
  • ✅ Linting passes
  • ✅ Snapshot file confirms no false positives for library functions

Merge Readiness

Ready to merge - The fix correctly addresses issue #1265 and all tests pass.


🤖 Automated review by Claude

@ep0chzer0 ep0chzer0 force-pushed the fix/dead-code-library-functions branch 4 times, most recently from 0ca2c72 to 8d1b2ef Compare January 20, 2026 22:03
The dead-code detector incorrectly flagged library functions as dead code.
This fix updates the type annotation and set comprehension to properly
track library function canonical names.

Also adds test case and snapshot for library function usage.

Fixes crytic#1265
@ep0chzer0 ep0chzer0 force-pushed the fix/dead-code-library-functions branch from 8d1b2ef to 766a4e9 Compare January 21, 2026 01:03
dguido and others added 2 commits January 22, 2026 01:28
- Remove unused Contract import from dead_code.py
- Fix misleading comment in test file that claimed unused library
  function should be flagged (library functions are excluded from
  dead-code detection)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@dguido dguido merged commit c1b00b4 into crytic:master Jan 22, 2026
34 checks passed
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]: Slither incorrectly reports internal library function as unused

2 participants