Demeter-Financial-Labs/claude-solidity-security
GitHub: Demeter-Financial-Labs/claude-solidity-security
这是一个Claude Code技能,用于对Solidity智能合约进行基于OWASP标准的安全审计,帮助识别和修复漏洞。
Stars: 2 | Forks: 0
# claude solidity 安全



一项用于审计 Solidity 智能合约的 Claude Code 技能,基于 [OWASP 智能合约安全验证标准 (SCSVS v0.0.1)](https://owasp.org/www-project-smart-contract-security/) 和 [智能合约安全测试指南 (SCSTG v0.0.1)](https://owasp.org/www-project-smart-contract-security/) 构建。
## 安装说明
**1. 克隆或下载此仓库:**
```
git clone ~/smart-contract-security-skill
# 或将文件夹放在您喜欢的任何位置
```
**2. 向 Claude Code 注册此技能:**
```
python3 - <<'PY'
import json, datetime
settings_path = "/home//.claude/settings.json"
plugins_path = "/home//.claude/plugins/installed_plugins.json"
skill_path = "/path/to/smart-contract-security-skill"
with open(plugins_path) as f:
installed = json.load(f)
now = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%S.000Z")
installed["plugins"]["smart-contract-security@local"] = [{
"scope": "user",
"installPath": skill_path,
"version": "1.0.0",
"installedAt": now,
"lastUpdated": now,
"gitCommitSha": "local"
}]
with open(plugins_path, "w") as f:
json.dump(installed, f, indent=2)
with open(settings_path) as f:
settings = json.load(f)
settings.setdefault("enabledPlugins", {})["smart-contract-security@local"] = True
with open(settings_path, "w") as f:
json.dump(settings, f, indent=2)
print("Done.")
PY
```
**3. 安装可选的静态分析工具:**
```
pip install slither-analyzer # primary static analyzer
pip install mythril # symbolic execution
brew install foundry # or: curl -L https://foundry.paradigm.xyz | bash
```
**4. 重启 Claude Code。** 此技能现在在每个会话中都可用。
## 使用方法
在会话开始时调用此技能:
```
/smart-contract-security
```
然后自然地描述你的任务——技能会自动检测适当的模式。
## 两种模式
### 审计模式
用于正式的安全评估。由 *“审计”*、*“完整审查”*、*“SCSVS 报告”* 等关键词触发。
运行一个完整的6阶段流水线:
1. 合约接收与分类(13种合约类型)
2. 自动化静态分析(Slither + Mythril + Foundry)
3. 按领域进行手动审查(所有11个SCSVS领域)
4. 漏洞评分(严重/高/中/低)
5. 生成包含SCSVS合规矩阵的结构化报告
6. 修复验证
### 开发模式
用于快速的内联代码审查。由 *“检查这个”*、*“这个安全吗?”*、粘贴代码触发。
运行一个前10项的即时分诊,并返回:
```
⚠️ [SEVERITY] Issue title
SCSVS: S3.3.A4
Line: 142
Problem: State updated after external call
Fix:
```
## 覆盖范围
涵盖所有11个SCSVS领域,每个领域都有完整的需求表和SCSTG测试方法(易受攻击代码 → 修复代码 → 如何检查):
| 领域 | 代码 | 主题 |
|--------|------|--------|
| 架构与威胁建模 | S1 | 代理模式、存储冲突、升级授权、威胁建模 |
| 策略与代码管理 | S2 | 编译器版本、弃用函数、NatSpec、测试覆盖 |
| 业务逻辑与经济安全 | S3 | 重入(CEI、修饰符顺序)、拉/推提币、代币经济学 |
| 访问控制 | S4 | RBAC、tx.origin、EIP-712、多重签名、Merkle 白名单 |
| 安全交互 | S5 | 外部调用、预言机数据源、跨链消息传递、桥接 |
| 密码学实践 | S6 | ecrecover、签名可塑性、Chainlink VRF、nonce |
| 算术与逻辑安全 | S7 | 溢出/下溢、定点数、闪电贷数学、舍入方向 |
| 拒绝服务 | S8 | 无界循环、gas 损耗、阻塞模式、try/catch |
| 区块链数据与状态管理 | S9 | ETH 锁定、存储损坏、ZK 证明、事件日志 |
| Gas 使用与效率 | S10 | 存储打包、calldata、L2 解决方案、重组确认 |
| 组件特定安全 | S11 | ERC20/721/1155、NFT、金库、stETH rebase、AMM、Uniswap V4 |
## 静态分析脚本
```
# 运行 Slither 并生成 JSON 输出
bash scripts/slither-scan.sh ./contracts
# 将 Slither 发现映射
python3 scripts/parse-findings.py slither-output.json
```
`parse-findings.py` 将约40个 Slither 检测器确定性地映射到 SCSVS ID,从而在审计轮次之间产生可重现的合规性差异。
## 文件结构
```
skills/smart-contract-security/
├── SKILL.md # Mode detection + routing
├── references/
│ ├── audit-workflow.md # Formal audit pipeline
│ ├── dev-workflow.md # Quick-check workflow + fix patterns
│ ├── taxonomy.md # 13 contract types + risk matrix
│ └── domains/
│ ├── arch.md (S1)
│ ├── code.md (S2)
│ ├── gov.md (S3)
│ ├── auth.md (S4)
│ ├── comm.md (S5)
│ ├── crypto.md (S6)
│ ├── arith.md (S7)
│ ├── dos.md (S8)
│ ├── state.md (S9)
│ ├── gas.md (S10)
│ └── comp.md (S11)
└── scripts/
├── slither-scan.sh
└── parse-findings.py
```
## 参考标准
- **SCSVS v0.0.1** — 智能合约安全验证标准(OWASP,2024)
- **SCSTG v0.0.1** — 智能合约安全测试指南(OWASP,2024)
- **EIP-712** — 类型化结构化数据哈希与签名
- **EIP-1967** — 标准代理存储槽
- **ERC-4626** — 代币化金库标准
标签:Claude Code, OWASP SCSVS, Slither, Solidity, 云安全监控, 以太坊, 区块链安全, 区块链开发, 智能合约安全, 服务器监控, 符号执行, 逆向工具, 静态分析