Skip to content

Commit 7f54c8b

Browse files
authored
Merge pull request #2686 from crytic/dev
Merge master <> dev
2 parents a77738f + e4e828b commit 7f54c8b

File tree

77 files changed

+6499
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+6499
-49
lines changed

Diff for: .github/workflows/linter.yml

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ jobs:
4444
run: |
4545
echo "::add-matcher::.github/workflows/matchers/yamllint.json"
4646
47+
- name: Remove part of the doc
48+
run: |
49+
rm -rf docs/src/
50+
4751
- name: Lint everything else
4852
uses: super-linter/super-linter/[email protected]
4953
if: always()

Diff for: .gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,5 @@ test_artifacts/
113113
# crytic export
114114
crytic-export/
115115

116-
# Auto-generated Github pages docs
117-
docs/
118-
119116
# slither.db.json
120117
slither.db.json

Diff for: README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,14 @@ See the [Printer documentation](https://github.com/crytic/slither/wiki/Printer-d
258258

259259
## Tools
260260

261-
* `slither-check-upgradeability`: [Review `delegatecall`-based upgradeability](https://github.com/crytic/slither/wiki/Upgradeability-Checks)
262-
* `slither-prop`: [Automatic unit test and property generation](https://github.com/crytic/slither/wiki/Property-generation)
263-
* `slither-flat`: [Flatten a codebase](https://github.com/crytic/slither/wiki/Contract-Flattening)
264-
* `slither-check-erc`: [Check the ERC's conformance](https://github.com/crytic/slither/wiki/ERC-Conformance)
265-
* `slither-format`: [Automatic patch generation](https://github.com/crytic/slither/wiki/Slither-format)
266-
* `slither-read-storage`: [Read storage values from contracts](./slither/tools/read_storage/README.md)
267-
* `slither-interface`: [Generate an interface for a contract](./slither/tools/interface/README.md)
268-
269-
See the [Tool documentation](https://github.com/crytic/slither/wiki/Tool-Documentation) for additional tools.
261+
* `slither-check-upgradeability`: [Review `delegatecall`-based upgradeability](./docs/src/tools/Upgradeability-Checks.md)
262+
* `slither-prop`: [Automatic unit test and property generation](./docs/src/tools/Property-generation.md)
263+
* `slither-flat`: [Flatten a codebase](./docs/src/tools/Contract-Flattening.md)
264+
* `slither-check-erc`: [Check the ERC's conformance](./docs/src/tools/ERC-Conformance.md)
265+
* `slither-read-storage`: [Read storage values from contracts](./docs/src/tools/ReadStorage.md)
266+
* `slither-interface`: [Generate an interface for a contract](./docs/src/tools/Interface.md)
267+
268+
See the [Tool documentation](./docs/src/tools/README.md) for additional tools.
270269

271270
[Contact us](https://www.trailofbits.com/contact/) to get help on building custom tools.
272271

Diff for: docs/src/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# [Slither, the smart contract static analyzer](https://crytic.github.io/slither/slither.html)
2+
3+
<img src="https://raw.githubusercontent.com/crytic/slither/master/logo.png" alt="Slither Static Analysis Framework Logo" width="500" />
4+
5+
[**Slither**](https://github.com/crytic/slither) is a Solidity & Vyper static analysis framework written in Python3. 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.
6+
7+
If you are looking to use Slither's cli:
8+
9+
- [Usage](./Usage.md) the most common flags
10+
11+
If you are looking to leverage Slither inbuilt features:
12+
13+
- [Detectors](./detectors/): Vulnerabilities detectors
14+
- [Printers](./printers): Printers (code vizualiation)
15+
- [Tools](./tools): Custom tools
16+
17+
If you are looking to learn how to extend Slither's capabilities:
18+
19+
- [API](./api): Introduction to static analysis & Slither's API
20+
- [Tutorial](./tutorials/): Hands-on exercises

Diff for: docs/src/SUMMARY.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
- [Introduction](./README.md)
2+
- [Usage](./Usage.md)
3+
- [API](./api/README.md)
4+
- [Static Analysis](./api/static_analysis.md)
5+
- [API](./api/api.md)
6+
- [SlithIR](./api/SlithIR.md)
7+
- [SSA](./api/SlithIR-SSA.md)
8+
- [Data dependency](./api/Data-dependency.md)
9+
- [JSON output](./api/JSON-output.md)
10+
- [Detectors](./detectors/Detector-Documentation.md)
11+
- [Detectors](./detectors/Detector-Documentation.md)
12+
- [Adding a detector](./detectors/Adding-a-new-detector.md)
13+
- [Printers](./printers/Printer-documentation.md)
14+
- [Tools](./tools/README.md)
15+
- [Adding a new tool](./tools/Adding-a-new-utility.md)
16+
- [Code Similarity](./tools/Code-Similarity-Detector.md)
17+
- [Contract Flattening](./tools/Contract-Flattening.md)
18+
- [Documentation](./tools/Documentation.md)
19+
- [Doctor](./tools/Doctor.md)
20+
- [ERC Conformance](./tools/ERC-Conformance.md)
21+
- [Interface](./tools/Interface.md)
22+
- [Mutator](./tools/Mutator.md)
23+
- [Path Finding Utility](./tools/Path-Finding-Utility.md)
24+
- [Property Generation](./tools/Property-generation.md)
25+
- [Read Storage](./tools/ReadStorage.md)
26+
- [Format](./tools/Slither-format.md)
27+
- [Upgradeability checks](./tools/Upgradeability-Checks.md)
28+
- [Tutorials](./tutorials/README.md)
29+
- [Exercise 1](./tutorials/exercise1.md)
30+
- [Exercise 2](./tutorials/exercise2.md)
31+
- [Exercise 3](./tutorials/exercise3.md)

Diff for: docs/src/Usage.md

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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)

Diff for: docs/src/api/Data-dependency.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Data dependency
2+
3+
Data dependency allows knowing if the value of a given variable is influenced by another variable's value.
4+
5+
Because smart contracts have a state machine based architecture, the results of the data dependency depend on the context (function/contract) of the analysis. Consider the following example:
6+
7+
```solidity
8+
contract MyContract{
9+
uint a = 0;
10+
uint b = 0;
11+
12+
function setA(uint input_a) public{
13+
a = input_a;
14+
}
15+
16+
function setB() public{
17+
b = a;
18+
}
19+
20+
}
21+
```
22+
23+
In this example, if we consider only `setA`, we have the following dependency:
24+
25+
- `a` is dependent on `input_a`
26+
27+
If we consider only `setB`, we have:
28+
29+
- `b` is dependent on `a`
30+
31+
If we consider the contract entirely (with all the functions), we have:
32+
33+
- `a` is dependent on `input_a`
34+
- `b` is dependent on `a` and `input_a` (by transitivity)
35+
36+
`slither.analyses.is_dependent(variable, variable_source, context)` allows to know if `variable` is dependent on `variable_source` on the given context.
37+
38+
As a result, in our previous example, `is_dependent(b, a, funcA)` will return `False`, while `is_dependent(b, a, myContract)` will return `True`:
39+
40+
```
41+
from slither import Slither
42+
from slither.analyses import is_dependent
43+
44+
slither = Slither('data_dependency_simple_example.sol')
45+
46+
myContract = slither.get_contract_from_name('MyContract')
47+
funcA = myContract.get_function_from_signature('setA(uint256)')
48+
input_a = funcA.parameters[0]
49+
50+
a = myContract.get_state_variable_from_name('a')
51+
b = myContract.get_state_variable_from_name('b')
52+
53+
print(f'{b.name} is dependant from {input_a.name}?: {is_dependent(b, a, funcA)}')
54+
print(f'{b.name} is dependant from {input_a.name}?: {is_dependent(b, a, myContract)}')
55+
```

0 commit comments

Comments
 (0)