Skip to content

feat: add ERC token detection printer#2944

Open
ep0chzer0 wants to merge 5 commits intocrytic:masterfrom
ep0chzer0:feature/erc-printer
Open

feat: add ERC token detection printer#2944
ep0chzer0 wants to merge 5 commits intocrytic:masterfrom
ep0chzer0:feature/erc-printer

Conversation

@ep0chzer0
Copy link
Contributor

Summary

Add a new printer that automatically identifies and classifies token contracts based on their implemented interfaces.

Closes #2783

Features

  • Multi-standard detection: Detects ERC-20, ERC-721, ERC-777, ERC-1155, and ERC-4626 tokens
  • Compliance analysis: Calculates compliance percentages for each standard
  • Partial detection: Identifies contracts with partial implementations (>= 30% compliance)
  • Confidence levels: Provides HIGH/MEDIUM/LOW confidence based on compliance
  • Event checking: Verifies required events are implemented
  • JSON output: Comprehensive structured output for programmatic use

Implementation

Uses the existing ERCS dictionary and erc_to_signatures() helper from slither.utils.erc as suggested by @dguido in the issue discussion. This leverages Slither's existing ERC definitions for consistent detection.

Usage

slither . --print erc

Example Output

ERC Token Detection Results
==================================================

+--------------------------+-------------------+
| Token Standard           | Contracts Found   |
+--------------------------+-------------------+
| ERC-20                   | 1                 |
| Partial Implementations  | 1                 |
+--------------------------+-------------------+

ERC-20 Tokens (Fungible)
------------------------------

MyERC20 (tokens.sol)
  Confidence: HIGH (100%)
  Functions: 9/9
  Events: 2/2

Partial/Non-Standard Implementations
------------------------------

PartialERC20 (tokens.sol)
  Appears to be: ERC-20 (33%)

Statistics
------------------------------
Total contracts analyzed: 3
Token contracts found: 1
Partial implementations: 1

Test Plan

  • Added test case in tests/e2e/printers/test_printers.py
  • Created test contracts with ERC-20, partial ERC-20, and non-token contracts
  • Verified ruff linting passes

@ep0chzer0 ep0chzer0 requested a review from smonicas as a code owner January 21, 2026 22:49
@ep0chzer0 ep0chzer0 force-pushed the feature/erc-printer branch 2 times, most recently from abd8a26 to e9ccd64 Compare January 23, 2026 18:03
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).
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.

Enhancement: Add Automatic Token Standard Detection Printer

1 participant