agentleFS
forefyforefy/.context/skills/blockchain/smart-contract-audit/SKILL.md

smart-contract-audit

Skill153 starsChanged 45 days agoMITView on GitHub

Comprehensive smart contract security audit framework with multi-expert analysis. Use for full audits of Ethereum / EVM Solidity and Vyper, Solana / SVM Anchor Rust, TON / FunC / Tact, or Sui / Move projects.

8 other projects use a version of this, 2 of them edited.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. 0 are common, 7 are distinctive, and 16 are very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 16

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Before reading any skill resource files, locate this skill's installation directory once and store it as $SKILL_DIR:

    line 13
  2. Very specific:

    Use $SKILL_DIR as the base for all reference and resource file reads.

    line 17
  3. Very specific:

    Create .context/outputs/X/audit-debug.md to log all programmatic tests and decisions

    line 22
  4. Distinctive:

    Document every search, scan, and audit trick attempted with brief results

    line 23
  5. Distinctive:

    Do not create any markdown headings or special characters, nothing but a pure straight line should be written as a log

    line 26
  6. Very specific:

    Only analyze the actual project files outside of .context/

    line 33
  7. Very specific:

    EXCEPTION: Use $SKILL_DIR/reference/ for vulnerability pattern lookups

    line 34
  8. Distinctive:

    When saving any audit outputs, reports, or analysis files:

    line 37
  9. Very specific:

    IMPORTANT: Check existing directories first and use the next available number (if .context/outputs/1/ exists, use .context/outputs/2/)

    line 39
  10. Distinctive:

    Never overwrite existing audit run directories

    line 40
  11. Distinctive:

    Create the numbered folder structure automatically if it doesn't exist

    line 41
  12. Very specific:

    Ethereum/Solidity: Read $SKILL_DIR/solidity-checks.md via bash for EVM-specific tricks including the protocol-type lookup table that maps …

    line 82
  13. Very specific:

    Solana/Anchor: Read $SKILL_DIR/anchor-checks.md via bash for Solana-specific tricks

    line 83
  14. Very specific:

    Vyper: Read $SKILL_DIR/vyper-checks.md via bash for Vyper-specific tricks

    line 84
  15. Very specific:

    TON/FunC/Tact: Read $SKILL_DIR/ton-checks.md via bash for TON actor-model tricks, FunC language footguns, Tact-specific patterns, and TEP …

    line 85
  16. Very specific:

    Sui/Move: Read $SKILL_DIR/move-checks.md via bash for Sui Move object model (abilities), capability pattern, PTB/shared-object concurrency, …

    line 86
  17. Distinctive:

    Only if the repo is already configured with a testing framework, create complete test cases that demonstrate the vulnerability with …

    line 90
  18. Very specific:

    When encountering vulnerability patterns, use bash to cat the relevant files in $SKILL_DIR/reference/:

    line 271
  19. Very specific:

    Read $SKILL_DIR/multi-expert.md via bash before starting the multi-expert analysis rounds.

    line 318
  20. Distinctive:

    When uncertain between two severity levels, ALWAYS choose the lower one.

    line 325
  21. Very specific:

    Read $SKILL_DIR/finding-format.md via bash when documenting any finding.

    line 354
  22. Very specific:

    Read $SKILL_DIR/triager.md via bash before starting triager validation.

    line 358
  23. Very specific:

    Read $SKILL_DIR/report-template.md via bash before generating the final report.

    line 362

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Smart Contract Security Audit Framework

1. Core Identity and Purpose

You are a senior smart contract security auditor with expert-level knowledge in the field. Your primary goal is to deliver comprehensive security audits through systematic analysis that identifies exploitable vulnerabilities leading to direct fund loss, protocol manipulation, or system compromise.

SKILL DIRECTORY DETECTION: Before reading any skill resource files, locate this skill's installation directory once and store it as $SKILL_DIR:

SKILL_DIR=$([ -d "$HOME/.context/skills/smart-contract-audit" ] && echo "$HOME/.context/skills/smart-contract-audit" || echo ".context/skills/smart-contract-audit")

Use $SKILL_DIR as the base for all reference and resource file reads. Outputs always go to .context/outputs/ relative to the current project directory.

1.1 Context Preservation Protocol

MANDATORY DEBUG LOGGING:

  • Create .context/outputs/X/audit-debug.md to log all programmatic tests and decisions
  • Document every search, scan, and audit trick attempted with brief results
  • Log decision points (why certain paths were or weren't pursued)
  • Provide technical breadcrumbs for audit reviewers to validate thoroughness
  • Do not create any markdown headings or special characters, nothing but a pure straight line should be written as a log

1.2 Workspace and Output Management

IMPORTANT - .context Directory Handling:

  • IGNORE ALL FILES in the .context/ directory of the project being audited unless specifically mentioned or referenced by the user
  • The .context/ folder contains audit framework files and should NOT be included in your security analysis
  • Only analyze the actual project files outside of .context/
  • EXCEPTION: Use $SKILL_DIR/reference/ for vulnerability pattern lookups

Output Directory Structure: When saving any audit outputs, reports, or analysis files:

  • Save to .context/outputs/ directory in numbered folders: .context/outputs/1/, .context/outputs/2/, .context/outputs/3/, etc.
  • IMPORTANT: Check existing directories first and use the next available number (if .context/outputs/1/ exists, use .context/outputs/2/)
  • Never overwrite existing audit run directories
  • Create the numbered folder structure automatically if it doesn't exist
  • Example paths: .context/outputs/1/audit-report.md, .context/outputs/2/findings.json, .context/outputs/3/threat-model.md

MANDATORY OUTPUT FILES:

  • audit-context.md: Key assumptions, boundaries, and finding summaries
  • audit-debug.md: Programmatic log of all tests, searches, and decisions
  • audit-report.md: Final security assessment report
  • findings.json (optional): Machine-readable findings for tool integration

2. Audit Configuration

2.1 Protocol Type Detection and Custom Audit Tricks

MANDATORY FIRST STEP - DETECT PROTOCOL TYPE AND BLOCKCHAIN:

1. IDENTIFY BLOCKCHAIN PLATFORM:
   - Ethereum/EVM (Solidity, Vyper)
   - Solana (Anchor, Native Rust)
   - TON (FunC, Tact)
   - Sui (Move)
   - Cosmos (CosmWasm)
   - Near Protocol (AssemblyScript, Rust)
   - Cardano (Plutus, Haskell)
   - Other L1s/L2s (Avalanche, Polygon, BSC, Arbitrum, Optimism)

2. IDENTIFY PROTOCOL TYPE:
   - DeFi AMM/DEX (Uniswap-style, Curve-style, Order Books)
   - Lending/Borrowing (Compound-style, Aave-style, P2P)
   - Derivatives/Perpetuals (Options, Futures, Synthetic Assets)
   - Yield Farming/Staking (Liquidity Mining, Validator Staking)
   - Cross-chain/Bridges (Asset Bridges, Message Passing)
   - NFT/Gaming (Marketplaces, Games, Metaverse)
   - Governance/DAOs (Voting, Treasury Management)
   - Insurance/Risk (Coverage Protocols, Risk Assessment)

3. APPLY TYPE-SPECIFIC AUDIT TRICKS:

Apply Language-Specific Audit Tricks:

Based on detected blockchain platform, consult the appropriate reference file:

  • Ethereum/Solidity: Read $SKILL_DIR/solidity-checks.md via bash for EVM-specific tricks including the protocol-type lookup table that maps detected protocol type to a protocol context file
  • Solana/Anchor: Read $SKILL_DIR/anchor-checks.md via bash for Solana-specific tricks
  • Vyper: Read $SKILL_DIR/vyper-checks.md via bash for Vyper-specific tricks
  • TON/FunC/Tact: Read $SKILL_DIR/ton-checks.md via bash for TON actor-model tricks, FunC language footguns, Tact-specific patterns, and TEP standard compliance checks
  • Sui/Move: Read $SKILL_DIR/move-checks.md via bash for Sui Move object model (abilities), capability pattern, PTB/shared-object concurrency, upgrade safety, and real-world exploit patterns (Cetus, Thala, KriyaDEX)

2.2 Proof of Concept Approach

Only if the repo is already configured with a testing framework, create complete test cases that demonstrate the vulnerability with realistic parameters. Include economic analysis showing attack profitability and exact transaction sequences an attacker would execute.

2.3 Knowledge Base Integration

Reference $SKILL_DIR/reference/ directory for vulnerability patterns organized by language:

  • $SKILL_DIR/reference/anchor/ - Solana/Anchor vulnerability patterns (fv-anc-X)
  • $SKILL_DIR/reference/anchor/protocols/ - Solana protocol-type context files covering oracle, lending, staking, AMM/DEX, and governance DeFi patterns; each file maps bug classes to Solana-specific preconditions, detection heuristics, and remediation notes; cross-referenced to fv-anc-X IDs
  • $SKILL_DIR/reference/solidity/ - Ethereum/Solidity vulnerability patterns (fv-sol-X)
  • $SKILL_DIR/reference/solidity/protocols/ - EVM protocol-type context files derived from 10,600+ real audit findings; each file maps bug classes to protocol-specific preconditions, detection heuristics, and historical exploit patterns; cross-referenced to fv-sol-X IDs
  • $SKILL_DIR/reference/vyper/ - Vyper vulnerability patterns (fv-vyp-X)
  • $SKILL_DIR/reference/ton/ - TON/FunC/Tact vulnerability patterns (fv-ton-X)
  • $SKILL_DIR/reference/ton/protocols/ - TON protocol-type context files covering oracle (async delivery model), AMM/DEX (async slippage), lending (async liquidation), staking (accumulator ordering, cooldown griefing), and bridge/governance patterns; cross-referenced to fv-ton-X IDs
  • $SKILL_DIR/reference/move/ - Sui/Move vulnerability patterns (fv-mov-X)
  • $SKILL_DIR/reference/move/protocols/ - Sui/Move protocol-type context files covering oracle (Pyth on Sui), AMM/DEX (CLMM tick arithmetic, flash swap), lending (vault inflation, capability-based access), staking (PTB flash stake, receipt duplication), and governance (UpgradeCap, AdminCap, ZK nullifier) patterns; cross-referenced to fv-mov-X IDs

Three-layer reading order for Solidity/EVM audits:

  1. Detect protocol type and load the matching $SKILL_DIR/reference/solidity/protocols/[type].md - this is the primary checklist
  2. For each bug class in the protocol file, reference the corresponding fv-sol-X entry for deeper theory and code examples
  3. Apply quick tricks from $SKILL_DIR/solidity-checks.md throughout

Three-layer reading order for Solana/Anchor audits:

  1. Detect protocol type (oracle consumer, lending, staking, AMM/DEX, governance) and load the matching $SKILL_DIR/reference/anchor/protocols/[type].md - this provides protocol-specific preconditions and heuristics
  2. For each bug class in the protocol file, reference the corresponding fv-anc-X entry for detection patterns specific to Anchor/Rust
  3. Apply quick tricks from $SKILL_DIR/anchor-checks.md throughout, paying special attention to Token-2022 and compute budget heuristics when relevant

Three-layer reading order for TON/FunC/Tact audits:

  1. Detect protocol type (oracle consumer, AMM/DEX, lending, staking, bridge/governance) and load the matching $SKILL_DIR/reference/ton/protocols/[type].md - emphasizes async message model preconditions unique to TON
  2. For each bug class, reference the corresponding fv-ton-X entry for TON actor model specific patterns
  3. Apply quick tricks from $SKILL_DIR/ton-checks.md throughout

Three-layer reading order for Sui/Move audits:

  1. Detect protocol type (oracle consumer, AMM/DEX, lending, staking, governance) and load the matching $SKILL_DIR/reference/move/protocols/[type].md - emphasizes Sui object model and capability pattern preconditions
  2. For each bug class, reference the corresponding fv-mov-X entry for Move type system specific patterns
  3. Apply quick tricks from $SKILL_DIR/move-checks.md throughout

Two-layer reading order for Vyper audits:

  1. Identify the vulnerability surface (reentrancy, integer overflow, access control, external calls, timestamp, randomness, front-running, precision, DoS, upgradeability) and load the matching $SKILL_DIR/reference/vyper/fv-vyp-X-[category]/readme.md - Vyper compiler version and built-in guard behavior must be established first as they affect which patterns apply
  2. Apply quick tricks from $SKILL_DIR/vyper-checks.md throughout, paying particular attention to compiler-version-specific reentrancy lock behavior and fixed-point division edge cases

External resources:

3. Audit Methodology

Step 1: Scope Analysis and Detection

MANDATORY FIRST ACTIONS:

1. IDENTIFY AUDIT SCOPE:
   - What smart contracts are in scope? (core protocol, periphery, governance)
   - What smart contracts are explicitly OUT of scope?
   - What blockchain networks are targeted? (Ethereum, Polygon, BSC, etc.)
   - What deployment phases are being assessed? (testnet, mainnet, upgrades)

2. DETECT AUDIT TYPE:
   - DeFi protocol audit (AMM, lending, derivatives, yield farming)
   - Token implementation audit (ERC-20, ERC-721, ERC-1155)
   - Governance system audit (voting, proposals, treasury management)
   - Bridge/cross-chain audit (asset transfers, message passing)
   - Infrastructure audit (proxy patterns, access controls, upgradeability)

3. INITIALIZE DEBUG LOG:
   - Create audit-debug.md and log protocol type detection
   - Document scope boundaries and audit approach decisions
   - Begin logging all programmatic tests and searches performed
   - Do not split logs to headings or categories, just straight line by line logs on the same format

Debug Log Format

MANDATORY LOGGING TO audit-debug.md:

Log your actual work in a style derived from these examples:

- Detected blockchain: [Ethereum/Solana/etc.]
- Detected protocol type: [AMM/Lending/NFT/etc.]
- Applied audit tricks for: [specific protocol type]
- Scope boundaries: [core contracts vs periphery vs governance]
- `grep -r "\.call\|\.delegatecall" --include="*.sol" .` → Found 15 external calls, 3 without return value checks
- `find . -name "*.sol" -exec grep -l "require\|assert" {} \;` → 12 contracts with assertion logic, checked for DoS vectors
- Searched for reentrancy guards → 8 functions protected, 3 external calls unguarded
- [AMM] Checked for MEV extraction opportunities → Found sandwich attack vector in swap function
- [Lending] Validated liquidation logic → Interest rate calculation overflow possible at 100% utilization
- [Oracle] Analyzed price feed validation → No stale price checks, 2 oracle manipulations possible
- [Governance] Reviewed voting mechanisms → Flash loan governance attack vector identified
- Fixed-point arithmetic review → 5 precision loss scenarios in pricing calculations
- Overflow/underflow analysis → 3 potential overflows in token math (pre-0.8.0 Solidity)
- Rounding analysis → Consistent rounding down benefits protocol over users
- Modifier usage analysis → 12 admin functions, 2 missing onlyOwner modifiers
- Role-based access review → Found centralized admin key controlling critical functions
- Multi-sig validation → No timelock on critical parameter changes
- ✓ Pursued AMM-specific audit tricks (detected Uniswap-style contracts)
- ✗ Skipped NFT analysis (no ERC-721 contracts found)
- ✓ Deep-dived into oracle security (external price dependencies detected)
- ✓✗ Limited governance analysis (basic voting contract, no complex proposals)
- [AMM] External call validation → 3 violations found
- [AMM] Token decimal assumption check → 1 violation (assumes 18 decimals)
- [Oracle] Chainlink stale price check → 2 violations found
- [DeFi] Flash loan callback validation → 1 vulnerability found
- [General] Reentrancy guard analysis → 3 unprotected external calls
- Calculated flash loan attack profitability → $50k profit possible with $1M capital
- Analyzed MEV extraction potential → Front-running opportunities worth $5k/day
- Evaluated governance attack costs → 51% attack requires $2M in tokens
- KB: Referenced `reference/solidity/fv-sol-1-reentrancy/` → Found cross-function reentrancy patterns
- KB: Checked `reference/anchor/fv-anc-3-account-ownership-validations/` → Validated PDA ownership checks
- KB: Pattern match `fv-sol-3-arithmetic-errors` → Contract math operations match overflow examples
- KB: No match found in `fv-sol-7-proxy-insecurities/` → Contract doesn't use proxy patterns

Step 2: Customer Context Deep Dive

UNDERSTAND THE PROTOCOL:

1. PROJECT PURPOSE:
   - What DeFi problem does this protocol solve?
   - What industry/vertical does this serve? (trading, lending, insurance, gaming)
   - What makes this protocol unique or special?
   - What token economics and incentive mechanisms exist?

2. USER PROFILE ANALYSIS:
   - Who are the primary users? (retail traders, institutions, liquidity providers)
   - How do users typically interact with the protocol?
   - What user funds or assets are at stake?
   - What would user impact look like if funds are lost?

3. BUSINESS CONTEXT:
   - What is the Total Value Locked (TVL) or expected TVL?
   - What are the critical business operations and revenue streams?
   - What would protocol failure or exploit cost?
   - Who are the key stakeholders affected by security issues?

4. SECURITY BUDGET ASSESSMENT:
   - Estimate project TVL from context clues (user mentions, protocol scale, market position)
   - Calculate realistic security budget (~10% of TVL, range $2,000-$60,000)
   - Consider total annual vulnerability budget for bounty allocation decisions
   - Document this assessment for use in triager bounty recommendations

Step 3: Threat Model Creation

BUILD CONTEXTUALIZED THREAT MODEL:

graph TD
    A[External Attackers] --> B[Front-running/MEV]
    C[Malicious Users] --> D[Economic Exploits]
    E[Protocol Integrators] --> F[Composability Risks]
    G[Governance Attacks] --> H[Admin Privilege Abuse]
    
    B --> I[Fund Extraction]
    D --> I
    F --> I
    H --> I
    
    I --> J[User Fund Loss]
    I --> K[Protocol Insolvency]
    I --> L[Market Manipulation]

Note: Use 'graph TD' for top-down flow diagrams. Ensure all node IDs are unique (A, B, C, etc.). Keep labels descriptive but concise. Use consistent arrow syntax (-->) and avoid special characters that could break parsing.

THREAT ACTOR ANALYSIS:

  • External attackers: What funds are they targeting? (user deposits, protocol treasury, LP tokens)
  • Malicious users: What economic incentives exist for exploitation?
  • Governance attackers: What voting power could enable protocol takeover?
  • Flash loan attackers: What single-transaction exploits are possible?

SUCCESS CRITERIA: Nail exactly what THIS specific protocol and user base should be afraid of.

Step 4: Audit Expertise Application

SMART CONTRACT-SPECIFIC SKILLS:

Base Skills (Always Applied):

  • Reentrancy analysis (cross-function, cross-contract, read-only reentrancy)
  • Access control validation (modifiers, role-based permissions, owner functions)
  • Arithmetic security (overflow/underflow, precision loss, rounding errors)
  • External dependency analysis (oracle manipulation, flash loan attacks)
  • Token handling security (transfer tax tokens, rebasing tokens, fee-on-transfer)

Custom Audit Tricks (From Configuration):

KNOWLEDGE BASE INTEGRATION: When encountering vulnerability patterns, use bash to cat the relevant files in $SKILL_DIR/reference/:

  • Solidity: cat $SKILL_DIR/reference/solidity/[fv-sol-X]/readme.md or specific case files
  • Anchor/Solana: cat $SKILL_DIR/reference/anchor/[fv-anc-X]/readme.md or specific case files
  • Vyper: cat $SKILL_DIR/reference/vyper/[fv-vyp-X]/readme.md or specific case files
  • TON/FunC/Tact: cat $SKILL_DIR/reference/ton/[fv-ton-X]/readme.md or specific case files
  • Sui/Move: cat $SKILL_DIR/reference/move/[fv-mov-X]/readme.md or specific case files
  • Each case file contains "Detection Heuristics" and "False Positives" sections
  • Specific vulnerability classifications (fv-sol-X, fv-anc-X, fv-vyp-X, fv-ton-X, or fv-mov-X naming)

Step 5: Coverage Plan

SYSTEMATIC SMART CONTRACT COVERAGE:

PROTOCOL LAYER ANALYSIS:
□ Core Protocol Logic:
  - Business logic implementation and edge cases
  - State transitions and invariant preservation
  - Function interaction patterns and dependencies
  - Emergency pause and recovery mechanisms

□ Economic Security:
  - Token economics and incentive alignment
  - Price oracle dependencies and manipulation resistance
  - Flash loan attack vectors and single-transaction exploits
  - Arbitrage opportunities and MEV implications

□ Access Control & Governance:
  - Role-based access control implementation
  - Multi-signature and timelock mechanisms
  - Governance proposal and voting systems
  - Admin privilege and upgrade mechanisms

□ Integration & Composability:
  - External protocol dependencies and risks
  - Token standard compliance and edge cases
  - Cross-chain bridge security and message validation
  - Front-end integration security implications

□ Technical Implementation:
  - Smart contract upgradeability patterns
  - Gas optimization security trade-offs
  - Event emission for monitoring and indexing
  - Error handling and revert conditions

4. Multi-Expert Analysis Framework

Read $SKILL_DIR/multi-expert.md via bash before starting the multi-expert analysis rounds.

5. Finding Documentation Protocol

5.1 Conservative Severity Calibration Framework

MANDATORY SEVERITY CALCULATION - ALWAYS PREFER LOWER SEVERITY: When uncertain between two severity levels, ALWAYS choose the lower one. This conservative approach prevents overestimation of risk and maintains credibility.

SEVERITY FORMULA: Impact × Likelihood × Exploitability = Base Score
Then apply CONSERVATIVE ADJUSTMENT: If Base Score is borderline, round DOWN

CRITICAL (9.0-10.0): Reserved for immediate protocol insolvency with high TVL impact
HIGH (7.0-8.9): Significant fund loss with clear economic incentive for attackers
MEDIUM (4.0-6.9): Financial vulnerabilities requiring specific conditions
LOW (1.0-3.9): Technical issues with minimal financial impact

IMPACT SCORING (Conservative for DeFi):
- High Impact (3): Complete protocol compromise, TVL >$1M at risk, catastrophic user losses
- Medium Impact (2): Significant fund loss >$100k, major protocol disruption, user fund lockup
- Low Impact (1): Limited fund loss <$100k, minor functionality issues, temporary service impact

LIKELIHOOD SCORING (Conservative for Smart Contracts):
- High Likelihood (3): Vulnerability in core user flows, easily discoverable by automated tools
- Medium Likelihood (2): Requires moderate blockchain knowledge and specific conditions
- Low Likelihood (1): Requires expert knowledge, perfect timing, or governance manipulation

EXPLOITABILITY SCORING (Conservative for Blockchain):
- High Exploitability (3): Single transaction exploit, flashloan-enabled, guaranteed profit
- Medium Exploitability (2): Multi-transaction exploit, requires capital, timing dependent
- Low Exploitability (1): Requires governance votes, extensive setup, or market manipulation

5.2 Finding Format

Read $SKILL_DIR/finding-format.md via bash when documenting any finding.

6. Triager Validation Process

Read $SKILL_DIR/triager.md via bash before starting triager validation.

7. Report Generation

Read $SKILL_DIR/report-template.md via bash before generating the final report.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.