Overview
This skill enables systematic bottom-up code comprehension through micro-level analysis. When active, Claude performs line-by-line and block-by-block examination applying First Principles, 5 Whys, and 5 Hows at granular scale to build stable, explicit mental models before any vulnerability identification.Author: Omar Inuwa
Version: 1.1.0
Version: 1.1.0
When to Use
Use this skill when you need to:Deep Comprehension
Develop thorough understanding of a codebase before security auditing
Bottom-Up Analysis
Build understanding from first principles instead of high-level guessing
Reduce Hallucinations
Minimize context loss and false assumptions during complex analysis
Architecture Review
Prepare for threat modeling or comprehensive system review
Installation
Analysis Phases
The skill follows a structured three-phase workflow:Initial Orientation
Bottom-up scan to map modules, entrypoints, actors, and storage without assuming behavior
Ultra-Granular Function Analysis
Line-by-line semantic analysis with cross-function flow tracking and invariant identification
Phase 1: Initial Orientation
Before deep analysis, perform minimal mapping to establish anchors:- Identify major modules/files/contracts
- Note obvious public/external entrypoints
- Identify likely actors (users, owners, relayers, oracles, other contracts)
- Identify important storage variables, dicts, state structs, or cells
- Build a preliminary structure without assuming behavior
Phase 2: Ultra-Granular Function Analysis
Every non-trivial function receives full micro analysis following this checklist:Per-Function Microstructure
1. Purpose- Why the function exists and its role in the system
- Parameters and implicit inputs (state, sender, env)
- Preconditions and constraints
- Return values
- State/storage writes
- Events/messages
- External interactions
What it does
What it does
Describe the operation performed by this code block
Why it appears here
Why it appears here
Explain the ordering logic and dependencies
Assumptions
Assumptions
List preconditions this block relies on
Invariants
Invariants
Identify what this block establishes or maintains
Dependencies
Dependencies
Note what later logic depends on this block
- First Principles - Understand from fundamental concepts
- 5 Whys - Recursively ask why until reaching root purpose
- 5 Hows - Recursively ask how until understanding implementation
Cross-Function Flow Analysis
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
- Treat as internal call
- Jump into the target contract/function
- Continue block-by-block micro-analysis
- Propagate invariants and assumptions seamlessly
- Describe payload/value/gas or parameters sent
- Identify assumptions about the target
- Consider all outcomes: revert, incorrect return values, unexpected state changes, misbehavior, reentrancy
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.
Output Quality Requirements
Analysis must meet these minimum thresholds:- 3 invariants documented per function
- 5 assumptions explicitly stated
- 3 risk considerations for external interactions
- 1 First Principles application
- 3 combined 5 Whys/5 Hows applications
Phase 3: Global System Understanding
After sufficient micro-analysis, synthesize global understanding: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
Anti-Hallucination Rules
| Rule | How to Apply |
|---|---|
| Never reshape evidence | When contradicted, update the model and state the correction explicitly |
| Periodically anchor key facts | Summarize core invariants, state relationships, actor roles, and 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 |
Rationalizations to Reject
"I get the gist"
"I get the gist"
Why it’s wrong: Gist-level understanding misses edge cases
Required action: Line-by-line analysis required
Required action: Line-by-line analysis required
"This function is simple"
"This function is simple"
Why it’s wrong: Simple functions compose into complex bugs
Required action: Apply 5 Whys anyway
Required action: Apply 5 Whys anyway
I'll remember this invariant
I'll remember this invariant
Why it’s wrong: You won’t. Context degrades.
Required action: Write it down explicitly
Required action: Write it down explicitly
"External call is probably fine"
"External call is probably fine"
Why it’s wrong: External = adversarial until proven otherwise
Required action: Jump into code or model as hostile
Required action: Jump into code or model as hostile
"I can skip this helper"
"I can skip this helper"
Why it’s wrong: Helpers contain assumptions that propagate
Required action: Trace the full call chain
Required action: Trace the full call chain
"This is taking too long"
"This is taking too long"
Why it’s wrong: Rushed context = hallucinated vulnerabilities later
Required action: Slow is fast
Required action: Slow is fast
Example: Function Micro-Analysis
Here’s how to apply the microstructure checklist to a DEX swap function:- Enables token exchange by accepting input tokens and sending output tokens
- Protects users from excessive slippage via minimum output requirement
amountIn: User-provided input amount (assumed > 0 after validation)minAmountOut: User’s slippage tolerance- Implicit:
msg.senderhas approvedamountIntokens - Implicit: Contract holds sufficient
tokenOutbalance
require(amountIn > 0, "Zero input");
- What: Validates positive input amount
- Why here: Must validate before expensive calculations
- Assumptions: Zero amounts would cause issues in pricing math
- Invariants: All code after this point knows
amountIn > 0 - First Principles: Zero-value exchanges are economically meaningless
uint256 amountOut = calculateOutput(amountIn);
- What: Computes exchange rate and output amount
- Why here: Need output before slippage check
- Dependencies: Relies on
amountIn > 0invariant - 5 Whys: Why calculate here? → To check slippage → To protect user → To prevent MEV/frontrunning → To maintain trust
- External call analysis: Jump into
calculateOutput()to verify pricing logic and manipulation resistance
require(amountOut >= minAmountOut, "Slippage");
- What: Enforces user’s slippage tolerance
- Assumptions: User calculated
minAmountOutbased on recent price - Invariants: Trade executes only if favorable to user
- Risk: User may set
minAmountOut = 0, accepting infinite slippage
- What: Execute the exchange
- Why this order: Input before output prevents reentrancy exploitation
- External calls: Both are ERC20 external calls
transferFrom: Attacker could implement malicious ERC20transfer: Output token could reenter if it’s the input token
- Assumptions: ERC20 implementation is not malicious
- Risk: Non-standard ERC20s may return false instead of reverting
- Calls:
calculateOutput()- must trace pricing logic - Shared state: Token balances modified
- Trust boundaries: User input → pricing → external token contracts
Subagent Usage
Claude may spawn thefunction-analyzer subagent for:
- Dense or complex functions
- Long data-flow or control-flow chains
- Cryptographic / mathematical logic
- Complex state machines
- Multi-module workflow reconstruction
Integration with Other Skills
This skill runs before:- Vulnerability discovery
- Classification / triage
- Report writing
- Impact modeling
- Exploit reasoning
- differential-review - Uses context-building for baseline analysis in Phase 4
- fp-check - Deep context helps distinguish true from false positives
- issue-writer - Write up findings after context is built
Related Skills
- Differential Review - Security-focused PR review using context-building
- FP Check - Systematic false positive verification