Skip to content

Commit 353d4da

Browse files
authored
Merge pull request #2475 from crytic/dev
sync master <> dev
2 parents 1a50b8e + 02df0dc commit 353d4da

File tree

148 files changed

+987
-642
lines changed

Some content is hidden

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

148 files changed

+987
-642
lines changed

.coderabbit.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
2+
language: "en"
3+
early_access: false
4+
knowledge_base:
5+
learnings:
6+
scope: auto
7+
issues:
8+
scope: global
9+
reviews:
10+
profile: "chill"
11+
request_changes_workflow: false
12+
high_level_summary: true
13+
poem: false
14+
review_status: true
15+
collapse_walkthrough: true
16+
auto_review:
17+
enabled: true
18+
ignore_title_keywords:
19+
- "WIP"
20+
- "DO NOT MERGE"
21+
drafts: false
22+
base_branches:
23+
- dev
24+
chat:
25+
auto_reply: true

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ jobs:
6767
6868
- name: Set up nix
6969
if: matrix.type == 'dapp'
70-
uses: cachix/install-nix-action@v26
70+
uses: cachix/install-nix-action@V27
7171

7272
- name: Set up cachix
7373
if: matrix.type == 'dapp'
74-
uses: cachix/cachix-action@v14
74+
uses: cachix/cachix-action@v15
7575
with:
7676
name: dapp
7777

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,7 @@ test_artifacts/
114114
crytic-export/
115115

116116
# Auto-generated Github pages docs
117-
docs/
117+
docs/
118+
119+
# slither.db.json
120+
slither.db.json

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,12 @@ Num | Detector | What it Detects | Impact | Confidence
196196
85 | `costly-loop` | [Costly operations in a loop](https://github.com/crytic/slither/wiki/Detector-Documentation#costly-operations-inside-a-loop) | Informational | Medium
197197
86 | `dead-code` | [Functions that are not used](https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code) | Informational | Medium
198198
87 | `reentrancy-unlimited-gas` | [Reentrancy vulnerabilities through send and transfer](https://github.com/crytic/slither/wiki/Detector-Documentation#reentrancy-vulnerabilities-4) | Informational | Medium
199-
88 | `similar-names` | [Variable names are too similar](https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-too-similar) | Informational | Medium
200-
89 | `too-many-digits` | [Conformance to numeric notation best practices](https://github.com/crytic/slither/wiki/Detector-Documentation#too-many-digits) | Informational | Medium
201-
90 | `cache-array-length` | [Detects `for` loops that use `length` member of some storage array in their loop condition and don't modify it.](https://github.com/crytic/slither/wiki/Detector-Documentation#cache-array-length) | Optimization | High
202-
91 | `constable-states` | [State variables that could be declared constant](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-constant) | Optimization | High
203-
92 | `external-function` | [Public function that could be declared external](https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external) | Optimization | High
204-
93 | `immutable-states` | [State variables that could be declared immutable](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-immutable) | Optimization | High
205-
94 | `var-read-using-this` | [Contract reads its own variable using `this`](https://github.com/crytic/slither/wiki/Detector-Documentation#public-variable-read-in-external-context) | Optimization | High
199+
88 | `too-many-digits` | [Conformance to numeric notation best practices](https://github.com/crytic/slither/wiki/Detector-Documentation#too-many-digits) | Informational | Medium
200+
89 | `cache-array-length` | [Detects `for` loops that use `length` member of some storage array in their loop condition and don't modify it.](https://github.com/crytic/slither/wiki/Detector-Documentation#cache-array-length) | Optimization | High
201+
90 | `constable-states` | [State variables that could be declared constant](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-constant) | Optimization | High
202+
91 | `external-function` | [Public function that could be declared external](https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external) | Optimization | High
203+
92 | `immutable-states` | [State variables that could be declared immutable](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-immutable) | Optimization | High
204+
93 | `var-read-using-this` | [Contract reads its own variable using `this`](https://github.com/crytic/slither/wiki/Detector-Documentation#public-variable-read-in-external-context) | Optimization | High
206205

207206
For more information, see
208207

@@ -302,5 +301,12 @@ Title | Usage | Authors | Venue | Code
302301
[Do Not Rug on Me: Leveraging Machine Learning Techniques for Automated Scam Detection](https://www.mdpi.com/2227-7390/10/6/949) | Use Slither to extract tokens' features (mintable, pausable, ..) | Mazorra, Bruno, Victor Adan, and Vanesa Daza | Mathematics 10.6 (2022) | -
303302
[MANDO: Multi-Level Heterogeneous Graph Embeddings for Fine-Grained Detection of Smart Contract Vulnerabilities](https://arxiv.org/abs/2208.13252) | Use Slither to extract the CFG and call graph | Hoang Nguyen, Nhat-Minh Nguyen, Chunyao Xie, Zahra Ahmadi, Daniel Kudendo, Thanh-Nam Doan and Lingxiao Jiang| IEEE 9th International Conference on Data Science and Advanced Analytics (DSAA, 2022) | [ge-sc](https://github.com/MANDO-Project/ge-sc)
304303
[Automated Auditing of Price Gouging TOD Vulnerabilities in Smart Contracts](https://www.cs.toronto.edu/~fanl/papers/price-icbc22.pdf) | Use Slither to extract the CFG and data dependencies| Sidi Mohamed Beillahi, Eric Keilty, Keerthi Nelaturu, Andreas Veneris, and Fan Long | 2022 IEEE International Conference on Blockchain and Cryptocurrency (ICBC) | [Smart-Contract-Repair](https://github.com/Veneris-Group/TOD-Location-Rectification)
304+
[Modeling and Enforcing Access Control Policies for Smart Contracts](https://publikationen.bibliothek.kit.edu/1000152805/151859658) | Extend Slither's data dependencies | Jan-Philipp Toberg, Jonas Schiffl, Frederik Reiche, Bernhard Beckert, Robert Heinrich, Ralf Reussner | IEEE International Conference on Decentralized Applications and Infrastructures (DAPPS), 2022 | [SolidityAccessControlEnforcement](https://github.com/KASTEL-CSSDA/SolidityAccessControlEnforcement)
305+
[Smart Contract Vulnerability Detection Based on Deep Learning and Multimodal Decision Fusion](https://www.mdpi.com/1424-8220/23/16/7246) | Use Slither to extract the CFG | Weichu Deng, Huanchun Wei, Teng Huang, Cong Cao, Yun Peng, and Xuan Hu | Sensors 2023, 23, 7246 | -
306+
[Semantic-enriched Code Knowledge Graph to Reveal Unknowns in Smart Contract Code Reuse](https://www.researchgate.net/profile/Qing-Huang-26/publication/370638129_Semantic-enriched_Code_Knowledge_Graph_to_Reveal_Unknowns_in_Smart_Contract_Code_Reuse/links/645b7b8639c408339b3a54da/Semantic-Enriched-Code-Knowledge-Graph-to-Reveal-Unknowns-in-Smart-Contract-Code-Reuse.pdf) | Use Slither to extract the code features (CFG, function, parameters types, ..) | Qing Huang, Dianshu Liao, Zhenchang Xing, Zhengkang Zuo, Changjing Wang, Xin Xia | ACM Transactions on Software Engineering and Methodology, 2023 | -
307+
[Smart Contract Parallel Execution with Fine-Grained State Accesses](https://personal.ntu.edu.sg/yi_li/files/Qi2023SCP.pdf) | Use Slither to build state access graphs | Xiaodong Qi, Jiao Jiao, Yi Li | International Conference on Distributed Computing Systems (ICDCS), 2023 | -
308+
[Bad Apples: Understanding the Centralized Security Risks in Decentralized Ecosystems](https://diaowenrui.github.io/paper/www23-yan.pdf) | Implement an internal analysis on top of Slither | Kailun Yan , Jilian Zhang , Xiangyu Liu , Wenrui Diao , Shanqing Guo | ACM Web Conference April 2023 | -
309+
[Identifying Vulnerabilities in Smart Contracts using Interval Analysis](https://arxiv.org/pdf/2309.13805.pdf) | Create 4 detectors on top of Slither | Ştefan-Claudiu Susan, Andrei Arusoaie | FROM 2023 | -
310+
Storage State Analysis and Extraction of Ethereum Blockchain Smart Contracts (no PDF in open access) | Rely on Slither's CFG and AST | Maha Ayub , Tania Saleem , Muhammad Janjua , Talha Ahmad | TOSEM 2023 | [SmartMuv](https://github.com/WaizKhan7/SmartMuv)
305311

306312
If you are using Slither on an academic work, consider applying to the [Crytic $10k Research Prize](https://blog.trailofbits.com/2019/11/13/announcing-the-crytic-10k-research-prize/).

plugin_example/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from setuptools import setup, find_packages
22

33
setup(
4-
name="slither-my-plugins",
4+
name="slither_my_plugin",
55
description="This is an example of detectors and printers to Slither.",
66
url="https://github.com/trailofbits/slither-plugins",
77
author="Trail of Bits",
88
version="0.0",
99
packages=find_packages(),
1010
python_requires=">=3.8",
11-
install_requires=["slither-analyzer==0.1"],
11+
install_requires=["slither-analyzer>=0.6.0"],
1212
entry_points={
1313
"slither_analyzer.plugin": "slither my-plugin=slither_my_plugin:make_plugin",
1414
},

plugin_example/slither_my_plugin/detectors/__init__.py

Whitespace-only changes.

plugin_example/slither_my_plugin/detectors/example.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class Example(AbstractDetector): # pylint: disable=too-few-public-methods
1111
IMPACT = DetectorClassification.HIGH
1212
CONFIDENCE = DetectorClassification.HIGH
1313

14-
WIKI = ""
14+
WIKI = "https://www.example.com/#example-detector"
1515

16-
WIKI_TITLE = ""
17-
WIKI_DESCRIPTION = ""
18-
WIKI_EXPLOIT_SCENARIO = ""
19-
WIKI_RECOMMENDATION = ""
16+
WIKI_TITLE = "example detector"
17+
WIKI_DESCRIPTION = "This is an example detector that always generates a finding"
18+
WIKI_EXPLOIT_SCENARIO = "Scenario goes here"
19+
WIKI_RECOMMENDATION = "Customize the detector"
2020

2121
def _detect(self):
2222

scripts/ci_test.sh

-84
This file was deleted.

scripts/json_diff.py

-27
This file was deleted.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
description="Slither is a Solidity and Vyper static analysis framework written in Python 3.",
99
url="https://github.com/crytic/slither",
1010
author="Trail of Bits",
11-
version="0.10.2",
11+
version="0.10.3",
1212
packages=find_packages(),
1313
python_requires=">=3.8",
1414
install_requires=[

slither/__main__.py

+60-31
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import sys
1212
import traceback
1313
from importlib import metadata
14-
from typing import Tuple, Optional, List, Dict, Type, Union, Any, Sequence
14+
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union
1515

1616

17-
from crytic_compile import cryticparser, CryticCompile
17+
from crytic_compile import cryticparser, CryticCompile, InvalidCompilation
1818
from crytic_compile.platform.standard import generate_standard_export
1919
from crytic_compile.platform.etherscan import SUPPORTED_NETWORK
2020
from crytic_compile import compile_all, is_supported
@@ -93,7 +93,13 @@ def process_all(
9393
detector_classes: List[Type[AbstractDetector]],
9494
printer_classes: List[Type[AbstractPrinter]],
9595
) -> Tuple[List[Slither], List[Dict], List[Output], int]:
96-
compilations = compile_all(target, **vars(args))
96+
97+
try:
98+
compilations = compile_all(target, **vars(args))
99+
except InvalidCompilation:
100+
logger.error("Unable to compile all targets.")
101+
sys.exit(2)
102+
97103
slither_instances = []
98104
results_detectors = []
99105
results_printers = []
@@ -205,47 +211,54 @@ def choose_detectors(
205211

206212
if args.detectors_to_run == "all":
207213
detectors_to_run = all_detector_classes
208-
if args.detectors_to_exclude:
209-
detectors_excluded = args.detectors_to_exclude.split(",")
210-
for detector in detectors:
211-
if detector in detectors_excluded:
212-
detectors_to_run.remove(detectors[detector])
213214
else:
214-
for detector in args.detectors_to_run.split(","):
215-
if detector in detectors:
216-
detectors_to_run.append(detectors[detector])
217-
else:
218-
raise ValueError(f"Error: {detector} is not a detector")
219-
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
215+
detectors_to_run = __include_detectors(
216+
set(detectors_to_run), args.detectors_to_run, detectors
217+
)
220218
return detectors_to_run
221219

222-
if args.exclude_optimization:
223-
detectors_to_run = [
224-
d for d in detectors_to_run if d.IMPACT != DetectorClassification.OPTIMIZATION
225-
]
220+
classification_map = {
221+
DetectorClassification.HIGH: args.exclude_high,
222+
DetectorClassification.MEDIUM: args.exclude_medium,
223+
DetectorClassification.LOW: args.exclude_low,
224+
DetectorClassification.INFORMATIONAL: args.exclude_informational,
225+
DetectorClassification.OPTIMIZATION: args.exclude_optimization,
226+
}
227+
excluded_classification = [
228+
classification for classification, included in classification_map.items() if included
229+
]
230+
detectors_to_run = [d for d in detectors_to_run if d.IMPACT not in excluded_classification]
226231

227-
if args.exclude_informational:
228-
detectors_to_run = [
229-
d for d in detectors_to_run if d.IMPACT != DetectorClassification.INFORMATIONAL
230-
]
231-
if args.exclude_low:
232-
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.LOW]
233-
if args.exclude_medium:
234-
detectors_to_run = [
235-
d for d in detectors_to_run if d.IMPACT != DetectorClassification.MEDIUM
236-
]
237-
if args.exclude_high:
238-
detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.HIGH]
239232
if args.detectors_to_exclude:
240233
detectors_to_run = [
241234
d for d in detectors_to_run if d.ARGUMENT not in args.detectors_to_exclude
242235
]
243236

244-
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
237+
if args.detectors_to_include:
238+
detectors_to_run = __include_detectors(
239+
set(detectors_to_run), args.detectors_to_include, detectors
240+
)
245241

246242
return detectors_to_run
247243

248244

245+
def __include_detectors(
246+
detectors_to_run: Set[Type[AbstractDetector]],
247+
detectors_to_include: str,
248+
detectors: Dict[str, Type[AbstractDetector]],
249+
) -> List[Type[AbstractDetector]]:
250+
include_detectors = detectors_to_include.split(",")
251+
252+
for detector in include_detectors:
253+
if detector in detectors:
254+
detectors_to_run.add(detectors[detector])
255+
else:
256+
raise ValueError(f"Error: {detector} is not a detector")
257+
258+
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
259+
return detectors_to_run
260+
261+
249262
def choose_printers(
250263
args: argparse.Namespace, all_printer_classes: List[Type[AbstractPrinter]]
251264
) -> List[Type[AbstractPrinter]]:
@@ -335,6 +348,14 @@ def parse_args(
335348
default=defaults_flag_in_config["printers_to_run"],
336349
)
337350

351+
group_printer.add_argument(
352+
"--include-interfaces",
353+
help="Include interfaces from inheritance-graph printer",
354+
action="store_true",
355+
dest="include_interfaces",
356+
default=False,
357+
)
358+
338359
group_detector.add_argument(
339360
"--list-detectors",
340361
help="List available detectors",
@@ -401,6 +422,14 @@ def parse_args(
401422
default=defaults_flag_in_config["exclude_high"],
402423
)
403424

425+
group_detector.add_argument(
426+
"--include-detectors",
427+
help="Comma-separated list of detectors that should be included",
428+
action="store",
429+
dest="detectors_to_include",
430+
default=defaults_flag_in_config["detectors_to_include"],
431+
)
432+
404433
fail_on_group = group_detector.add_mutually_exclusive_group()
405434
fail_on_group.add_argument(
406435
"--fail-pedantic",

0 commit comments

Comments
 (0)