feat: add ERC token detection printer#2944
Open
ep0chzer0 wants to merge 5 commits intocrytic:masterfrom
Open
Conversation
abd8a26 to
e9ccd64
Compare
Add a new printer that automatically identifies and classifies token contracts based on their implemented interfaces. The printer detects: - ERC-20 (Fungible tokens) - ERC-721 (NFTs) - ERC-777 (Advanced fungible tokens) - ERC-1155 (Multi-token standard) - ERC-4626 (Tokenized vaults) Features: - Uses ERCS dictionary from slither.utils.erc for standard definitions - Calculates compliance percentages for each standard - Detects partial implementations (>= 30% compliance) - Provides colored output with confidence levels - Includes comprehensive JSON output for programmatic use Usage: slither . --print erc Closes crytic#2783
- Use Event.full_name property for consistent event signature format - Add type hints for contract parameters - Extract magic numbers to named constants (CONFIDENCE_HIGH, CONFIDENCE_MEDIUM, PARTIAL_THRESHOLD) - Add defensive check for source_mapping.filename being None - Remove redundant compliance calculations - Add disclaimer about signature-only detection - Add ERC-721 test contract and interface exclusion test - Fix conditional test assertions to be unconditional
The add_other() method requires source_mapping and compilation_unit parameters, which is designed for element-based output. Using generate_output() with additional_fields is the correct API for printer-specific structured data. Fixes test failure: Output.add_other() missing required argument
Store compliance results in a cache dictionary during the first pass through token standards, then reuse cached values when checking for partial implementations. This reduces compliance calculations from 10 to 5 per contract (50% reduction).
e9ccd64 to
9e0cd5b
Compare
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
Add a new printer that automatically identifies and classifies token contracts based on their implemented interfaces.
Closes #2783
Features
Implementation
Uses the existing
ERCSdictionary anderc_to_signatures()helper fromslither.utils.ercas suggested by @dguido in the issue discussion. This leverages Slither's existing ERC definitions for consistent detection.Usage
slither . --print ercExample Output
Test Plan
tests/e2e/printers/test_printers.py