audit-context-building

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deep Context Builder Skill (Ultra-Granular Pure Context Mode)

深度上下文构建Skill(超精细化纯上下文模式)

Lifecycle Position

生命周期定位

Phase 5 (Review — optional deep-dive). For security audit or deep architectural review. Load after
code-analyzer
for targeted analysis.
第5阶段(审查——可选深度探索)。用于安全审计或深度架构审查。需在
code-analyzer
之后加载以进行针对性分析。

1. Purpose

1. 目标

This skill governs how Claude thinks during the context-building phase of an audit.
When active, Claude will:
  • Perform line-by-line / block-by-block code analysis by default.
  • Apply First Principles, 5 Whys, and 5 Hows at micro scale.
  • Continuously link insights → functions → modules → entire system.
  • Maintain a stable, explicit mental model that evolves with new evidence.
  • Identify invariants, assumptions, flows, and reasoning hazards.
This skill defines a structured analysis format (see Example: Function Micro-Analysis below) and runs before the vulnerability-hunting phase.

本Skill用于规范Claude在审计的上下文构建阶段的思考方式
激活本Skill后,Claude将:
  • 默认执行逐行/逐块代码分析。
  • 在微观层面应用First Principles5 Whys5 Hows方法。
  • 持续将见解关联到函数、模块乃至整个系统。
  • 维护一个随新证据不断演化的稳定、明确的心智模型。
  • 识别不变量、假设、流程和推理风险。
本Skill定义了结构化的分析格式(见下文示例:函数微观分析),且运行于漏洞排查阶段之前

2. When to Use This Skill

2. 何时使用本Skill

Use when:
  • Deep comprehension is needed before bug or vulnerability discovery.
  • You want bottom-up understanding instead of high-level guessing.
  • Reducing hallucinations, contradictions, and context loss is critical.
  • Preparing for security auditing, architecture review, or threat modeling.
Do not use for:
  • Vulnerability findings
  • Fix recommendations
  • Exploit reasoning
  • Severity/impact rating

适用场景:
  • 在发现漏洞或缺陷前需要深度理解代码时。
  • 希望通过自下而上的方式理解系统,而非高层猜测时。
  • 减少幻觉、矛盾和上下文丢失至关重要时。
  • 为安全审计、架构审查或威胁建模做准备时。
不适用场景:
  • 漏洞发现
  • 修复建议
  • 漏洞利用推理
  • 严重性/影响评级

3. How This Skill Behaves

3. 本Skill的行为模式

When active, Claude will:
  • Default to ultra-granular analysis of each block and line.
  • Apply micro-level First Principles, 5 Whys, and 5 Hows.
  • Build and refine a persistent global mental model.
  • Update earlier assumptions when contradicted ("Earlier I thought X; now Y.").
  • Periodically anchor summaries to maintain stable context.
  • Avoid speculation; express uncertainty explicitly when needed.
Goal: deep, accurate understanding, not conclusions.

激活后,Claude将:
  • 默认对每个代码块和代码行进行超精细化分析
  • 在微观层面应用First Principles、5 Whys和5 Hows方法。
  • 构建并优化持久化的全局心智模型。
  • 当之前的假设被推翻时进行更新(例如:“此前我认为是X;现在修正为Y。”)。
  • 定期锚定总结内容以维持稳定的上下文。
  • 避免猜测;必要时明确表达不确定性。
目标:深度、准确的理解,而非得出结论。

Rationalizations (Do Not Skip)

合理化检查(不可跳过)

RationalizationWhy It's WrongRequired Action
"I get the gist"Gist-level understanding misses edge casesLine-by-line analysis required
"This function is simple"Simple functions compose into complex bugsApply 5 Whys anyway
"I'll remember this invariant"You won't. Context degrades.Write it down explicitly
"External call is probably fine"External = adversarial until proven otherwiseJump into code or model as hostile
"I can skip this helper"Helpers contain assumptions that propagateTrace the full call chain
"This is taking too long"Rushed context = hallucinated vulnerabilities laterSlow is fast

合理化理由错误原因要求动作
“我理解大意了”仅理解大意会遗漏边缘情况必须执行逐行分析
“这个函数很简单”简单函数组合后可能产生复杂漏洞仍需应用5 Whys方法
“我会记住这个不变量”上下文会逐渐衰减,无法长期记忆必须明确记录下来
“外部调用应该没问题”外部组件在被验证前应视为具有攻击性深入代码分析或假设其为恶意组件
“我可以跳过这个辅助函数”辅助函数包含的假设会传播到其他模块追踪完整的调用链
“这太耗时了”仓促构建的上下文会导致后续出现幻觉式漏洞判断慢即是快

4. Phase 1 — Initial Orientation (Bottom-Up Scan)

4. 第一阶段——初始定位(自下而上扫描)

Before deep analysis, Claude performs a minimal mapping:
  1. Identify major modules/files/contracts.
  2. Note obvious public/external entrypoints.
  3. Identify likely actors (users, owners, relayers, oracles, other contracts).
  4. Identify important storage variables, dicts, state structs, or cells.
  5. Build a preliminary structure without assuming behavior.
This establishes anchors for detailed analysis.

在深度分析前,Claude会执行最小化映射:
  1. 识别主要模块/文件/合约。
  2. 标记明显的公共/外部入口点。
  3. 识别可能的参与者(用户、所有者、中继器、预言机、其他合约)。
  4. 识别重要的存储变量、字典、状态结构体或单元。
  5. 在不假设行为的前提下构建初步结构。
此步骤为后续的详细分析建立锚点。

5. Phase 2 — Ultra-Granular Function Analysis (Default Mode)

5. 第二阶段——超精细化函数分析(默认模式)

Every non-trivial function receives full micro analysis.
每个非平凡函数都需接受完整的微观分析。

5.1 Per-Function Microstructure Checklist

5.1 函数微观结构检查清单

For each function:
  1. Purpose
    • Why the function exists and its role in the system.
  2. Inputs & Assumptions
    • Parameters and implicit inputs (state, sender, env).
    • Preconditions and constraints.
  3. Outputs & Effects
    • Return values.
    • State/storage writes.
    • Events/messages.
    • External interactions.
  4. Block-by-Block / Line-by-Line Analysis For each logical block:
    • What it does.
    • Why it appears here (ordering logic).
    • What assumptions it relies on.
    • What invariants it establishes or maintains.
    • What later logic depends on it.
    Apply per-block:
    • First Principles
    • 5 Whys
    • 5 Hows

针对每个函数:
  1. 目标
    • 函数存在的原因及其在系统中的角色。
  2. 输入与假设
    • 参数和隐式输入(状态、调用者、环境)。
    • 前置条件和约束。
  3. 输出与影响
    • 返回值。
    • 状态/存储写入操作。
    • 事件/消息。
    • 外部交互。
  4. 逐块/逐行分析 针对每个逻辑块:
    • 它的功能是什么。
    • 为什么在此处出现(排序逻辑)。
    • 它依赖哪些假设。
    • 它建立或维护了哪些不变量。
    • 后续逻辑依赖它的哪些内容。
    针对每个块应用:
    • First Principles
    • 5 Whys
    • 5 Hows

5.2 Cross-Function & External Flow Analysis

5.2 跨函数与外部流分析

(Full Integration of Jump-Into-External-Code Rule)
When encountering calls, continue the same micro-first analysis across boundaries.
(完整集成“深入外部代码”规则)
当遇到调用时,跨边界继续采用相同的微观优先分析方式

Internal Calls

内部调用

  • Jump into the callee immediately.
  • Perform block-by-block analysis of relevant code.
  • Track flow of data, assumptions, and invariants: caller → callee → return → caller.
  • Note if callee logic behaves differently in this specific call context.
  • 立即跳转到被调用函数。
  • 对相关代码执行逐块分析。
  • 追踪数据、假设和不变量的流转: 调用者 → 被调用者 → 返回 → 调用者。
  • 注意被调用函数在此特定调用上下文中的行为是否有差异。

External Calls — Two Cases

外部调用——两种情况

Case A — External Call to a Contract Whose Code Exists in the Codebase Treat as an internal call:
  • Jump into the target contract/function.
  • Continue block-by-block micro-analysis.
  • Propagate invariants and assumptions seamlessly.
  • Consider edge cases based on the actual code, not a black-box guess.
Case B — External Call Without Available Code (True External / Black Box) Analyze as adversarial:
  • Describe payload/value/gas or parameters sent.
  • Identify assumptions about the target.
  • Consider all outcomes:
    • revert
    • incorrect/strange return values
    • unexpected state changes
    • misbehavior
    • reentrancy (if applicable)
情况A——调用代码库中存在的合约 视为内部调用处理:
  • 跳转到目标合约/函数。
  • 继续执行逐块微观分析。
  • 无缝传递不变量和假设。
  • 根据实际代码而非黑盒猜测来考虑边缘情况。
情况B——调用无可用代码的外部组件(真正的外部/黑盒) 视为具有攻击性的组件进行分析:
  • 描述发送的负载/价值/ gas或参数。
  • 识别对目标组件的假设。
  • 考虑所有可能的结果:
    • 回滚(revert)
    • 不正确/异常的返回值
    • 意外的状态变化
    • 异常行为
    • 重入(如适用)

Continuity Rule

连续性规则

Treat the entire call chain as one continuous execution flow. Never reset context. All invariants, assumptions, and data dependencies must propagate across calls.

将整个调用链视为一个连续的执行流。 绝不重置上下文。 所有不变量、假设和数据依赖必须在调用间传递。

5.3 Complete Analysis Example

5.3 完整分析示例

See FUNCTION_MICRO_ANALYSIS_EXAMPLE.md for a complete walkthrough demonstrating:
  • Full micro-analysis of a DEX swap function
  • Application of First Principles, 5 Whys, and 5 Hows
  • Block-by-block analysis with invariants and assumptions
  • Cross-function dependency mapping
  • Risk analysis for external interactions
This example demonstrates the level of depth and structure required for all analyzed functions.

完整的演示流程请参考FUNCTION_MICRO_ANALYSIS_EXAMPLE.md,其中包含:
  • 对DEX交换函数的完整微观分析
  • First Principles、5 Whys和5 Hows方法的应用
  • 包含不变量和假设的逐块分析
  • 跨函数依赖映射
  • 外部交互的风险分析
此示例展示了所有被分析函数所需达到的深度和结构化要求。

5.4 Output Requirements

5.4 输出要求

When performing ultra-granular analysis, Claude MUST structure output following the format defined in OUTPUT_REQUIREMENTS.md.
Key requirements:
  • Purpose (2-3 sentences minimum)
  • Inputs & Assumptions (all parameters, preconditions, trust assumptions)
  • Outputs & Effects (returns, state writes, external calls, events, postconditions)
  • Block-by-Block Analysis (What, Why here, Assumptions, First Principles/5 Whys/5 Hows)
  • Cross-Function Dependencies (internal calls, external calls with risk analysis, shared state)
Quality thresholds:
  • Minimum 3 invariants per function
  • Minimum 5 assumptions documented
  • Minimum 3 risk considerations for external interactions
  • At least 1 First Principles application
  • At least 3 combined 5 Whys/5 Hows applications

执行超精细化分析时,Claude必须按照OUTPUT_REQUIREMENTS.md中定义的格式组织输出。
关键要求:
  • 目标(至少2-3句话)
  • 输入与假设(所有参数、前置条件、信任假设)
  • 输出与影响(返回值、状态写入、外部调用、事件、后置条件)
  • 逐块分析(功能、存在原因、依赖假设、First Principles/5 Whys/5 Hows应用)
  • 跨函数依赖(内部调用、带风险分析的外部调用、共享状态)
质量阈值:
  • 每个函数至少3个不变量
  • 至少记录5个假设
  • 外部交互至少3个风险考量
  • 至少应用1次First Principles方法
  • 至少应用3次5 Whys/5 Hows方法

5.5 Completeness Checklist

5.5 完整性检查清单

Before concluding micro-analysis of a function, verify against the COMPLETENESS_CHECKLIST.md:
  • Structural Completeness: All required sections present (Purpose, Inputs, Outputs, Block-by-Block, Dependencies)
  • Content Depth: Minimum thresholds met (invariants, assumptions, risk analysis, First Principles)
  • Continuity & Integration: Cross-references, propagated assumptions, invariant couplings
  • Anti-Hallucination: Line number citations, no vague statements, evidence-based claims
Analysis is complete when all checklist items are satisfied and no unresolved "unclear" items remain.

在完成函数的微观分析前,需对照COMPLETENESS_CHECKLIST.md进行验证:
  • 结构完整性:包含所有必填部分(目标、输入、输出、逐块分析、依赖)
  • 内容深度:满足最低阈值(不变量、假设、风险分析、First Principles应用)
  • 连续性与集成性:交叉引用、传递的假设、不变量关联
  • 反幻觉:引用行号、无模糊表述、基于证据的结论
当所有检查项均满足且无未解决的“不明确”项时,分析才算完成。

6. Phase 3 — Global System Understanding

6. 第三阶段——全局系统理解

After sufficient micro-analysis:
  1. State & Invariant Reconstruction
    • Map reads/writes of each state variable.
    • Derive multi-function and multi-module invariants.
  2. Workflow Reconstruction
    • Identify end-to-end flows (deposit, withdraw, lifecycle, upgrades).
    • Track how state transforms across these flows.
    • Record assumptions that persist across steps.
  3. Trust Boundary Mapping
    • Actor → entrypoint → behavior.
    • Identify untrusted input paths.
    • Privilege changes and implicit role expectations.
  4. Complexity & Fragility Clustering
    • Functions with many assumptions.
    • High branching logic.
    • Multi-step dependencies.
    • Coupled state changes across modules.
These clusters help guide the vulnerability-hunting phase.

在完成足够的微观分析后:
  1. 状态与不变量重构
    • 映射每个状态变量的读写操作。
    • 推导跨函数和跨模块的不变量。
  2. 工作流重构
    • 识别端到端流程(存款、取款、生命周期、升级)。
    • 追踪状态在这些流程中的转换。
    • 记录在各步骤中持续存在的假设。
  3. 信任边界映射
    • 参与者 → 入口点 → 行为。
    • 识别不可信的输入路径。
    • 权限变化和隐含的角色预期。
  4. 复杂度与脆弱性聚类
    • 包含大量假设的函数。
    • 高分支逻辑。
    • 多步骤依赖。
    • 跨模块的耦合状态变化。
这些聚类结果将为漏洞排查阶段提供指导。

7. Stability & Consistency Rules

7. 稳定性与一致性规则

(Anti-Hallucination, Anti-Contradiction)
Claude must:
  • Never reshape evidence to fit earlier assumptions. When contradicted:
    • Update the model.
    • State the correction explicitly.
  • Periodically anchor key facts Summarize core:
    • invariants
    • state relationships
    • actor roles
    • workflows
  • Avoid vague guesses Use:
    • "Unclear; need to inspect X." instead of:
    • "It probably…"
  • Cross-reference constantly Connect new insights to previous state, flows, and invariants to maintain global coherence.

(反幻觉、反矛盾)
Claude必须:
  • 绝不修改证据以适配之前的假设。 当假设被推翻时:
    • 更新心智模型。
    • 明确声明修正内容。
  • 定期锚定关键事实 总结核心内容:
    • 不变量
    • 状态关系
    • 参与者角色
    • 工作流
  • 避免模糊猜测 使用:
    • “不明确;需要检查X。” 而非:
    • “可能……”
  • 持续交叉引用 将新见解与之前的状态、流程和不变量关联,以维持全局一致性。

8. Subagent Usage

8. 子Agent使用

Claude may spawn subagents for:
  • Dense or complex functions.
  • Long data-flow or control-flow chains.
  • Cryptographic / mathematical logic.
  • Complex state machines.
  • Multi-module workflow reconstruction.
Subagents must:
  • Follow the same micro-first rules.
  • Return summaries that Claude integrates into its global model.

Claude可生成子Agent用于处理以下场景:
  • 密集或复杂的函数。
  • 长数据流或控制流链。
  • 加密/数学逻辑。
  • 复杂状态机。
  • 跨模块工作流重构。
子Agent必须:
  • 遵循相同的微观优先规则。
  • 返回可被Claude整合到全局心智模型中的总结内容。

9. Relationship to Other Phases

9. 与其他阶段的关系

This skill runs before:
  • Vulnerability discovery
  • Classification / triage
  • Report writing
  • Impact modeling
  • Exploit reasoning
It exists solely to build:
  • Deep understanding
  • Stable context
  • System-level clarity

本Skill运行于以下阶段之前
  • 漏洞发现
  • 分类/分流
  • 报告撰写
  • 影响建模
  • 漏洞利用推理
它的唯一作用是构建:
  • 深度理解
  • 稳定上下文
  • 系统级清晰度

10. Non-Goals

10. 非目标

While active, Claude should NOT:
  • Identify vulnerabilities
  • Propose fixes
  • Generate proofs-of-concept
  • Model exploits
  • Assign severity or impact
This is pure context building only.
激活本Skill时,Claude不得:
  • 识别漏洞
  • 提出修复方案
  • 生成概念验证(POC)
  • 建模漏洞利用
  • 分配严重性或影响评级
这是纯上下文构建阶段。