关于 solana-audit
solana-audit 是一项审查 Solana 程序安全漏洞的技能,组织代码探索、并行或组合扫描、发现项验证及结构化审计报告。
主要功能
- 01设置审计范围和深度
- 02梳理程序结构与威胁模型
- 03按类别扫描漏洞
- 04验证并排列候选发现项
- 05生成结构化审计报告
- 06可选保存审计结果
适用场景
- 01审计 Solana 程序仓库
- 02将发现项与已接受风险对照
- 03报告并排列漏洞候选项
- 04留存审计结果供后续复查
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ workersio/ skills --skill solana-audit安装后在 Claude Code 中输入/solana-audit确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/CHEATSHEET.mdaccount-closure-vulnerability.mdaccount-not-initialized.mdanchor-specific.mdarbitrary-cpi-target.mdaudit-checklist.mddivision-precision-loss.mdduplicate-mutable-accounts.mdexploit-case-studies.mdinstruction-access-control.mdinteger-overflow-underflow.mdmissing-authority-validation.mdmissing-bump-canonicalization.mdmissing-owner-check.mdmissing-signer-check.mdmissing-slippage-check.mdoracle-manipulation.mdpda-seed-collision.mdprivilege-escalation.mdreinitialization.mdreferences/agents/adversarial-scanner.mdauth-state-scanner.mdcpi-math-scanner.mdexplorer.mdframework-scanner.mdlogic-economic-scanner.mdreferences/protocols/bridge-protocol.mddex-amm-protocol.mdlending-protocol.mdstaking-protocol.md详细介绍
Solana 智能合约审计
触发条件
当用户要求以下操作时,启用此技能:
- 对 Solana 程序进行安全审计、审查或分析
- 检查 Solana 智能合约是否存在漏洞或可利用的问题
- 对包含
solana_program、anchor_lang、pinocchio、#[program]或#[derive(Accounts)]的代码进行安全分析
工作流
阶段 0:设置与配置
扫描前,确定审计范围并检查是否存在先前数据。
步骤 1 — 向用户询问 3 个配置问题(如果用户说“直接审计”或类似表述,则跳过):
- 范围: 要审计哪些程序?(默认:仓库中的所有 Solana 程序)
- 示例答案:“全部”“只审计 vault 程序”“programs/staking 和 programs/rewards”
- 深度: 标准还是深度?标准模式会并行运行 4 个扫描 Agent。深度模式会增加第 5 个对抗性 Agent 进行交叉验证。(默认:标准)
- 已知约束: 是否有已接受的风险或信任假设?(默认:无)
- 示例答案:“管理员是 3/5 多签”“我们接受升级权限风险”“暂时忽略 token-2022”
步骤 2 — 存储配置:
如果 ${CLAUDE_PLUGIN_DATA} 可用:
- 读取
${CLAUDE_SKILL_DIR}/references/templates/config-template.json,了解其架构 - 将用户的答案写入
${CLAUDE_PLUGIN_DATA}/config.json - 检查是否存在先前的审计数据:
${CLAUDE_PLUGIN_DATA}/audit-log.jsonl— 如果文件存在且包含同一程序的记录,告知用户:“发现此前于 [date] 进行的审计。报告了 [N] 个发现。”${CLAUDE_PLUGIN_DATA}/accepted-risks.json— 如果文件存在,则加载已接受的风险,以便在阶段 3 进行交叉比对
如果 ${CLAUDE_PLUGIN_DATA} 不可用,则继续操作,不保存数据。不要报错或警告——直接静默跳过。
默认值(如果用户跳过配置):范围=所有程序,深度=标准,无已知约束。
阶段 1:探索
阅读 references/agents/explorer.md,并使用 Agent 工具启动探索 Agent。
如何构造 Agent 调用:
- 读取文件
${CLAUDE_SKILL_DIR}/references/agents/explorer.md。Agent 提示词是## Agent Prompt部分中三个反引号围栏之间的文本。 - 在提示词中,将
[Insert: repository path or "full codebase scan"]替换为实际目标路径(取自阶段 0 的范围,或仓库根目录)。 - 启动 Agent:
Agent(subagent_type="Explore", prompt="<the filled-in prompt>")
它会返回:程序映射、指令列表、账户结构、PDA 映射、CPI 图、协议类型分类、LOC 计数和威胁模型。
必须启动此 Agent,并在继续之前等待其输出。探索结果会作为共享上下文传递给每个扫描 Agent。
自适应规模
探索 Agent 返回后,确定程序规模并选择扫描策略:
| 规模 | 标准 | 扫描策略 |
|---|---|---|
| 小型 | <500 LOC 且 <5 条指令 | 使用一个组合扫描 Agent 覆盖所有类别(A 至 R)。在提示词中直接包含 CHEATSHEET 中的所有漏洞检查项。无需使用单独的 Agent 文件。 |
| 中型 | 500–2000 LOC | 标准的 4 个 Agent 并行扫描(见下方阶段 2) |
| 大型 | >2000 LOC | 标准的 4 个 Agent 并行扫描。告知用户:“这是一个大型程序。建议使用 depth: deep 运行,以进行对抗性交叉验证。” |
对于小型程序,构造一个 Agent 提示词,并执行以下操作:
- 将探索结果作为上下文
- 引用
${CLAUDE_SKILL_DIR}/references/scoring.md中的评分规则 - 引用
${CLAUDE_SKILL_DIR}/references/CHEATSHEET.md中的全部 30 种漏洞类型 - 指示 Agent 一次扫描所有类别(A-1 至 R-3)
- 使用与各扫描 Agent 相同的输出格式
- 然后跳转到阶段 3,并使用该 Agent 的输出
对于中型和大型程序,继续进入阶段 2。
阶段 2:并行扫描
预扫描:语法扫描
在启动扫描器 Agent 之前,运行整合后的语法扫描:
- 阅读
${CLAUDE_SKILL_DIR}/references/scripts/scan-commands.md - 对目标程序目录执行 grep 命令
- 按类别(A、S、C、M、L、T、R)整理结果
- 统计每个类别的命中总数
将语法扫描结果传递给所有扫描器 Agent,并在其上下文开头添加以下说明:
编排器已完成第一轮(语法扫描)。结果如下。请直接进入第二轮——语义审查。
[在此粘贴按类别整理的语法扫描结果]
这样可以避免 4 个 Agent 重复执行 grep。
启动扫描器 Agent
阅读 references/scoring.md,了解置信度评分规则和误报门槛。然后阅读全部 4 个 Agent 提示词文件,并使用 4 次同时进行的 Agent 工具调用并行启动它们。
构造每个 Agent 调用的方法:
- 阅读 Agent 提示词文件(例如
${CLAUDE_SKILL_DIR}/references/agents/auth-state-scanner.md)。提示词是## Agent Prompt部分中三重反引号围栏之间的全部内容。 - 将
[INSERT EXPLORER OUTPUT HERE — the full codebase analysis from the explorer agent]替换为 explorer Agent 输出的完整原文。 - 将方括号中的引用路径(例如
[references/scoring.md])替换为以${CLAUDE_SKILL_DIR}为基准的绝对文件路径(例如${CLAUDE_SKILL_DIR}/references/scoring.md),以便 Agent 可以直接使用Read读取;不要将文件内容内联粘贴。 - 对于逻辑经济扫描器,根据 explorer 的分类填入协议类型,以便加载正确的协议参考资料。
- 将语法扫描结果(来自上述预扫描步骤)添加到每个 Agent 上下文的开头。
身份验证扫描器(references/agents/auth-state-scanner.md)
- 类别 A-1..A-5 + S-1..S-8 — 13 种漏洞类型
CPI 扫描器(references/agents/cpi-math-scanner.md)
- 类别 C-1..C-3 + M-1..M-4 — 7 种漏洞类型
逻辑扫描器(references/agents/logic-economic-scanner.md)
- 类别 L-1..L-4 + T-1..T-3 — 7 种漏洞类型
- 根据 explorer 的分类加载特定协议的参考资料
框架扫描器(references/agents/framework-scanner.md)
- 框架特定检查(Anchor/Native/Pinocchio)+ R-1..R-3
在单个响应中启动全部 4 个:
Agent(prompt="<auth-state-scanner prompt with explorer output + syntactic scan results inserted>")
Agent(prompt="<cpi-math-scanner prompt with explorer output + syntactic scan results inserted>")
Agent(prompt="<logic-economic-scanner prompt with explorer output + syntactic scan results inserted>")
Agent(prompt="<framework-scanner prompt with explorer output + syntactic scan results inserted>")
每个 Agent 都会返回候选项,包括分类 ID、文件:行号、证据、攻击路径、置信度评分和误报门槛结果。
深度模式(当用户要求进行全面/深度审计,或配置中的 depth=deep 时):4 个扫描器完成后,再根据 references/agents/adversarial-scanner.md 启动第 5 个对抗性 Agent。将 explorer 输出和合并后的扫描结果传递给它,以便进行交叉验证。
阶段 3:验证与证伪
- 合并所有 Agent 候选列表
- 去重(依据根本原因)——当两个 Agent 标记了相同的根本原因时,保留置信度较高的版本。如果它们标记的是相同位置,但分类 ID 不同,则两项都保留。
- 按置信度分数从高到低排序。重新按顺序编号(VULN-001、VULN-002……)。
- 检查已接受的风险——如果阶段 0 加载了
accepted-risks.json,请通过taxonomy_id+file交叉比对每项发现。将匹配的发现标记为“Previously Accepted”,并附上已存储的原因。报告中仍须包含这些发现,但不将其计为新发现。 - 证伪——每个 Agent 已应用误报判定门槛(具体路径、可触达入口、无缓解措施)。对于剩余候选项,再检查两项防御:
- 利用漏洞的成本是否高于攻击者可能获得的收益?(经济上不可行)
- 是否存在会阻断攻击路径的链下组件(keeper、多签、时间锁)? 如果任一防御成立,则删除该候选项或相应降低其置信度。
- 与 references/exploit-case-studies.md 交叉比对——这是否符合已知的漏洞利用模式?
- 对每项确认的发现,查阅其分类 ID 对应的单独参考文件(例如,references/missing-signer-check.md),了解详细的修复建议
- 使用 references/audit-checklist.md §严重性校准中的校准表评估严重性
对于 Anchor 程序,还应查阅 references/anchor-specific.md,了解框架特有的注意事项。
阶段 4:报告
生成最终审计报告。每项发现都必须包含来自 references/vulnerability-taxonomy.md 的分类 ID 和置信度分数。
如果存在一项或多项发现,请使用标准报告模板:
# Security Audit Report: [Program Name]
## Executive Summary
- Audit date, scope (files, instructions, LOC)
- Framework: Native / Anchor / Pinocchio
- Protocol type: [from explorer classification]
- Methods: Parallel agent scan (4 agents + adversarial), confidence-scored validation
- Finding counts by severity: X Critical, Y High, Z Medium, W Low, V Informational
- Confidence threshold: 75/100
## Methodology
- Phase 0: Scope configuration and prior audit check
- Phase 1: Codebase exploration (program map, CPI graph, threat model)
- Phase 2: Pre-scan syntactic analysis + parallel scan — 4 agents across 30 vulnerability types across 7 categories
- Phase 3: Merge, deduplicate by root cause, accepted risk check, devil's advocate falsification
- Phase 4: Confidence-scored report
- Reference: vulnerability taxonomy based on Wormhole, Cashio, Mango, Neodyme, Crema exploits
## Findings
### [CRITICAL] VULN-001: Title (Confidence: 95/100)
**File:** path/to/file.rs:line
**Category:** A-1 (Missing Signer Check)
**Description:** ...
**Attack Path:** caller → instruction → state change → impact
**Impact:** ...
**Recommendation:** ...
**Fix:**
```rust
// Remediation code (framework-specific)
```
### [HIGH] VULN-002: Title (Confidence: 80/100)
**File:** path/to/file.rs:line
**Category:** S-7 (Reinitialization)
...
---
### Below Confidence Threshold
---
### [MEDIUM] VULN-003: Title (Confidence: 60/100)
**File:** path/to/file.rs:line
**Category:** M-2 (Division Precision Loss)
**Description:** ...
**Impact:** ...
*(No fix recommendation — below confidence threshold)*
## Summary Table
| ID | Title | Severity | Category | Confidence | File | Status |
|---|---|---|---|---|---|---|
| VULN-001 | Missing Signer Check | Critical | A-1 | 95 | lib.rs:16 | Open |
| VULN-002 | Reinitialization | High | S-7 | 80 | lib.rs:11 | Open |
| --- | Below Confidence Threshold | --- | --- | <75 | --- | --- |
| VULN-003 | Division Precision Loss | Medium | M-2 | 60 | math.rs:45 | Open |
## Appendix
- Complete file listing reviewed
- Vulnerability taxonomy reference
- Explorer output (program map, CPI graph, threat model)
如果没有发现(审计结果干净),请使用以下替代模板:
# Security Audit Report: [Program Name]
## Executive Summary
- **Result: No vulnerabilities identified**
- Audit date, scope (files, instructions, LOC)
- Framework: Native / Anchor / Pinocchio
- Protocol type: [from explorer classification]
- Methods: Parallel agent scan (4 agents), confidence-scored validation
- Finding counts: 0 Critical, 0 High, 0 Medium, 0 Low, 0 Informational
## Methodology
- Phase 0: Scope configuration and prior audit check
- Phase 1: Codebase exploration (program map, CPI graph, threat model)
- Phase 2: Pre-scan syntactic analysis + parallel scan — 4 agents across 30 vulnerability types across 7 categories
- Phase 3: Merge, deduplicate, devil's advocate falsification
- Phase 4: Confidence-scored report
## Categories Reviewed
All 7 categories (30 vulnerability types) were scanned:
| Category | IDs | Types Checked | Findings |
|----------|-----|---------------|----------|
| A: Authentication & Authorization | A-1..A-5 | 5 | 0 |
| S: Account & State Management | S-1..S-8 | 8 | 0 |
| C: Cross-Program Invocation | C-1..C-3 | 3 | 0 |
| M: Arithmetic & Math | M-1..M-4 | 4 | 0 |
| L: Logic & Economic | L-1..L-4 | 4 | 0 |
| T: Token-Specific | T-1..T-3 | 3 | 0 |
| R: Runtime & Deployment | R-1..R-3 | 3 | 0 |
## Scope
- Files reviewed: [list]
- Instructions analyzed: [count]
- Lines of code: [LOC]
## Disclaimer
A clean audit report does not guarantee the absence of vulnerabilities. This audit covers the 30 vulnerability types in the solana-audit taxonomy and is limited to static analysis of the on-chain program source code. It does not cover:
- Off-chain components (frontends, keepers, bots)
- Economic modeling or game-theoretic analysis beyond basic checks
- Deployment configuration (actual on-chain upgrade authority, program data account state)
- Vulnerabilities outside the taxonomy scope
- Bugs introduced after the audit date
## Appendix
- Complete file listing reviewed
- Vulnerability taxonomy reference
- Explorer output (program map, CPI graph, threat model)
报告规则:
- 每项发现都必须有一行
**Category:**,其中包含分类 ID(例如,A-1、S-7、C-1) - 每项发现都必须有一个
**Confidence:**分数 - 置信度 >= 75 的发现必须包含框架特定的修复代码
- 置信度 < 75 的发现应列在 Below Confidence Threshold 分隔线下方,且不包含修复代码
- 在每个严重性分组内,按置信度从高到低排序
- 摘要表必须包含 Category 和 Confidence 列
- 建议必须包含框架特定的修复方法(例如,
Signer<'info>、Account<'info, T>、close = destination)
审计结果持久化
生成报告后,如果 ${CLAUDE_PLUGIN_DATA} 可用,请持久化审计结果:
- 阅读
${CLAUDE_SKILL_DIR}/references/templates/audit-log-schema.md以了解架构 - 向
${CLAUDE_PLUGIN_DATA}/audit-log.jsonl追加一行 JSONL,包含:时间戳、程序名称、路径、框架、协议类型、LOC、指令数量、深度、按严重性统计的发现数量、发现 ID 和分类 ID - 告知用户:“审计结果已保存。你可以将发现标记为已接受的风险,以供未来审计参考。”
如果 ${CLAUDE_PLUGIN_DATA} 不可用,则静默跳过。
后续步骤:形式化验证
对于涉及算术安全(M-1、M-2、M-3、M-4)、状态不变量(S-1 至 S-8)或授权逻辑(A-1 至 A-5)的 CRITICAL 或 HIGH 级别发现,建议使用 /kani-proof 进行形式化验证:
可进行形式化验证: 可使用
/kani-proof对[function_name()]中的发现 VULN-NNN([taxonomy_id]:[title])进行形式化验证,以证明修复正确且漏洞不会再次出现。
示例:“可使用 /kani-proof 对 calculate_reward() 中的发现 VULN-001(M-1:整数溢出)进行形式化验证,以证明在有界输入条件下所有算术运算都是安全的。”
这只是一项轻量级建议——不要因此阻碍报告生成。
参考资料
references/ 目录包含:
核心参考资料:
- CHEATSHEET.md — 涵盖全部 30 种漏洞类型的精简速查表,包含可用于 grep 的关键词(请先加载此文件)
- scoring.md — 误报门槛 + 置信度评分规则(所有 Agent 均会加载)
- vulnerability-taxonomy.md — 完整索引,链接到各个漏洞参考文件
- audit-checklist.md — 按指令分类的验证清单 + 语法 grep 命令
- anchor-specific.md — Anchor 框架特有的注意事项
- exploit-case-studies.md — 真实世界的 Solana 漏洞利用模式(损失超过 $500M)
扫描自动化:
- scripts/scan-commands.md — 预扫描阶段使用的汇总语法扫描命令
持久化模板:
- templates/config-template.json — 审计配置架构
- templates/audit-log-schema.md — 审计日志和已接受风险的架构
20 个单独的漏洞文件 — 每个文件都包含前置条件、易受攻击的模式、检测启发式规则、误报和修复方法
Agent 提示词(references/agents/):
- explorer.md — 第 1 阶段探索
- auth-state-scanner.md — 身份验证扫描器(类别 A + S)
- cpi-math-scanner.md — CPI 扫描器(类别 C + M)
- logic-economic-scanner.md — 逻辑扫描器(类别 L + T)
- framework-scanner.md — 框架扫描器(框架 + R)
- adversarial-scanner.md — DEEP 模式威胁建模
特定协议的参考资料(references/protocols/)—— 根据探索器的分类按需加载:
- lending-protocol.md — 抵押品、清算和利率模式
- dex-amm-protocol.md — 交换、LP 代币和 AMM 曲线模式
- staking-protocol.md — 奖励分配、纪元和委托模式
- bridge-protocol.md — 消息验证、重放和守护者模式