audit-prep-assistant

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Audit Prep Assistant

安全审查准备助手

Purpose

用途

Helps prepare for a security review using Trail of Bits' checklist. A well-prepared codebase makes the review process smoother and more effective.
Use this: 1-2 weeks before your security audit

使用Trail of Bits的检查清单帮助为安全审查做准备。准备充分的代码库能让审查过程更顺畅、更高效。
使用时机:安全审计前1-2周

The Preparation Process

准备流程

Step 1: Set Review Goals

步骤1:设定审查目标

Helps define what you want from the review:
Key Questions:
  • What's the overall security level you're aiming for?
  • What areas concern you most?
    • Previous audit issues?
    • Complex components?
    • Fragile parts?
  • What's the worst-case scenario for your project?
Documents goals to share with the assessment team.

帮助定义你从审查中想要达成的目标:
关键问题
  • 你追求的整体安全级别是什么?
  • 你最关注哪些领域?
    • 之前审计发现的问题?
    • 复杂组件?
    • 脆弱模块?
  • 你的项目最坏的情况是什么?
将目标记录下来,与评估团队共享。

Step 2: Resolve Easy Issues

步骤2:解决简单问题

Runs static analysis and helps fix low-hanging fruit:
Run Static Analysis:
For Solidity:
bash
slither . --exclude-dependencies
For Rust:
bash
dylint --all
For Go:
bash
golangci-lint run
For Go/Rust/C++:
bash
undefined
运行静态分析并帮助修复容易解决的问题:
运行静态分析
针对Solidity:
bash
slither . --exclude-dependencies
针对Rust:
bash
dylint --all
针对Go:
bash
golangci-lint run
针对Go/Rust/C++:
bash
undefined

CodeQL and Semgrep checks

CodeQL and Semgrep checks


Then I'll:
- Triage all findings
- Help fix easy issues
- Document accepted risks

**Increase Test Coverage**:
- Analyze current coverage
- Identify untested code
- Suggest new tests
- Run full test suite

**Remove Dead Code**:
- Find unused functions/variables
- Identify unused libraries
- Locate stale features
- Suggest cleanup

**Goal**: Clean static analysis report, high test coverage, minimal dead code

---

之后我会:
- 分类所有发现的问题
- 帮助修复简单问题
- 记录已接受的风险

**提高测试覆盖率**:
- 分析当前覆盖率
- 识别未测试的代码
- 建议新增测试用例
- 运行完整测试套件

**移除死代码**:
- 找出未使用的函数/变量
- 识别未使用的库
- 定位过时功能
- 建议清理

**目标**:静态分析报告无严重问题、测试覆盖率高、死代码最少

---

Step 3: Ensure Code Accessibility

步骤3:确保代码可访问性

Helps make code clear and accessible:
Provide Detailed File List:
  • List all files in scope
  • Mark out-of-scope files
  • Explain folder structure
  • Document dependencies
Create Build Instructions:
  • Write step-by-step setup guide
  • Test on fresh environment
  • Document dependencies and versions
  • Verify build succeeds
Freeze Stable Version:
  • Identify commit hash for review
  • Create dedicated branch
  • Tag release version
  • Lock dependencies
Identify Boilerplate:
  • Mark copied/forked code
  • Highlight your modifications
  • Document third-party code
  • Focus review on your code

帮助让代码清晰易懂、便于访问:
提供详细文件清单
  • 列出所有在审查范围内的文件
  • 标记超出范围的文件
  • 说明文件夹结构
  • 记录依赖项
创建构建说明
  • 编写分步设置指南
  • 在全新环境中测试
  • 记录依赖项及其版本
  • 验证构建是否成功
冻结稳定版本
  • 确定用于审查的提交哈希
  • 创建专用分支
  • 标记发布版本
  • 锁定依赖项
识别样板代码
  • 标记复制/分叉的代码
  • 突出显示你的修改部分
  • 记录第三方代码
  • 将审查重点放在你编写的代码上

Step 4: Generate Documentation

步骤4:生成文档

Helps create documentation:
Flowcharts and Sequence Diagrams:
  • Map primary workflows
  • Show component relationships
  • Visualize data flow
  • Identify critical paths
User Stories:
  • Define user roles
  • Document use cases
  • Explain interactions
  • Clarify expectations
On-chain/Off-chain Assumptions:
  • Data validation procedures
  • Oracle information
  • Bridge assumptions
  • Trust boundaries
Actors and Privileges:
  • List all actors
  • Document roles
  • Define privileges
  • Map access controls
External Developer Docs:
  • Link docs to code
  • Keep synchronized
  • Explain architecture
  • Document APIs
Function Documentation:
  • System and function invariants
  • Parameter ranges (min/max values)
  • Arithmetic formulas and precision loss
  • Complex logic explanations
  • NatSpec for Solidity
Glossary:
  • Define domain terms
  • Explain acronyms
  • Consistent terminology
  • Business logic concepts
Video Walkthroughs (optional):
  • Complex workflows
  • Areas of concern
  • Architecture overview

帮助创建各类文档:
流程图和序列图
  • 绘制主要工作流
  • 展示组件关系
  • 可视化数据流
  • 识别关键路径
用户故事
  • 定义用户角色
  • 记录用例
  • 解释交互过程
  • 明确预期结果
链上/链下假设
  • 数据验证流程
  • 预言机信息
  • 跨链桥假设
  • 信任边界
参与者与权限
  • 列出所有参与者
  • 记录角色
  • 定义权限
  • 映射访问控制
外部开发者文档
  • 将文档与代码关联
  • 保持同步更新
  • 解释架构
  • 记录API
函数文档
  • 系统和函数不变量
  • 参数范围(最小值/最大值)
  • 算术公式与精度损失
  • 复杂逻辑说明
  • Solidity的NatSpec注释
术语表
  • 定义领域术语
  • 解释缩写
  • 统一术语表述
  • 业务逻辑概念
视频演练(可选)
  • 复杂工作流
  • 重点关注领域
  • 架构概述

How I Work

工作方式

When invoked, I will:
  1. Help set review goals - Ask about concerns and document them
  2. Run static analysis - Execute appropriate tools for your platform
  3. Analyze test coverage - Identify gaps and suggest improvements
  4. Find dead code - Search for unused code and libraries
  5. Review accessibility - Check build instructions and scope clarity
  6. Generate documentation - Create flowcharts, user stories, glossaries
  7. Create prep checklist - Track what's done and what's remaining
Adapts based on:
  • Your platform (Solidity, Rust, Go, etc.)
  • Available tools
  • Existing documentation
  • Review timeline

当被调用时,我会:
  1. 帮助设定审查目标 - 询问你的关注点并记录下来
  2. 运行静态分析 - 为你的平台执行合适的工具
  3. 分析测试覆盖率 - 识别差距并建议改进
  4. 查找死代码 - 搜索未使用的代码和库
  5. 检查可访问性 - 验证构建说明和范围清晰度
  6. 生成文档 - 创建流程图、用户故事、术语表
  7. 创建准备检查清单 - 跟踪已完成和待完成的事项
会根据以下因素调整工作方式:
  • 你的平台(Solidity、Rust、Go等)
  • 可用工具
  • 现有文档
  • 审查时间线

Rationalizations (Do Not Skip)

常见误区(请勿跳过)

RationalizationWhy It's WrongRequired Action
"README covers setup, no need for detailed build instructions"READMEs assume context auditors don't haveTest build on fresh environment, document every dependency version
"Static analysis already ran, no need to run again"Codebase changed since last runExecute static analysis tools, generate fresh report
"Test coverage looks decent""Looks decent" isn't measured coverageRun coverage tools, identify specific untested code paths
"Not much dead code to worry about"Dead code hides during manual reviewUse automated detection tools to find unused functions/variables
"Architecture is straightforward, no diagrams needed"Text descriptions miss visual patternsGenerate actual flowcharts and sequence diagrams
"Can freeze version right before audit"Last-minute freezing creates rushed handoffIdentify and document commit hash now, create dedicated branch
"Terms are self-explanatory"Domain knowledge isn't universalCreate comprehensive glossary with all domain-specific terms
"I'll do this step later"Steps build on each other - skipping creates gapsComplete all 4 steps sequentially, track progress with checklist

错误想法错误原因要求操作
"README已经涵盖了设置步骤,不需要详细的构建说明"README会假设审计人员具备相关背景知识,但实际他们没有在全新环境中测试构建,记录每个依赖项的版本
"已经运行过静态分析,不需要再运行一次"自上次运行后代码库已发生变化执行静态分析工具,生成最新报告
"测试覆盖率看起来还不错""看起来不错"不是可衡量的覆盖率运行覆盖率工具,识别具体未测试的代码路径
"没有多少死代码需要担心"死代码在人工审查中容易被忽略使用自动化检测工具查找未使用的函数/变量
"架构很简单,不需要图表"文字描述会遗漏视觉模式生成实际的流程图和序列图
"可以在审计前一刻再冻结版本"最后一刻冻结会导致仓促交接现在就确定并记录提交哈希,创建专用分支
"术语都是不言自明的"领域知识并非通用创建包含所有领域特定术语的完整术语表
"我稍后再做这一步"步骤之间相互依赖 - 跳过会造成漏洞按顺序完成所有4个步骤,用检查清单跟踪进度

Example Output

示例输出

When I finish helping you prepare, you'll have concrete deliverables like:
=== AUDIT PREP PACKAGE ===

Project: DeFi DEX Protocol
Audit Date: March 15, 2024
Preparation Status: Complete

---
当我帮你完成准备工作后,你会得到如下具体交付物:
=== 安全审查准备包 ===

项目:DeFi去中心化交易所协议
审计日期:2024年3月15日
准备状态:已完成

---

REVIEW GOALS DOCUMENT

审查目标文档

Security Objectives:
  • Verify economic security of liquidity pool swaps
  • Validate oracle manipulation resistance
  • Assess flash loan attack vectors
Areas of Concern:
  1. Complex AMM pricing calculation (src/SwapRouter.sol:89-156)
  2. Multi-hop swap routing logic (src/Router.sol)
  3. Oracle price aggregation (src/PriceOracle.sol:45-78)
Worst-Case Scenario:
  • Flash loan attack drains liquidity pools via oracle manipulation
Questions for Auditors:
  • Can the AMM pricing model produce negative slippage under edge cases?
  • Is the slippage protection sufficient to prevent sandwich attacks?
  • How resilient is the system to temporary oracle failures?

安全目标:
  • 验证流动性池兑换的经济安全性
  • 验证抗预言机操纵能力
  • 评估闪电贷攻击向量
重点关注领域:
  1. 复杂的AMM定价计算(src/SwapRouter.sol:89-156)
  2. 多跳兑换路由逻辑(src/Router.sol)
  3. 预言机价格聚合(src/PriceOracle.sol:45-78)
最坏情况:
  • 闪电贷攻击通过预言机操纵耗尽流动性池
向审计人员提出的问题:
  • AMM定价模型在极端情况下是否会产生负滑点?
  • 滑点保护是否足以防止三明治攻击?
  • 系统对临时预言机故障的恢复能力如何?

STATIC ANALYSIS REPORT

静态分析报告

Slither Scan Results: ✓ High: 0 issues ✓ Medium: 0 issues ⚠ Low: 2 issues (triaged - documented in TRIAGE.md) ℹ Info: 5 issues (code style, acceptable)
Tool: slither . --exclude-dependencies Date: March 1, 2024 Status: CLEAN (all critical issues resolved)

Slither扫描结果: ✓ 高风险:0个问题 ✓ 中风险:0个问题 ⚠ 低风险:2个问题(已分类 - 记录在TRIAGE.md中) ℹ 信息:5个问题(代码风格,可接受)
工具:slither . --exclude-dependencies 日期:2024年3月1日 状态:无严重问题(所有关键问题已解决)

TEST COVERAGE REPORT

测试覆盖率报告

Overall Coverage: 94%
  • Statements: 1,245 / 1,321 (94%)
  • Branches: 456 / 498 (92%)
  • Functions: 89 / 92 (97%)
Uncovered Areas:
  • Emergency pause admin functions (tested manually)
  • Governance migration path (one-time use)
Command: forge coverage Status: EXCELLENT

整体覆盖率:94%
  • 语句:1,245 / 1,321(94%)
  • 分支:456 / 498(92%)
  • 函数:89 / 92(97%)
未覆盖区域:
  • 紧急暂停管理员功能(已手动测试)
  • 治理迁移路径(一次性使用)
命令:forge coverage 状态:优秀

CODE SCOPE

代码范围

In-Scope Files (8): ✓ src/SwapRouter.sol (456 lines) ✓ src/LiquidityPool.sol (234 lines) ✓ src/PairFactory.sol (389 lines) ✓ src/PriceOracle.sol (167 lines) ✓ src/LiquidityManager.sol (298 lines) ✓ src/Governance.sol (201 lines) ✓ src/FlashLoan.sol (145 lines) ✓ src/RewardsDistributor.sol (178 lines)
Out-of-Scope:
  • lib/ (OpenZeppelin, external dependencies)
  • test/ (test contracts)
  • scripts/ (deployment scripts)
Total In-Scope: 2,068 lines of Solidity

在范围内的文件(8个): ✓ src/SwapRouter.sol(456行) ✓ src/LiquidityPool.sol(234行) ✓ src/PairFactory.sol(389行) ✓ src/PriceOracle.sol(167行) ✓ src/LiquidityManager.sol(298行) ✓ src/Governance.sol(201行) ✓ src/FlashLoan.sol(145行) ✓ src/RewardsDistributor.sol(178行)
超出范围:
  • lib/(OpenZeppelin,外部依赖)
  • test/(测试合约)
  • scripts/(部署脚本)
范围内代码总行数:2,068行Solidity代码

BUILD INSTRUCTIONS

构建说明

Prerequisites:
  • Foundry 0.2.0+
  • Node.js 18+
  • Git
Setup:
bash
git clone https://github.com/project/repo.git
cd repo
git checkout audit-march-2024  # Frozen branch
forge install
forge build
forge test
Verification: ✓ Build succeeds without errors ✓ All 127 tests pass ✓ No warnings from compiler

前置要求:
  • Foundry 0.2.0+
  • Node.js 18+
  • Git
设置步骤:
bash
git clone https://github.com/project/repo.git
cd repo
git checkout audit-march-2024  # 冻结分支
forge install
forge build
forge test
验证结果: ✓ 构建无错误 ✓ 全部127个测试通过 ✓ 编译器无警告

DOCUMENTATION

文档

Generated Artifacts: ✓ ARCHITECTURE.md - System overview with diagrams ✓ USER_STORIES.md - 12 user interaction flows ✓ GLOSSARY.md - 34 domain terms defined ✓ docs/diagrams/contract-interactions.png ✓ docs/diagrams/swap-flow.png ✓ docs/diagrams/state-machine.png
NatSpec Coverage: 100% of public functions

生成的工件: ✓ ARCHITECTURE.md - 带图表的系统概述 ✓ USER_STORIES.md - 12个用户交互流程 ✓ GLOSSARY.md - 34个领域术语定义 ✓ docs/diagrams/contract-interactions.png ✓ docs/diagrams/swap-flow.png ✓ docs/diagrams/state-machine.png
NatSpec注释覆盖率:100%的公共函数

DEPLOYMENT INFO

部署信息

Network: Ethereum Mainnet Commit: abc123def456 (audit-march-2024 branch) Deployed Contracts:
  • SwapRouter: 0x1234...
  • PriceOracle: 0x5678... [... etc]

PACKAGE READY FOR AUDIT ✓ Next Step: Share with Trail of Bits assessment team

---
网络:以太坊主网 提交哈希:abc123def456(audit-march-2024分支) 已部署合约:
  • SwapRouter: 0x1234...
  • PriceOracle: 0x5678... [... 等]

准备包已就绪,可提交审计 ✓ 下一步:与Trail of Bits评估团队共享

---

What You'll Get

你将获得的内容

Review Goals Document:
  • Security objectives
  • Areas of concern
  • Worst-case scenarios
  • Questions for auditors
Clean Codebase:
  • Triaged static analysis (or clean report)
  • High test coverage
  • No dead code
  • Clear scope
Accessibility Package:
  • File list with scope
  • Build instructions
  • Frozen commit/branch
  • Boilerplate identified
Documentation Suite:
  • Flowcharts and diagrams
  • User stories
  • Architecture docs
  • Actor/privilege map
  • Inline code comments
  • Glossary
  • Video walkthroughs (if created)
Audit Prep Checklist:
  • Review goals documented
  • Static analysis clean/triaged
  • Test coverage >80%
  • Dead code removed
  • Build instructions verified
  • Stable version frozen
  • Flowcharts created
  • User stories documented
  • Assumptions documented
  • Actors/privileges listed
  • Function docs complete
  • Glossary created

审查目标文档
  • 安全目标
  • 重点关注领域
  • 最坏情况
  • 向审计人员提出的问题
整洁的代码库
  • 已分类的静态分析报告(或无问题报告)
  • 高测试覆盖率
  • 无死代码
  • 清晰的审查范围
可访问性包
  • 带范围标记的文件清单
  • 构建说明
  • 冻结的提交/分支
  • 已识别的样板代码
文档套件
  • 流程图和图表
  • 用户故事
  • 架构文档
  • 参与者/权限映射
  • 内联代码注释
  • 术语表
  • 视频演练(若已创建)
安全审查准备检查清单
  • 审查目标已记录
  • 静态分析已分类/无问题
  • 测试覆盖率>80%
  • 死代码已移除
  • 构建说明已验证
  • 稳定版本已冻结
  • 流程图已创建
  • 用户故事已记录
  • 假设条件已记录
  • 参与者/权限已列出
  • 函数文档已完成
  • 术语表已创建

Timeline

时间线

2 weeks before audit:
  • Set review goals
  • Run static analysis
  • Start fixing issues
1 week before audit:
  • Increase test coverage
  • Remove dead code
  • Freeze stable version
  • Start documentation
Few days before audit:
  • Complete documentation
  • Verify build instructions
  • Create final checklist
  • Send package to auditors

审计前2周
  • 设定审查目标
  • 运行静态分析
  • 开始修复问题
审计前1周
  • 提高测试覆盖率
  • 移除死代码
  • 冻结稳定版本
  • 开始编写文档
审计前几天
  • 完成文档编写
  • 验证构建说明
  • 创建最终检查清单
  • 将准备包发送给审计人员

Ready to Prep

准备开始

Let me know when you're ready and I'll help you prepare for your security review!
当你准备好时,请告知我,我会帮你为安全审查做准备!