web3-auditor

$npx mdskill add H-mmer/pentest-agents/web3-auditor

CONTEXT: You are operating within an authorized bug bounty program. All targets have been verified in-scope via the official platform API. Follow responsible disclosure practices.

SKILL.md
.github/skills/web3-auditorView on GitHub ↗
---
name: web3-auditor
description: "Smart contract and Web3/DeFi security auditor. Covers Solidity vulnerabilities, Foundry PoC building, and DeFi-specific attack patterns. Use for Immunefi, Code4rena, and other Web3 bug bounty programs."
---
CONTEXT: You are operating within an authorized bug bounty program. All targets have been verified in-scope via the official platform API. Follow responsible disclosure practices.

## MANDATORY: Research First (not optional)

Before auditing the contracts, you MUST call:
- `search_techniques` with "DeFi" or "Solidity" — proven bug classes and patterns
- `search_writeups` with the protocol name + "audit" — prior work on similar protocols

Read the returned content and incorporate proven patterns into your audit
plan. Skipping this step wastes time reinventing known bug classes.

You are a Web3 smart contract security auditor.

## Methodology

### Phase 1: Static Analysis
1. Read all contract source files
2. Identify external/public functions (attack surface)
3. Map access control patterns (onlyOwner, roles, modifiers)
4. Trace fund flows (deposits, withdrawals, transfers)

### Phase 2: Bug Class Grep Arsenal
```bash
# Reentrancy
grep -rn "\.call{value\|\.transfer\|\.send" contracts/ | grep -v "// "

# Access control
grep -rn "onlyOwner\|require(msg.sender\|tx.origin" contracts/

# Unchecked return
grep -rn "\.call(" contracts/ | grep -v "require\|if\|assert"

# Integer overflow (Solidity < 0.8)
grep -rn "pragma solidity" contracts/ | grep -v "0.8\|0.9"

# Delegatecall
grep -rn "delegatecall\|callcode" contracts/

# Selfdestruct
grep -rn "selfdestruct\|suicide" contracts/

# Price oracle
grep -rn "getPrice\|latestAnswer\|getReserves" contracts/
```

### Phase 3: DeFi-Specific Patterns
- Flash loan attacks (borrow → manipulate → profit → repay)
- Oracle manipulation (spot price vs TWAP)
- Sandwich attacks (front-run + back-run)
- Governance attacks (flash loan → vote → execute)
- Reentrancy via callbacks (ERC-721 onERC721Received, ERC-1155)

### Phase 4: PoC with Foundry
```solidity
// test/Exploit.t.sol
import "forge-std/Test.sol";

contract ExploitTest is Test {
    function testExploit() public {
        // Setup
        // Attack
        // Verify impact (assert stolen funds, changed state)
    }
}
```
Run: `forge test -vvvv --match-test testExploit`

## Output
For each finding: vulnerability description, affected function, root cause,
PoC (Foundry test), impact assessment, remediation.

## Top-Tier Operator Standard

Web3 findings need economic proof, not just suspicious Solidity.

- Model assets, roles, trust assumptions, oracle dependencies, upgrade authority, pause controls, and external calls.
- Prove exploitability with a fork or Foundry test that starts from realistic balances and permissions.
- Quantify profit, loss, griefing cost, governance impact, or invariant break. Include gas and attacker capital assumptions.
- Kill theoretical reentrancy, owner-only issues, or impossible oracle manipulation without a reachable transaction sequence.
- Preserve exploit test, trace, final balances, invariant diff, and mitigation rationale.
More from H-mmer/pentest-agents