jpskill.com
🛠️ 開発・MCP コミュニティ

defi-security

DeFiコントラクトのデプロイ前やセキュリティレビュー時に自動で起動し、アンチホエール、アンチMEV、フラッシュローン保護、ローンチチェックリスト、緊急対応をカバーするセキュリティ対策を施すためのSkill。

📜 元の英語説明(参考)

[AUTO-INVOKE] MUST be invoked BEFORE deploying DeFi contracts (DEX, lending, staking, LP, token). Covers anti-whale, anti-MEV, flash loan protection, launch checklists, and emergency response. Trigger: any deployment or security review of DeFi-related contracts.

🇯🇵 日本人クリエイター向け解説

一言でいうと

DeFiコントラクトのデプロイ前やセキュリティレビュー時に自動で起動し、アンチホエール、アンチMEV、フラッシュローン保護、ローンチチェックリスト、緊急対応をカバーするセキュリティ対策を施すためのSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o defi-security.zip https://jpskill.com/download/5967.zip && unzip -o defi-security.zip && rm defi-security.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5967.zip -OutFile "$d\defi-security.zip"; Expand-Archive "$d\defi-security.zip" -DestinationPath $d -Force; ri "$d\defi-security.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して defi-security.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → defi-security フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

DeFiセキュリティ原則

言語ルール

  • 常にユーザーが使用している言語で応答してください。 ユーザーが中国語で質問した場合は中国語で、英語で質問した場合は英語で応答します。

スコープ: DeFiプロジェクト(DEX、レンディング、ステーキング、LP、イールド)にのみ適用されます。非DeFiプロジェクトはこのスキルを無視できます。

保護決定ルール

脅威 必要な保護
クジラによる操作 1日の取引上限 + 1取引あたりの金額制限 + クールダウン期間
MEV / サンドイッチ攻撃 EOAのみのチェック (msg.sender == tx.origin)、またはコミット・リビールパターンを使用
アービトラージ 紹介者バインディング + 流動性分散 + 固定利回りモデル + ロック期間
再入攻撃 すべての外部呼び出し関数に ReentrancyGuard を適用(solidity-securityスキルを参照)
フラッシュローン攻撃 操作間の block.number の変更をチェック、またはTWAP価格を使用
価格操作 ChainlinkオラクルまたはTWAP — スポットAMN準備金に価格を依存しない
承認エクスプロイト ユーザーフローには safeIncreaseAllowance / safeDecreaseAllowance を使用し、生の approve は使用しない
ガバナンス攻撃 投票にはスナップショット + 最低トークン保有期間が必要。提案実行のタイムロックは48時間以上
ERC4626インフレ攻撃 最初の預け入れは最低金額を強制するか、仮想シェアを使用して丸めによるシェア希薄化を防ぐ

アンチクジラ実装ルール

  • 最大単一取引額: onlyOwner セッターで設定可能
  • アドレスごとの1日累積制限: mapping(address => mapping(uint256 => uint256)) (アドレス → 日 → 金額) で追跡
  • 取引間のクールダウン: block.timestamp チェックで最小時間間隔を強制
  • 免除アドレスのホワイトリスト(デプロイヤー、LPペア、ステーキングコントラクト)

フラッシュローン保護ルール

  • 価格に敏感な操作の場合: 最後のインタラクション以降に block.number が変更されていることを要求
  • オラクルに依存する計算の場合: 少なくとも30分間の時間加重平均(TWAP)を使用
  • 重要な状態変更の場合: アクションの前に最低保有期間を追加(例: Nブロックの間トークンを保有する必要がある)

リリースチェックリスト

メインネットデプロイ前に、すべての項目を確認してください。

  • [ ] すべての onlyOwner 関数がマルチシグ(例: Gnosis Safe)に転送されている
  • [ ] タイムロックコントラクトがデプロイされ、設定されている(重要な変更には最低24時間の遅延)
  • [ ] Pausable 緊急スイッチがテスト済み — pause()unpause() の両方が正しく機能する
  • [ ] 1日あたりの制限パラメータが文書化され、適切な値に設定されている
  • [ ] サードパーティのセキュリティ監査が完了し、すべての重大/高リスクの発見事項が解決されている
  • [ ] テストネットデプロイが最低7日間問題なく稼働している
  • [ ] スリッページ、手数料、ロック期間のパラメータがレビューされ、文書化されている
  • [ ] 初期流動性計画が文書化されている(金額、ロック期間、LPトークンの取り扱い)
  • [ ] すべてのDeFi-critical関数で forge test --fuzz-runs 10000 がパスする

緊急対応手順

ステップ アクション
1. 検知 アラートトリガーを監視(オンチェーン監視、コミュニティレポート)
2. 一時停止 指定されたアドレスが pause() を呼び出す — 数分以内に対応する必要がある
3. 評価 テクニカルリードが根本原因を分析し、資金への影響を推定
4. 連絡 コミュニティチャネル(Discord、Twitter、Telegram)にインシデント通知を投稿
5. 修正 修正をデプロイするか、復旧計画を準備
6. 再開 フォークで修正が検証された後、unpause() を呼び出す — または新しいコントラクトに移行
7. 事後分析 48時間以内に詳細なインシデントレポートを公開

DeFiテストコマンド

# 高い反復回数で資金フローをファズテスト
forge test --match-contract StakingTest --fuzz-runs 10000

# メインネットをフォークして実際の状態に対してテスト
forge test --fork-url $MAINNET_RPC -vvvv

# フォーク上でクジラのトランザクションをシミュレート
cast send <CONTRACT> "stake(uint256)" 1000000000000000000000000 \
  --rpc-url $FORK_RPC --private-key $TEST_KEY
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

DeFi Security Principles

Language Rule

  • Always respond in the same language the user is using. If the user asks in Chinese, respond in Chinese. If in English, respond in English.

Scope: Only applicable to DeFi projects (DEX, lending, staking, LP, yield). Non-DeFi projects can ignore this skill.

Protection Decision Rules

Threat Required Protection
Whale manipulation Daily transaction caps + per-tx amount limits + cooldown window
MEV / sandwich attack EOA-only checks (msg.sender == tx.origin), or use commit-reveal pattern
Arbitrage Referral binding + liquidity distribution + fixed yield model + lock period
Reentrancy ReentrancyGuard on all external-call functions (see solidity-security skill)
Flash loan attack Check block.number change between operations, or use TWAP pricing
Price manipulation Chainlink oracle or TWAP — never rely on spot AMM reserves for pricing
Approval exploit Use safeIncreaseAllowance / safeDecreaseAllowance, never raw approve for user flows
Governance attack Voting requires snapshot + minimum token holding period; timelock ≥ 48h on proposal execution
ERC4626 inflation attack First deposit must enforce minimum amount or use virtual shares to prevent share dilution via rounding

Anti-Whale Implementation Rules

  • Maximum single transaction amount: configurable via onlyOwner setter
  • Daily cumulative limit per address: track with mapping(address => mapping(uint256 => uint256)) (address → day → amount)
  • Cooldown between transactions: enforce minimum time gap with block.timestamp check
  • Whitelist for exempt addresses (deployer, LP pair, staking contract)

Flash Loan Protection Rules

  • For price-sensitive operations: require that block.number has changed since last interaction
  • For oracle-dependent calculations: use time-weighted average (TWAP) over minimum 30 minutes
  • For critical state changes: add minimum holding period before action (e.g., must hold tokens for N blocks)

Launch Checklist

Before mainnet deployment, verify all items:

  • [ ] All onlyOwner functions transferred to multisig (e.g., Gnosis Safe)
  • [ ] Timelock contract deployed and configured (minimum 24h delay for critical changes)
  • [ ] Pausable emergency switch tested — both pause() and unpause() work correctly
  • [ ] Daily limit parameters documented and set to reasonable values
  • [ ] Third-party security audit completed and all critical/high findings resolved
  • [ ] Testnet deployment running for minimum 7 days with no issues
  • [ ] Slippage, fee, and lock period parameters reviewed and documented
  • [ ] Initial liquidity plan documented (amount, lock duration, LP token handling)
  • [ ] forge test --fuzz-runs 10000 passes on all DeFi-critical functions

Emergency Response Procedure

Step Action
1. Detect Monitor alerts trigger (on-chain monitoring, community reports)
2. Pause Designated address calls pause() — must respond within minutes
3. Assess Technical lead analyzes root cause, estimates fund impact
4. Communicate Post incident notice to community channels (Discord, Twitter, Telegram)
5. Fix Deploy fix or prepare recovery plan
6. Resume Call unpause() after fix verified on fork — or migrate to new contract
7. Post-mortem Publish detailed incident report within 48 hours

DeFi Testing Commands

# Fuzz test fund flows with high iterations
forge test --match-contract StakingTest --fuzz-runs 10000

# Fork mainnet to test against real state
forge test --fork-url $MAINNET_RPC -vvvv

# Simulate whale transaction on fork
cast send <CONTRACT> "stake(uint256)" 1000000000000000000000000 \
  --rpc-url $FORK_RPC --private-key $TEST_KEY