|
| 1 | +## Usage |
| 2 | + |
| 3 | +- [How to run Slither](#how-to-run-slither) |
| 4 | + - [Foundry/Hardhat](#foundryhardhat) |
| 5 | + - [solc](#solc) |
| 6 | + - [Etherscan](#etherscan) |
| 7 | + - [AST input](#ast-file) |
| 8 | +- [Options](#options) |
| 9 | + - [Detector selection](#detector-selection) |
| 10 | + - [Printer selection](#printer-selection) |
| 11 | + - [Path Filtering](#path-filtering) |
| 12 | + - [Triage mode](#triage-mode) |
| 13 | + - [Configuration file](#configuration-file) |
| 14 | +- [IDE integrations](#ide-integration) |
| 15 | + |
| 16 | +## How to run Slither |
| 17 | + |
| 18 | +All the [`crytic-compile`](https://github.com/crytic/crytic-compile/wiki/Configuration) options are available through Slither. |
| 19 | + |
| 20 | +### Foundry/hardhat |
| 21 | + |
| 22 | +To run Slither on a Foundry/hardhat directory: |
| 23 | + |
| 24 | +``` |
| 25 | +slither . |
| 26 | +``` |
| 27 | + |
| 28 | +### solc |
| 29 | + |
| 30 | +To run Slither from a Solidity file: |
| 31 | + |
| 32 | +``` |
| 33 | +slither file.sol |
| 34 | +``` |
| 35 | + |
| 36 | +### Etherscan |
| 37 | + |
| 38 | +To run Slither from a contract hosted on Etherscan, run |
| 39 | + |
| 40 | +``` |
| 41 | +slither 0x7F37f78cBD74481E593F9C737776F7113d76B315 |
| 42 | +``` |
| 43 | + |
| 44 | +We recommend installing [solc-select](https://github.com/crytic/solc-select/) so Slither can switch to the expected solc version automatically. |
| 45 | + |
| 46 | +### Detector selection |
| 47 | + |
| 48 | +Slither runs all its detectors by default. |
| 49 | + |
| 50 | +To run only selected detectors, use `--detect detector1,detector2`. For example: |
| 51 | + |
| 52 | +``` |
| 53 | +slither file.sol --detect arbitrary-send,pragma |
| 54 | +``` |
| 55 | + |
| 56 | +To exclude detectors, use `--exclude detector1,detector2`. For example: |
| 57 | + |
| 58 | +``` |
| 59 | +slither file.sol --exclude naming-convention,unused-state,suicidal |
| 60 | +``` |
| 61 | + |
| 62 | +To exclude detectors with an informational or low severity, use `--exclude-informational` or `--exclude-low`. |
| 63 | + |
| 64 | +`--list-detectors` lists [available detectors](https://github.com/crytic/slither/wiki/Detector-Documentation). |
| 65 | + |
| 66 | +### Printer selection |
| 67 | + |
| 68 | +By default, no printers are run. |
| 69 | + |
| 70 | +To run selected printers, use `--print printer1,printer2`. For example: |
| 71 | + |
| 72 | +``` |
| 73 | +slither file.sol --print inheritance-graph |
| 74 | +``` |
| 75 | + |
| 76 | +`--list-printers` lists [available printers](https://github.com/crytic/slither/wiki/Printer-Documentation). |
| 77 | + |
| 78 | +### Path filtering |
| 79 | + |
| 80 | +`--filter-paths path1` will exclude all the results that are only related to `path1`. The path specified can be a path directory or a filename. Direct string comparison and [Python regular expression](https://docs.python.org/3/library/re.html) are used. |
| 81 | + |
| 82 | +Examples: |
| 83 | + |
| 84 | +``` |
| 85 | +slither . --filter-paths "openzepellin" |
| 86 | +``` |
| 87 | + |
| 88 | +Filter all the results only related to openzepellin. |
| 89 | + |
| 90 | +``` |
| 91 | +slither . --filter-paths "Migrations.sol|ConvertLib.sol" |
| 92 | +``` |
| 93 | + |
| 94 | +Filter all the results only related to the file `SafeMath.sol` or `ConvertLib.sol`. |
| 95 | + |
| 96 | +### Triage mode |
| 97 | + |
| 98 | +Slither offers two ways to remove results: |
| 99 | + |
| 100 | +- By adding `//slither-disable-next-line DETECTOR_NAME` before the issue |
| 101 | +- By adding `// slither-disable-start [detector] ... // slither-disable-end [detector]` around the code to disable the detector on a large section |
| 102 | +- By adding `@custom:security non-reentrant` before the variable declaration will indicate to Slither that the external calls from this variable are non-reentrant |
| 103 | +- By running the triage mode (see below) |
| 104 | + |
| 105 | +### Triage mode |
| 106 | + |
| 107 | +`--triage-mode` runs Slither in its triage mode. For every finding, Slither will ask if the result should be shown for the next run. Results are saved in `slither.db.json`. |
| 108 | + |
| 109 | +Examples: |
| 110 | + |
| 111 | +``` |
| 112 | +slither . --triage-mode |
| 113 | +[...] |
| 114 | +0: C.destination (test.sol#3) is never initialized. It is used in: |
| 115 | + - f (test.sol#5-7) |
| 116 | +Reference: https://github.com/trailofbits/slither/wiki/Vulnerabilities-Description#uninitialized-state-variables |
| 117 | +Results to hide during next runs: "0,1,..." or "All" (enter to not hide results): 0 |
| 118 | +[...] |
| 119 | +``` |
| 120 | + |
| 121 | +The second run of Slither will hide the above result. |
| 122 | + |
| 123 | +To show the hidden results again, delete `slither.db.json`. |
| 124 | + |
| 125 | +### Configuration File |
| 126 | + |
| 127 | +Some options can be set through a json configuration file. By default, `slither.config.json` is used if present (it can be changed through `--config-file file.config.json`). |
| 128 | + |
| 129 | +Options passed via the CLI have priority over options set in the configuration file. |
| 130 | + |
| 131 | +The following flags are supported: |
| 132 | + |
| 133 | +``` |
| 134 | +{ |
| 135 | + "detectors_to_run": "all", |
| 136 | + "printers_to_run": None, |
| 137 | + "detectors_to_exclude": None, |
| 138 | + "detectors_to_include": None, |
| 139 | + "exclude_dependencies": False, |
| 140 | + "exclude_informational": False, |
| 141 | + "exclude_optimization": False, |
| 142 | + "exclude_low": False, |
| 143 | + "exclude_medium": False, |
| 144 | + "exclude_high": False, |
| 145 | + "fail_on": FailOnLevel.PEDANTIC, |
| 146 | + "json": None, |
| 147 | + "sarif": None, |
| 148 | + "disable_color": False, |
| 149 | + "filter_paths": None, |
| 150 | + "include_paths": None, |
| 151 | + "generate_patches": False, |
| 152 | + "skip_assembly": False, |
| 153 | + "legacy_ast": False, |
| 154 | + "zip": None, |
| 155 | + "zip_type": "lzma", |
| 156 | + "show_ignored_findings": False, |
| 157 | + "sarif_input": "export.sarif", |
| 158 | + "sarif_triage": "export.sarif.sarifexplorer", |
| 159 | + "triage_database": "slither.db.json", |
| 160 | + # codex |
| 161 | + "codex": False, |
| 162 | + "codex_contracts": "all", |
| 163 | + "codex_model": "text-davinci-003", |
| 164 | + "codex_temperature": 0, |
| 165 | + "codex_max_tokens": 300, |
| 166 | + "codex_log": False, |
| 167 | +} |
| 168 | +``` |
| 169 | + |
| 170 | +For flags related to the compilation, see the [`crytic-compile` configuration](https://github.com/crytic/crytic-compile/blob/master/crytic_compile/cryticparser/defaults.py) |
0 commit comments