返回更新列表
新发布Jul 29, 2026

slither v0.11.6

Solidity 和 Vyper 的静态分析器

分享

Slither,智能合约静态分析器

Slither Static Analysis Framework Logo

Build Status PyPI Slither - Read the Docs Slither - Wiki

加入 Empire Hacking Slack

Slack Status

- 讨论与支持

Slither 是一个用 Python3 编写的 Solidity 和 Vyper 静态分析框架。它运行一套漏洞检测器,打印合约细节的可视化信息,并提供 API 以轻松编写自定义分析。Slither 使开发者能够发现漏洞,增强代码理解,并快速原型化自定义分析。

功能

  • 以低误报率检测易受攻击的 Solidity 代码(查看战利品列表)
  • 识别源代码中错误条件发生的位置
  • 轻松集成到持续集成和 Hardhat/Foundry 构建中
  • 内置的 'printers' 快速报告关键合约信息
  • 检测器 API,可使用 Python 编写自定义分析
  • 能够分析使用 Solidity >= 0.4 编写的合约
  • 中间表示(SlithIR)实现简单、高精度的分析
  • 正确解析 99.9% 的公开 Solidity 代码
  • 每个合约的平均执行时间不到 1 秒
  • CI 中与 Github 的代码扫描集成
  • 支持 Vyper 智能合约

使用

在 Hardhat/Foundry/Dapp/Brownie 应用程序上运行 Slither:```console slither .

如果你的项目有依赖项,这是首选选项,因为 Slither 依赖于底层编译框架来编译源代码。

不过,你也可以在单个不导入依赖的文件上运行 Slither:```console
slither tests/uninitialized.sol

如何安装

注意 Slither 需要 Python 3.10+。 如果您打算使用 支持的编译框架,则需要 solc 即 Solidity 编译器;我们推荐使用 solc-select 来方便地在不同 solc 版本间切换。

使用 uv(推荐)

uv 是一个快速的 Python 包管理器,速度比 pip 快 10 到 100 倍。```console

Install uv if you haven't already

curl -LsSf https://astral.sh/uv/install.sh | sh

Install slither as a tool

uv tool install slither-analyzer

Or run slither without installation

uvx --from slither-analyzer slither

升级:```console
uv tool upgrade slither-analyzer

使用 Pip```console

python3 -m pip install slither-analyzer

要升级:```console
python3 -m pip install --upgrade slither-analyzer

使用 Brew```console

brew install slither-analyzer

### 使用 Git(开发)```bash
git clone https://github.com/crytic/slither.git && cd slither

# Install as editable for development
uv tool install -e .

# Or use uv run for testing without installation
uv run slither <target>

The -e flag installs in editable mode, meaning changes to the source code are immediately reflected without reinstalling.

使用 Docker

使用 eth-security-toolbox Docker 镜像。它在一个镜像中包含了我们所有的安全工具和每个主要版本的 Solidity。/home/share 将被挂载到容器内的 /share。```bash docker pull trailofbits/eth-security-toolbox

为了在容器中共享一个目录:```bash
docker run -it -v /home/share:/share trailofbits/eth-security-toolbox

集成

  • 对于 GitHub Action 集成,请使用 slither-action
  • 对于 pre-commit 集成,请使用(将 $GIT_TAG 替换为实际标签) ```YAML
  • 要生成Markdown报告,使用 slither [target] --checklist
  • 要生成带有GitHub源代码高亮的Markdown报告,使用 slither [target] --checklist --markdown-root https://github.com/ORG/REPO/blob/COMMIT/(替换 ORGREPOCOMMIT

检测器

编号检测器检测内容影响置信度
1abiencoderv2-array存储型 abiencoderv2 数组
2arbitrary-send-erc20transferFrom 使用任意的 from
3array-by-reference按值修改存储数组
4encode-packed-collisionABI encodePacked 碰撞
5incorrect-shift移位指令中参数顺序错误。
6multiple-constructors多个构造函数模式
7name-reused合约名称被重复使用
8protected-vars检测到未受保护的变量
9public-mappings-nested具有嵌套变量的公共映射
10rtlo使用了从右到左覆盖控制字符
11shadowing-state状态变量遮蔽
12suicidal允许任何人销毁合约的函数
13uninitialized-state未初始化的状态变量
14uninitialized-storage未初始化的存储变量
15unprotected-upgrade未受保护的可升级合约
16arbitrary-send-erc20-permittransferFrom 使用任意的 from 与 permit
17arbitrary-send-eth将以太币发送到任意目标的函数
18controlled-array-length受污染的数组长度赋值
19controlled-delegatecall受控的 delegatecall 目标
20delegatecall-loop在循环中使用 delegatecall 的可支付函数
21incorrect-exp不正确的指数运算
22incorrect-return在汇编模式下错误地使用了 return
23msg-value-loop循环中的 msg.value
24reentrancy-eth重入漏洞(窃取以太币)
25reentrancy-balance导致余额检查过时的重入漏洞
26return-leave使用 return 代替了 leave
27storage-array有符号存储整数数组编译器错误
28unchecked-transfer未检查的代币转账
29weak-prng弱 PRNG
30domain-separator-collision检测到 ERC20 代币中函数的签名与 EIP-2612 的 DOMAIN_SEPARATOR() 发生碰撞
31enum-conversion检测危险的枚举类型转换
32erc20-interface不正确的 ERC20 接口
33erc721-interface不正确的 ERC721 接口
34incorrect-equality危险的严格相等比较
35locked-ether锁定以太币的合约
36mapping-deletion对包含结构的映射进行删除操作
37pyth-deprecated-functions检测 Pyth 已弃用的函数
38pyth-unchecked-confidence检测到未检查 Pyth 价格的置信度级别
39pyth-unchecked-publishtime检测到未检查 Pyth 价格的 publishTime
40shadowing-abstract来自抽象合约的状态变量遮蔽
41tautological-compare变量与自身进行比较,根据比较类型总是返回 true 或 false
42tautology永真或矛盾
43write-after-write未使用的写入
44boolean-cst布尔常量的误用
45chronicle-unchecked-price检测到未检查 Chronicle 价格。
46constant-function-asm使用汇编代码的常量函数
47constant-function-state改变状态的常量函数
48divide-before-multiply不精确的算术运算顺序
49gelato-unprotected-randomness在未受保护的函数中调用 _requestRandomness
50out-of-order-retryable无序的可重试交易
51reentrancy-no-eth重入漏洞(未窃取以太币)
52reused-constructor重复使用的基构造函数
53tx-origin危险的 tx.origin 用法
54unchecked-lowlevel未检查的低级调用
55unchecked-send未检查的 send
56uninitialized-local未初始化的局部变量
57unused-return未使用的返回值
58chainlink-feed-registry检测到使用了 Chainlink feed registry
59incorrect-modifier可能返回默认值的修饰符
60optimism-deprecation检测到使用了已弃用的 Optimism 预部署或函数。
61shadowing-builtin内建符号遮蔽
62shadowing-local局部变量遮蔽
63uninitialized-fptr-cst构造函数中未初始化的函数指针调用
64variable-scope在声明之前使用的局部变量
65void-cst构造函数调用未实现
66calls-loop循环中的多次调用
67events-access缺少事件-访问控制
68events-maths缺少事件-算术运算
69incorrect-unary危险的一元表达式
70missing-zero-check缺少零地址验证
71reentrancy-benign良性重入漏洞
72reentrancy-events导致事件乱序的重入漏洞
73return-bomb低级被调用者可能意外消耗所有调用者的 gas。
74timestamp危险的 block.timestamp 用法
75assembly汇编代码使用信息
76assert-state-change断言状态变更信息
77boolean-equal与布尔常量比较信息
78cyclomatic-complexity检测圈复杂度高(>11)的函数信息
79deprecated-standards已弃用的 Solidity 标准信息
80erc20-indexed未索引的 ERC20 事件参数信息
81function-init-state函数初始化状态变量信息
82incorrect-using-for检测 using-for 语句中,给定库没有函数匹配给定类型信息
83low-level-calls低级调用信息
84missing-inheritance缺少继承信息
85naming-convention符合 Solidity 命名约定信息
86pragma使用了不同的 pragma 指令信息
87redundant-statements冗余语句信息
88solc-version不正确的 Solidity 版本信息
89unimplemented-functions未实现的函数信息
90unindexed-event-address包含地址参数但无索引参数的事件信息
91unused-state未使用的状态变量信息
92costly-loop循环中的昂贵操作信息
93dead-code未使用的函数信息
94reentrancy-unlimited-gas通过 send 和 transfer 的重入漏洞信息
95too-many-digits符合数值记法最佳实践信息
96cache-array-length检测在循环条件中使用某些存储数组的 length 成员且未修改它的 for 循环。优化
97constable-states可声明为常量的状态变量优化
98external-function可声明为 external 的 public 函数优化
99immutable-states可声明为 immutable 的状态变量优化
100var-read-using-this合约使用 this 读取自身的变量优化

更多信息,请参见:

输出器

快速概览输出器

深入审查输出器* call-graph: 将合约的调用图导出为 dot 文件

要运行打印机,请使用 --print 和逗号分隔的打印机列表。

参见 打印机文档 获取完整列表。

工具

参见 工具文档 获取更多工具。

联系我们 以获取构建自定义工具的帮助。

API 文档

Slither 内部文档可在 此处 获取。

获取帮助

欢迎访问我们的 Slack 频道 (#ethereum) 以获取使用或扩展 Slither 的帮助。

常见问题解答

如何排除模拟或测试?

如何解决“未知文件”或编译问题?

  • 由于 slither 需要 solc AST,它必须具备所有依赖关系。 如果一个合约有依赖关系,slither contract.sol 会失败。 相反,在 contracts/ 的父目录中使用 slither .(当你运行 ls 时应该能看到 contracts/)。 如果你有 node_modules/ 文件夹,它必须与 contracts/ 位于同一目录。为了验证此问题是否与 slither 相关, 运行你正在使用的框架的编译命令,例如 npx hardhat compile。该命令必须成功执行; 否则,slither 的编译引擎 crytic-compile 无法生成 AST。

许可证

Slither 根据 AGPLv3 许可证授权和分发。如果你正在寻找许可证条款的例外情况,请联系我们

出版文章

Trail of Bits 出版文章

外部出版文章

标题用途作者会议/期刊代码
ReJection: A AST-Based Reentrancy Vulnerability Detection Method基于AST的分析,构建于Slither之上Rui Ma, Zefeng Jian, Guangyuan Chen, Ke Ma, Yujia ChenCTCIS 19-
MPro: Combining Static and Symbolic Analysis for Scalable Testing of Smart Contract通过Slither利用数据依赖关系William Zhang, Sebastian Banescu, Leodardo Pasos, Steven Stewart, Vijay GaneshISSRE 2019MPro
ETHPLOIT: From Fuzzing to Efficient Exploit Generation against Smart Contracts通过Slither利用数据依赖关系Qingzhao Zhang, Yizhuo Wang, Juanru Li, Siqi MaSANER 20-
Verification of Ethereum Smart Contracts: A Model Checking Approach基于Slither的CFG构建符号执行Tam Bang, Hoang H Nguyen, Dung Nguyen, Toan Trieu, Tho QuanIJMLC 20-
Smart Contract Repair依赖Slither的漏洞检测器Xiao Liang Yu, Omar Al-Bataineh, David Lo, Abhik RoychoudhuryTOSEM 20SCRepair
Demystifying Loops in Smart Contracts通过Slither利用数据依赖关系Ben Mariano, Yanju Chen, Yu Feng, Shuvendu Lahiri, Isil DilligASE 20-
Trace-Based Dynamic Gas Estimation of Loops in Smart Contracts使用Slither的CFG检测循环Chunmiao Li, Shijie Nie, Yang Cao, Yijun Yu, Zhenjiang HuIEEE Open J. Comput. Soc. 1 (2020)-
SAILFISH: Vetting Smart Contract State-Inconsistency Bugs in Seconds依赖SlithIR构建存储依赖图Priyanka Bose, Dipanjan Das, Yanju Chen, Yu Feng, Christopher Kruegel, and Giovanni VignaS&P 22Sailfish
SolType: Refinement Types for Arithmetic Overflow in Solidity使用Slither作为前端构建细化类型系统Bryan Tan, Benjamin Mariano, Shuvendu K. Lahiri, Isil Dillig, Yu FengPOPL 22-
Do Not Rug on Me: Leveraging Machine Learning Techniques for Automated Scam Detection使用Slither提取代币特征(可铸造、可暂停等)Mazorra, Bruno, Victor Adan, and Vanesa DazaMathematics 10.6 (2022)-
MANDO: Multi-Level Heterogeneous Graph Embeddings for Fine-Grained Detection of Smart Contract Vulnerabilities使用Slither提取CFG和调用图Hoang Nguyen, Nhat-Minh Nguyen, Chunyao Xie, Zahra Ahmadi, Daniel Kudendo, Thanh-Nam Doan and Lingxiao JiangIEEE 9th International Conference on Data Science and Advanced Analytics (DSAA, 2022)ge-sc
Automated Auditing of Price Gouging TOD Vulnerabilities in Smart Contracts使用Slither提取CFG和数据依赖关系Sidi Mohamed Beillahi, Eric Keilty, Keerthi Nelaturu, Andreas Veneris, and Fan Long2022 IEEE International Conference on Blockchain and Cryptocurrency (ICBC)Smart-Contract-Repair
Modeling and Enforcing Access Control Policies for Smart Contracts扩展Slither的数据依赖关系Jan-Philipp Toberg, Jonas Schiffl, Frederik Reiche, Bernhard Beckert, Robert Heinrich, Ralf ReussnerIEEE International Conference on Decentralized Applications and Infrastructures (DAPPS), 2022SolidityAccessControlEnforcement
Smart Contract Vulnerability Detection Based on Deep Learning and Multimodal Decision Fusion使用Slither提取CFGWeichu Deng, Huanchun Wei, Teng Huang, Cong Cao, Yun Peng, and Xuan HuSensors 2023, 23, 7246-
Semantic-enriched Code Knowledge Graph to Reveal Unknowns in Smart Contract Code Reuse使用Slither提取代码特征(CFG、函数、参数类型等)Qing Huang, Dianshu Liao, Zhenchang Xing, Zhengkang Zuo, Changjing Wang, Xin XiaACM Transactions on Software Engineering and Methodology, 2023-
Smart Contract Parallel Execution with Fine-Grained State Accesses使用Slither构建状态访问图Xiaodong Qi, Jiao Jiao, Yi LiInternational Conference on Distributed Computing Systems (ICDCS), 2023-
Bad Apples: Understanding the Centralized Security Risks in Decentralized Ecosystems在Slither之上实现内部分析Kailun Yan , Jilian Zhang , Xiangyu Liu , Wenrui Diao , Shanqing GuoACM Web Conference April 2023-
Identifying Vulnerabilities in Smart Contracts using Interval Analysis在Slither之上创建4个检测器Ştefan-Claudiu Susan, Andrei ArusoaieFROM 2023-
Storage State Analysis and Extraction of Ethereum Blockchain Smart Contracts (no PDF in open access)依赖Slither的CFG和ASTMaha Ayub , Tania Saleem , Muhammad Janjua , Talha AhmadTOSEM 2023SmartMuv

如果你在学术工作中使用 Slither,考虑申请 Crytic $10k 研究奖

分类