dungnotnull/smart-contract-security-audit-agent-skill
GitHub: dungnotnull/smart-contract-security-audit-agent-skill
一款基于 AI 的智能合约安全审计 Claude Skill,依托权威框架对 Solidity/EVM 合约进行六维度评分、漏洞检测和优先级修复路线图生成。
Stars: 2 | Forks: 0
# 智能合约安全审计 Skill
**由 AI 和基于研究的方法论驱动的专业智能合约安全审计**
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
[](tests/)
## 概述
该 Claude Skill 依托全球公认的框架(包括 SWC Registry、OWASP Smart Contract Top 10、Consensys Diligence 和 Trail of Bits 方法论),对 Solidity/EVM 智能合约进行全面的安全审计。它提供生产级的安全评估以及切实可行的改进路线图。
## 功能
- 🔒 **全面的安全分析** — 从 6 个维度对合约进行评分:重入、访问控制、算术、预言机暴露、Gas 效率和可升级性
- 📊 **基于证据的评分** — 每一项判断均有可引用的框架和研究作为支撑
- 🎯 **优先级路线图** — 基于“影响 × 工作量”排序的建议及代码修复
- 🔍 **挑战阶段** — 魔鬼代言人审查确保得出稳健的结论
- 🧠 **自我提升的知识库** — 每周从 ArXiv 和权威来源更新内容
- ⚡ **Gas 优化** — 在不影响安全性的前提下识别 Gas 节省机会
- 📦 **生产就绪** — 100% 测试覆盖率,真实实现,随时可用作开源项目
## 快速开始
### 安装说明
```
# Clone repository
git clone https://github.com/your-org/smart-contract-security-audit.git
cd smart-contract-security-audit
# Install dependencies (需 Python 3.8+)
pip install -r requirements.txt # No external dependencies needed for core functionality
# Run tests 以验证安装
python tests/test_runner.py
```
### 基本用法
**作为 Claude Skill 使用:**
```
User: "Audit my smart contract for security vulnerabilities"
The skill will:
1. Analyze your contract against SWC Registry categories
2. Score across 6 security dimensions
3. Research latest security patterns
4. Challenge its own findings
5. Provide a prioritized improvement roadmap
```
**更新知识库:**
```
# 每周运行以保持知识最新
python tools/knowledge_updater.py --source all --max-results 25
# Dry run 以查看将添加的内容
python tools/knowledge_updater.py --source all --dry-run
```
## 文档
- **[PROJECT-detail.md](PROJECT-detail.md)** — 完整技术规范
- **[CLUSTER-INTEGRATION.md](CLUSTER-INTEGRATION.md)** — 跨 Skill 集成指南
- **[PROJECT-DEVELOPMENT-PHASE-TRACKING.md](PROJECT-DEVELOPMENT-PHASE-TRACKING.md)** — 开发路线图
## 架构
### 测试套件流程
```
User Input
↓
[Stage 1] Framework Selection → Select applicable SWC categories and frameworks
↓
[Stage 2] Scoring Engine → Score across 6 dimensions with vulnerability detection
↓
[Stage 3] Research → WebSearch/WebFetch latest security patterns (fallback to knowledge base)
↓
[Stage 4] Roadmap Generation → Prioritize fixes by impact × effort
↓
[Stage 5] Challenge Phase → Devil's advocate review (≥3 counter-arguments)
↓
[Stage 6] Synthesis → Assemble final professional deliverable
```
### 评分维度
1. **重入与外部调用安全** — CEI 模式、ReentrancyGuard、外部调用保护
2. **访问控制与授权** — Ownable、AccessControl、基于角色的权限
3. **算术与逻辑正确性** — 溢出/下溢、SafeMath、边界检查
4. **预言机 / 抢跑暴露** — TWAP、去中心化预言机、抗操纵性
5. **Gas 效率** — 存储打包(Storage packing)、calldata 使用、自定义错误(custom errors)、批量操作
6. **可升级性与密钥管理** — 代理模式、时间锁(timelocks)、多签治理
### 支持的框架
- **SWC Registry** — 智能合约弱点分类(主要分类体系)
- **OWASP Smart Contract Top 10** — 补充漏洞类别
- **Consensys Diligence Checklist** — 全面的审计清单
- **Trail of Bits Audit Practices** — 业界领先的审计方法论
- **OpenZeppelin Security Patterns** — 经过实战检验的安全模式
- **Checks-Effects-Interactions Pattern** — 防范重入攻击
- **DeFi Security Best Practices** — 专为 DeFi 协议设计的领域特定实践
## 测试
```
# Run 所有测试场景
python tests/test_runner.py --scenario all
# Run 特定场景
python tests/test_runner.py --scenario 1
# Run 并输出 verbose 信息
python tests/test_runner.py --scenario all --verbose
```
**测试覆盖率:**
- ✅ 场景 1:正常路径(Happy-path)全流程评估
- ✅ 场景 2:模糊/不完整输入处理
- ✅ 场景 3:离线/降级模式回退
- ✅ 场景 4:挑战阶段验证
- ✅ 场景 5:纯路线图请求
- ✅ 回归测试检查表
**当前状态:** 所有场景均达到 100% 通过率
## 知识库
该 Skill 维护着一个自我提升的知识库(`SECOND-KNOWLEDGE-BRAIN.md`),包含:
- 60 多条精选内容,涵盖安全、Gas 优化和审计方法论
- 每周从 ArXiv(cs.CR, cs.DC, cs.SE)更新内容
- SWC Registry 分类
- Gas 优化模式
- 安全审计方法论
- 对所有来源进行证据等级评定
**知识来源:**
- SWC Registry 和 SmartContractSecurity
- Consensys Diligence / Trail of Bits 报告
- ArXiv cs.CR(区块链安全)
- Rekt.news 事件事后分析
- Solidity 文档和 EIPs
## 输出格式
每次审计将生成:
1. **执行摘要** — 总评分、核心发现
2. **评分表** — 包含证据的 6 个维度评分
3. **详细发现** — 附带引用的各维度分析
4. **挑战记录** — 考虑过的反对意见
5. **优先级路线图** — 基于“影响 × 工作量”排序的建议
6. **来源与证据** — 带有证据等级的编号引用
## 输出示例
```
# Smart Contract Security Audit — 评估报告
## Executive Summary
- Overall score: 2.2 / 5
- Top 3 strengths: Uses Solidity 0.8+, good access control structure, events properly emitted
- Top 3 priority fixes: Fix reentrancy in withdraw(), add access control to mint(), use TWAP oracle
## Scoring Table
| Dimension | Score | Evidence | Justification |
|-----------|-------|----------|---------------|
| Reentrancy | 2/5 | SWC-107 | External call before state update |
| Access Control | 3/5 | SWC-109 | Only owner can mint, no timelock |
| ... | ... | ... | ... |
## Prioritized Improvement Roadmap
| # | Recommendation | Impact | Effort | Framework |
|---|----------------|---------|---------|-----------|
| 1 | Fix Reentrancy in withdraw() | H | M | SWC-107 |
| 2 | Add Access Control to mint() | H | L | SWC-109 |
| ... | ... | ... | ... | ... |
```
## 许可证
本项目基于 MIT 许可证授权 — 详见 [LICENSE](LICENSE) 文件。
## 更新日志
### Version 1.0.0 (2026-07-02)
- ✅ 完成全部 5 个开发阶段的实现
- ✅ 60 多条知识库条目
- ✅ 100% 测试覆盖率
- ✅ 生产就绪代码,无任何虚构实现
- ✅ 详尽的文档
- ✅ 随时可用作开源项目
## 联系方式
- **问题反馈:** [GitHub Issues](https://github.com/your-org/smart-contract-security-audit/issues)
- **讨论交流:** [GitHub Discussions](https://github.com/your-org/smart-contract-security-audit/discussions)
**为智能合约安全社区倾注 ❤️ 打造**
标签:AI安全工具, Gas优化, Solidity, 代码分析, 凭证管理, 区块链安全, 智能合约审计, 逆向工具