Web3 smart contract

From woohyun212/security-skill · View interactive version

Web3 smart contract is an AI agent skill from the GitHub repository woohyun212/security-skill. Smart contract security audit covering 10 DeFi vulnerability classes with Foundry PoC templates

How to use this skill

Skill file

What this skill does

Audits Solidity smart contracts and DeFi protocols against 10 high-frequency vulnerability classes: Accounting State Desynchronization, Access Control, Incomplete Code Path, Off-By-One, Oracle Manipulation, ERC4626 Attacks, Reentrancy, Flash Loan Attacks, Signature Replay, and Proxy/Upgrade Issues. Guides an auditor from pre-dive assessment through grep-pattern scanning, manual code review, Foundry proof-of-concept test writing, and severity-rated findings report generation.

When to use

Prerequisites

```bash

curl -L https://foundry.paradigm.xyz | bash

foundryup

```

```bash

# Debian/Ubuntu

apt install ripgrep

# macOS

brew install ripgrep

```

```bash

pip install slither-analyzer

```

Inputs

| Variable | Required | Description |

|----------|----------|-------------|

| SECSKILL_CONTRACT_DIR | required | Path to the Solidity source directory |

| SECSKILL_PROTOCOL_NAME | optional | Protocol name for report labeling |

| SECSKILL_TVL_USD | optional | Approximate TVL in USD for risk context |

| SECSKILL_OUTPUT_DIR | optional | Directory to save findings and PoC files (default: ./output) |

| SECSKILL_RPC_URL | optional | RPC URL for forked Foundry tests (e.g. mainnet fork) |

Workflow

Step 1: Pre-dive assessment

Before reading code, collect signal that shapes audit priorities.

export SRC="${SECSKILL_CONTRACT_DIR:?Set SECSKILL_CONTRACT_DIR}"
export OUTDIR="${SECSKILL_OUTPUT_DIR:-./output}"
export PROTOCOL="${SECSKILL_PROTOCOL_NAME:-unknown}"
mkdir -p "$OUTDIR"

echo "===== Pre-Dive Assessment: $PROTOCOL ====="
echo "TVL (USD)    : ${SECSKILL_TVL_USD:-unknown}"
echo "Source path  : $SRC"
echo "Contract count:"
find "$SRC" -name "*.sol" | grep -v test | grep -v lib | wc -l
echo "Lines of code:"
find "$SRC" -name "*.sol" | grep -v test | grep -v lib | xargs wc -l | tail -1
echo ""
echo "[*] Check: Does the protocol have a prior audit? (check docs/audits/)"
echo "[*] Check: Is the code verified on Etherscan?"
echo "[*] Check: Is there a proxy/upgrade pattern in use?"

Pre-dive signal checklist:

Steps 2–11: Grep-pattern scans (Bug Classes 1–10)

Reference: See REFERENCE.md for the complete grep command blocks for all 10 bug classes (BC1 Accounting State Desynchronization through BC10 Proxy/Upgrade Issues).

Run each grep-pattern scan in order. Save output files to $OUTDIR. Manually confirm or dismiss each flagged result before creating a finding entry.

Bug class descriptions:

Step 12: Write Foundry PoC test for confirmed findings

Reference: See REFERENCE.md for the complete Foundry PoC template (reentrancy drain example) and the forge test run command.

For each confirmed CRITICAL or HIGH finding, write a Foundry test at test/PoC_<BugClass>_<FindingTitle>.t.sol. Use a mainnet fork (--fork-url $SECSKILL_RPC_URL) when the protocol interacts with live DeFi primitives.

Step 13: Assess severity and generate findings report

Reference: See REFERENCE.md for the severity table (CRITICAL/HIGH/MEDIUM/LOW/INFO) and the finding detail template.

## Smart Contract Audit Findings: <PROTOCOL_NAME>

**TVL**: $<TVL_USD>
**Audit date**: <YYYY-MM-DD>
**Source**: <SECSKILL_CONTRACT_DIR>

### Findings

| ID | Bug Class | Title | Severity | PoC Test |
|----|-----------|-------|----------|----------|
| F-001 | BC7 Reentrancy | Cross-function reentrancy in withdraw() allows ETH drain | CRITICAL | PoC_Reentrancy_WithdrawDrain.t.sol |
| F-002 | BC5 Oracle | Spot price from getReserves() manipulable via flash loan | HIGH | PoC_Oracle_FlashLoan.t.sol |
| F-003 | BC9 Signature | Missing nonce in permit() signature allows replay | MEDIUM | PoC_SignatureReplay.t.sol |

Done when

Failure modes

| Symptom | Cause | Resolution |

|---------|-------|------------|

| forge not found | Foundry not installed | Run curl -L https://foundry.paradigm.xyz \| bash && foundryup |

| PoC test fails to compile | Import paths incorrect | Adjust remappings.txt or use --remappings flag; check foundry.toml |

| Fork test fails with RPC error | Invalid or rate-limited RPC URL | Use a dedicated Alchemy/Infura endpoint; set SECSKILL_RPC_URL correctly |

| No grep results for a bug class | Pattern not present in this codebase | Mark that class as N/A with a note; it may still warrant manual review |

| Slither produces excessive false positives | Default detectors too broad | Run with --detect reentrancy,suicidal,uninitialized-local to scope to highest-signal detectors |

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.