slither v0.9.3 releases: Static Analyzer for Solidity
Slither, the Solidity source analyzer
Slither is a Solidity static analysis framework written in Python 3. It runs a suite of vulnerability detectors, prints visual information about contract details, and provides an API to easily write custom analyses. Slither enables developers to find vulnerabilities, enhance their code comprehension, and quickly prototype custom analyses.
Features
- Detects vulnerable Solidity code with low false positives
- Identifies where the error condition occurs in the source code
- Easy integration into continuous integration and Truffle builds
- Built-in ‘printers’ quickly report crucial contract information
- Detector API to write custom analyses in Python
- Ability to analyze contracts written with Solidity >= 0.4
- Intermediate representation (SlithIR) enables simple, high-precision analyses
Changelog v0.9.3
Added
- Detector: High cyclomatic complexity @bart1e in #1618
- Clarify requirement of installing solc by @CodeSandwich in #1599
- Slither-check-upgradeability: support complex datatypes by @webthethird in #1535
- Add enums to echidna printer’s list of constants by @samalws in #1665
- Add cyclomatic complexity to function-summary by @smonicas in #1685
- Add github pages docs by @0xalpharush in #1656
- Add issue template for trouble with installation by @0xalpharush in #1623
- APIs
- Add unregister_detector by @sidarth16 in #1722
- Add unregister_printer by @sidarth16 in #1724
Changed
- Detectors improvements
- Detect local shadowing of return vars by @0xalpharush in #1510
- Consider constants in divide-before-multiply by @0xalpharush in #1641
- Do not recommend to making strings immutable by @0xalpharush in #1639
- Restrict variable-scope detector to only solc 0.4.x by @0xalpharush in #1731
- Minor codex improvements by @montyly in #1600
- Minor API improvements by @montyly in #1601
- Use enum string formatting by @0xalpharush in #1636
- Add more types by @montyly in #1624
- Update list of external publications by @montyly in #1738
- Abstract contract property by @bsamuels453 in #1679
- Improve echidna printer for user defined types by @montyly in #1690
- Revert “show ignored findings by default for checklist” by @0xalpharush in #1643
- Improve tests from 1625 by @montyly in #1741
- Improve parsing of contract’s comment by @montyly in #1734
- Update filter-paths help by @0xalpharush in #1749
- Slithir printer improve top level functions format by @smonicas in #1744
- Add issue template for false neg. and positive by @0xalpharush in #1753
- Make web3 required dependency by @0xalpharush in #1743
- Update reentrancy_eth.py by @sidarth16 in #1706
- CI
- Run tests in parallel by @0xalpharush in #1637
- Only run python linters when .py changed by @0xalpharush in #1638
- Cancel action on new commits by @montyly in #1661
- Improvements to GH actions by @montyly in #1662
- Further CI improvements by @montyly in #1663
- Update linter.yml name by @0xalpharush in #1770
- Upgrade nix installation to fix CI installation by @0xalpharush in #1711
Fixed
- Fix ternary in nested expressions @0xalpharush in #1650
- Fix CI badge in README by @elopez in #1603
- Bugs fixed in strongly connected components and cyclomatic complexity algorithms by @bart1e in #1617
- ‘Not in UPPER_CASE_WITH_UNDERSCORES’ warning for public constant vars removed by @bart1e in #1530
- Missing references fix by @bart1e in #1604
- Fix support for constant variable lookup in yul by @montyly in #1611
- Uninitialized storage fix by @0xalpharush in #1725
- Fix stdout capture by @0xalpharush in #1740
- Move assertion to proper branch by @montyly in #1691
- Include salt in operation,
NewContract
, reads by @0xalpharush in #1762 - Fix declaration and evm printer by @0xalpharush in #1765
- Fix IR operation when initializing array with one-element array literal by @Troublor in #1761
- WIKI URL fixed by @bart1e in #1695
- Fix using for global function name collision by @0xalpharush in #1625
Install
Slither requires Python 3.6+ and solc, the Solidity compiler.
Using Pip
$ pip install slither-analyzer
Using Git
$ git clone https://github.com/trailofbits/slither.git && cd slither
$ python setup.py install
Use
Run Slither on a Truffle application:
slither .
Run Slither on a single file:
Slither can be run on:
- A
.sol
file - A Truffle directory
- A directory containing
*.sol
files (all the*.sol
files will be analyzed) - A glob (be sure to quote the argument when using a glob)
Configuration
--solc SOLC
: Path tosolc
(default ‘solc’)--solc-args SOLC_ARGS
: Add custom solc arguments.SOLC_ARGS
can contain multiple arguments--disable-solc-warnings
: Do not print solc warnings--solc-ast
: Use the solc AST file as input (solc file.sol --ast-json > file.ast.json
)--json FILE
: Export results as JSON
Detectors
By default, all the detectors are run.
Num | Detector | What it Detects | Impact | Confidence |
---|---|---|---|---|
1 | suicidal |
Functions allowing anyone to destruct the contract | High | High |
2 | uninitialized-local |
Uninitialized local variables | High | High |
3 | uninitialized-state |
Uninitialized state variables | High | High |
4 | uninitialized-storage |
Uninitialized storage variables | High | High |
5 | arbitrary-send |
Functions that send ether to arbitrary destinations | High | Medium |
6 | controlled-delegatecall |
Controlled delegatecall destination | High | Medium |
7 | reentrancy |
Reentrancy vulnerabilities | High | Medium |
8 | locked-ether |
Contracts that lock ether | Medium | High |
9 | const-func |
Constant functions changing the state | Medium | Medium |
10 | tx-origin |
Dangerous usage of tx.origin |
Medium | Medium |
11 | assembly |
Assembly usage | Informational | High |
12 | constable-states |
State variables that could be declared constant | Informational | High |
13 | external-function |
Public function that could be declared as external | Informational | High |
14 | low-level-calls |
Low level calls | Informational | High |
15 | naming-convention |
Conformance to Solidity naming conventions | Informational | High |
16 | pragma |
If different pragma directives are used | Informational | High |
17 | solc-version |
Old versions of Solidity (< 0.4.23) | Informational | High |
18 | unused-state |
Unused state variables |
Printers
To run a printer, use –print and a comma-separated list of printers.
Num | Printer | Description |
---|---|---|
1 | call-graph |
Export the call-graph of the contracts to a dot file |
2 | contract-summary |
Print a summary of the contracts |
3 | function-summary |
Print a summary of the functions |
4 | human-summary |
Print a human-readable summary of the contracts |
5 | inheritance |
Print the inheritance relations between contracts |
6 | inheritance-graph |
Export the inheritance graph of each contract to a dot file |
7 | slithir |
Print the slithIR representation of the functions |
8 | vars-and-auth |
Print the state variables written and the authorization of the functions |
Tutorial
Copyright (C) 2018