How crytic/slither works
Project Type and Purpose
• Slither is an open‑source, Python‑based static analysis framework and CLI tool for Solidity & Vyper smart contracts.
• Its goal is to parse smart‑contract source, build an intermediate representation (SlithIR), run vulnerability “detectors,” emit visual/printer reports, and offer an API for extensions.
High‑Level Architecture Components
A. CLI / Entry‑Point Layer
• slither/__main__.py, slither/slither.py define the slither console command.
• Subcommands under slither/tools/* (e.g., slither-read-storage, slither-flat) are separate entry points.
• plugin_example demonstrates how to add new detectors via Python entry_points.
B. Parsing Layer
• slither/solc_parsing: wraps the Solidity compiler AST, builds Solidity AST + basic CFG.
• slither/vyper_parsing: handles Vyper AST and CFG.
• Relies on external solc (or crytic‑compile) to produce JSON AST.
C. Core Model & IR
• slither/core: builds a unified object model (CompilationUnit, AST nodes, CFG, scoping, type information).
• slither/slithir: converts core model to SlithIR SSA, supports IR operations, SSA variables, dominator analysis.
D. Analysis & Detectors
• slither/analyses/*: built‑in analyses (data dependency, EVM CFG generation, write‐analysis).
• slither/detectors/*: a plugin‑style architecture where each detector inspects the core model or IR and emits findings.
• slither/visitors: AST/IR visitors to factor common traversal logic.
E. Formatters & Printers
• slither/formatters: transforms raw detector findings into human‑readable or SARIF formats.
• slither/printers: visual “printers” (call graph, CFG, inheritance graph) and summaries; these render dot files, plain text, or JSON.
F. Tools (Standalone Utilities)
• Under slither/tools/*: wrap detectors/printers for specialized workflows: upgradeability checks, property generation, flattening, ERC compliance, etc.
• Each has its own __main__.py and reuses core and detectors.
G. Utilities & Shared Code
• slither/utils: common helpers (command‑line parsing, code complexity, output capture).
• scripts, Makefile, Dockerfile, GitHub Actions workflows orchestrate CI, testing, packaging.
H. Tests & Documentation
• tests/unit and tests/e2e: verify core model, IR correctness, detector outputs, printer outputs.
• docs/src: user/docs, API references, how to write detectors/printers.
Data Flow and Interactions
1. User invokes slither (or one of the slither-* tools).
2. CLI layer calls Parsing Layer → obtains AST + basic CFG.
3. Core Model builds semantic objects; SlithIR converts to SSA IR.
4. Analyses run on core model and IR to produce dependency graphs, CFGs, call graphs.
5. Detectors execute against model/IR, emit vulnerabilities/warnings.
7. Tools wrap steps 2–6 for specialized commands.
8. Results go to console, files, or CI integrations (e.g., SARIF for GitHub code scanning).
Architectural Patterns & Principles
• Layered design: CLI → Parsing → Core Model → IR → Analyses/Detectors → Output
• Plugin architecture: detectors, printers, and tools are registered via Python entry points.
• Separation of concerns: parsing, modeling, analysis, and reporting are distinct modules.
• Extensibility: users can add new detectors/printers/tools without modifying core.
Technologies & External Services
• Python 3.8+
• External solc compiler or crytic‑compile backend
• Docker for containerized execution
• GitHub Actions for CI (lint, test, docs, publish)
• PyPI packaging (setup.py, pyproject.toml)
• Graphviz (dot) for graphs
Essential Elements
• Component names and responsibilities
• Notes on extensibility (entry_points, plugin_example)
• External dependencies/services clearly outside core boundary