Blockchain Security
Purpose
Guide blockchain-specific security analysis covering smart contract auditing, DeFi threat modeling, economic security, incident response, formal verification, and bug bounty programs. Combines traditional security engineering with blockchain-specific risks like economic attack vectors, flash loans, oracle manipulation, and MEV.
Agent Protocol
Trigger
"blockchain security", "smart contract audit", "DeFi security", "DeFi threat model", "blockchain threat modeling", "audit methodology", "blockchain incident response", "emergency pause", "fork coordination", "bug bounty", "Immunefi", "Code4rena", "economic security", "game theory blockchain", "incentive analysis", "MEV security", "certora", "formal verification blockchain", "Halmos", "Scribble", "solidity security", "smart contract vulnerability", "blockchain exploit", "flash loan attack", "oracle manipulation", "reentrancy", "access control blockchain", "cross-chain security", "bridge security"
Input Context
- Smart contracts or protocol to analyze
- Platform (EVM/Solana/Cosmos/Cardano)
- Security objective (audit/threat model/incident response/pre-audit review)
- Codebase location and audit history
- Previous incidents or vulnerabilities
- TVL and risk exposure
Output Artifact
Security analysis including: threat model, vulnerability findings, economic analysis, verification approach, and remediation recommendations.
Response Format
- Threat model: assets, actors, attack vectors, trust assumptions, attack surface
- Audit approach: methodology, tools, timeline, expected coverage
- Economic analysis: incentive structures, game theory, exploit scenarios
- Security controls: mitigations, circuit breakers, monitoring
- Verification: formal properties, invariants, proof techniques
- Incident response: emergency plan, communication template
Completion Criteria
- Threat model identifies all trust assumptions and attack surfaces
- Vulnerability findings include severity, impact, likelihood, and remediation
- Economic analysis models incentive alignment and identifies exploit paths
- Formal verification specifies key invariants (solvency, access control, correctness)
- Emergency response plan covers: pause, communication, fork coordination, post-mortem
Max Response Length
5000 tokens
Decision Trees
Security Assessment Type
Security need:
├── Pre-deployment audit?
│ ├── Early stage → Threat modeling + architecture review
│ │ ├── Identify trust assumptions
│ │ ├── Map attack surface
│ │ └── Design security controls
│ ├── Mid-development → Full audit (automated + manual + fuzz)
│ │ ├── Slither + Mythril static analysis (first pass)
│ │ ├── Manual line-by-line review (second pass)
│ │ ├── Foundry fuzz + invariant tests (third pass)
│ │ ├── Echidna/Medusa property-based fuzzing (fourth pass)
│ │ └── Certora/Halmos formal verification (fifth pass)
│ └── Pre-launch → Final audit + bug bounty launch
│ ├── Re-audit after fixes
│ ├── Immunefi or Code4rena bounty program
│ └── Emergency response plan
├── Incident response?
│ ├── Ongoing exploit → Emergency pause + communication
│ ├── Post-exploit → Damage assessment + recovery plan
│ └── Post-mortem → Root cause analysis + fix implementation
└── Ongoing security?
├── Continuous monitoring → Forta, Tenderly alerts
├── Bug bounty management → VRT, severity classification
└── Periodic review → Quarterly parameter review, annual deep audit
Vulnerability Severity (Immunefi Standard)
| Severity |
Impact |
Payout Range |
| Critical |
Direct loss of funds, permanent DoS |
Up to $10M+ |
| High |
Theft of unclaimed yield, temporary DoS |
$50K-$500K |
| Medium |
Contract fails to deliver expected return, temporarily frozen funds |
$5K-$50K |
| Low |
Griefing (no direct financial loss) |
$1K-$5K |
| None |
Informational |
No payout |
DeFi Threat Modeling (STRIDE-Blockchain)
STRIDE Adapted for Blockchain
| Threat |
Blockchain Equivalent |
Example |
| Spoofing |
Fake event log emission, counterfeit token |
Impostor token impersonation |
| Tampering |
State manipulation, reorg, flash loan price |
Manipulating oracle price |
| Repudiation |
Unauthorized proposal, fake governance |
Flash loan governance attack |
| Information disclosure |
Mempool snooping, frontrunning |
MEV extraction from public tx pool |
| Denial of Service |
Gas griefing, block stuffing |
Low-cost DoS via state bloat |
| Elevation of Privilege |
Unauthorized role assignment, proxy admin |
OpenZeppelin UUPS unauthorized upgrade |
Common Attack Trees
Reentrancy Attack Tree
├── External call before state update
│ ├── ETH transfer via .call{value}() (forward all gas)
│ ├── ERC-777 callback (tokensToSend hook)
│ └── ERC-1155 callback (onERC1155Received)
├── Recipient is malicious contract
│ └── Malicious fallback re-enters victim function
└── Mitigations:
├── Checks-effects-interactions pattern
├── ReentrancyGuard (OpenZeppelin)
└── Pull-over-push for payments
Oracle Manipulation Attack Tree
├── Single oracle price source
│ ├── Flash loan to manipulate AMM price
│ ├── Sandwich attack on oracle update
│ └── Frontrun oracle transaction
├── TWAP manipulation
│ └── Multi-block TWAP manipulation (expensive but possible)
└── Mitigations:
├── Redundant oracles (minimum 3 independent sources)
├── TWAP with sufficient window (30 min+)
├── Stale price checks (max age < 1 hour)
└── Circuit breakers on price deviation
Audit Methodology
Phase 1: Scope & Recon
- Define audit scope: contracts, functions, interactions
- Review specification and architecture documentation
- Understand trust model: admin roles, upgrade paths, emergency mechanisms
- Set up local environment with all dependencies
Phase 2: Automated Analysis
- Run Slither: detect common vulnerabilities, generate inheritance graph
- Run Mythril: symbolic execution for deep vulnerability detection
- Run Aderyn: Solidity static analyzer for spec violations
- Run Halmos: symbolic testing for complex assertions
- Run semgrep with custom rules
Phase 3: Manual Review
- Storage layout review: collision risks, upgrade compatibility
- Access control review: privilege escalation paths, role hierarchy
- Business logic review: correctness, edge cases, integer handling
- External dependency review: oracle, bridge, token interactions
- Economic analysis: incentive alignment, MEV exposure, game theory
Phase 4: Fuzz & Invariant
- Parameterized fuzzing with Foundry
- Invariant tests with Echidna or Medusa
- Stateful fuzzing with Foundry fuzz
- Differential testing with reference implementation
Phase 5: Formal Verification
- Certora CVL for critical invariants (solvency, access control)
- Scribble for annotation-based formal specs
- Halmos for symbolic testing of complex logic
Phase 6: Report & Remediation
- Document findings with severity, impact, exploit scenario, fix
- Retest fixes after remediation
- Final report with methodology, findings, and risk assessment
Common Vulnerability Examples
Reentrancy
// VULNERABLE
function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount);
(bool ok, ) = msg.sender.call{value: amount}(""); // external call BEFORE state
require(ok);
balances[msg.sender] -= amount; // state update AFTER
}
// FIXED: CEI pattern
function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount);
balances[msg.sender] -= amount; // state update FIRST
(bool ok, ) = msg.sender.call{value: amount}(""); // then external call
require(ok);
}
Access Control
// VULNERABLE: init function unprotected
function initialize(address _owner) external {
owner = _owner; // anyone can call this
}
// FIXED
function initialize(address _owner) external initializer {
__Ownable_init(_owner);
}
Rules
- Always start with threat modeling before writing any code — identify assets, trust boundaries, attack surfaces
- Audit pipeline: scope → manual review → automated tooling → fuzz/invariant → formal verification → report
- Economic security is as important as code security — analyze game theory and incentive alignment
- Bug bounty programs follow Immunefi severity: Critical (up to $1M+), High ($50K-$100K), Medium ($5K-$20K), Low ($1K-$5K)
- Incident response: freeze/pause contract → assess damage → communicate → fork coordination → post-mortem → compensation
- Formal verification complements but does NOT replace manual review and fuzz testing
- Always verify signature malleability (low-s for ECDSA), nonce reuse, and signature replay protection
- Cross-chain bridges require additional security layers: rate limiting, circuit breakers, tiered security
References
- references/audit-methodology.md — Smart Contract Audit Methodology
- references/blockchain-security-advanced.md — Blockchain Security Advanced Topics
- references/blockchain-security-fundamentals.md — Blockchain Security Fundamentals
- references/bug-bounty-program.md — Bug Bounty Programs for Blockchain Projects
- references/economic-security.md — Economic Security in Blockchain Systems
- references/formal-verification-deep.md — Formal Verification for Smart Contracts
- references/incident-response.md — Blockchain Incident Response
- references/smart-contract-security.md — Smart Contract Security
- references/threat-modeling.md — Threat Modeling for Blockchain Systems
- references/blockchain-vulnerability-catalog.md — Common Blockchain Vulnerabilities Catalog
- references/cross-chain-security.md — Cross-Chain Security Considerations
Phase
blockchain → blockchain-security
Source: j4flmao/agent-skills — distributed by TomeVault.
1---2name: j4flmao-agent-skills-blockchain-security3description: Blockchain Security4---56# Blockchain Security78## Purpose9Guide blockchain-specific security analysis covering smart contract auditing, DeFi threat modeling, economic security, incident response, formal verification, and bug bounty programs. Combines traditional security engineering with blockchain-specific risks like economic attack vectors, flash loans, oracle manipulation, and MEV.1011## Agent Protocol1213### Trigger14"blockchain security", "smart contract audit", "DeFi security", "DeFi threat model", "blockchain threat modeling", "audit methodology", "blockchain incident response", "emergency pause", "fork coordination", "bug bounty", "Immunefi", "Code4rena", "economic security", "game theory blockchain", "incentive analysis", "MEV security", "certora", "formal verification blockchain", "Halmos", "Scribble", "solidity security", "smart contract vulnerability", "blockchain exploit", "flash loan attack", "oracle manipulation", "reentrancy", "access control blockchain", "cross-chain security", "bridge security"1516### Input Context17- Smart contracts or protocol to analyze18- Platform (EVM/Solana/Cosmos/Cardano)19- Security objective (audit/threat model/incident response/pre-audit review)20- Codebase location and audit history21- Previous incidents or vulnerabilities22- TVL and risk exposure2324### Output Artifact25Security analysis including: threat model, vulnerability findings, economic analysis, verification approach, and remediation recommendations.2627### Response Format281. **Threat model**: assets, actors, attack vectors, trust assumptions, attack surface292. **Audit approach**: methodology, tools, timeline, expected coverage303. **Economic analysis**: incentive structures, game theory, exploit scenarios314. **Security controls**: mitigations, circuit breakers, monitoring325. **Verification**: formal properties, invariants, proof techniques336. **Incident response**: emergency plan, communication template3435### Completion Criteria36- Threat model identifies all trust assumptions and attack surfaces37- Vulnerability findings include severity, impact, likelihood, and remediation38- Economic analysis models incentive alignment and identifies exploit paths39- Formal verification specifies key invariants (solvency, access control, correctness)40- Emergency response plan covers: pause, communication, fork coordination, post-mortem4142### Max Response Length435000 tokens4445## Decision Trees4647### Security Assessment Type48```49Security need:50├── Pre-deployment audit?51│ ├── Early stage → Threat modeling + architecture review52│ │ ├── Identify trust assumptions53│ │ ├── Map attack surface54│ │ └── Design security controls55│ ├── Mid-development → Full audit (automated + manual + fuzz)56│ │ ├── Slither + Mythril static analysis (first pass)57│ │ ├── Manual line-by-line review (second pass)58│ │ ├── Foundry fuzz + invariant tests (third pass)59│ │ ├── Echidna/Medusa property-based fuzzing (fourth pass)60│ │ └── Certora/Halmos formal verification (fifth pass)61│ └── Pre-launch → Final audit + bug bounty launch62│ ├── Re-audit after fixes63│ ├── Immunefi or Code4rena bounty program64│ └── Emergency response plan65├── Incident response?66│ ├── Ongoing exploit → Emergency pause + communication67│ ├── Post-exploit → Damage assessment + recovery plan68│ └── Post-mortem → Root cause analysis + fix implementation69└── Ongoing security?70 ├── Continuous monitoring → Forta, Tenderly alerts71 ├── Bug bounty management → VRT, severity classification72 └── Periodic review → Quarterly parameter review, annual deep audit73```7475### Vulnerability Severity (Immunefi Standard)76| Severity | Impact | Payout Range |77|---|---|---|78| Critical | Direct loss of funds, permanent DoS | Up to $10M+ |79| High | Theft of unclaimed yield, temporary DoS | $50K-$500K |80| Medium | Contract fails to deliver expected return, temporarily frozen funds | $5K-$50K |81| Low | Griefing (no direct financial loss) | $1K-$5K |82| None | Informational | No payout |8384## DeFi Threat Modeling (STRIDE-Blockchain)8586### STRIDE Adapted for Blockchain87| Threat | Blockchain Equivalent | Example |88|---|---|---|89| Spoofing | Fake event log emission, counterfeit token | Impostor token impersonation |90| Tampering | State manipulation, reorg, flash loan price | Manipulating oracle price |91| Repudiation | Unauthorized proposal, fake governance | Flash loan governance attack |92| Information disclosure | Mempool snooping, frontrunning | MEV extraction from public tx pool |93| Denial of Service | Gas griefing, block stuffing | Low-cost DoS via state bloat |94| Elevation of Privilege | Unauthorized role assignment, proxy admin | OpenZeppelin UUPS unauthorized upgrade |9596### Common Attack Trees9798**Reentrancy Attack Tree**99```100├── External call before state update101│ ├── ETH transfer via .call{value}() (forward all gas)102│ ├── ERC-777 callback (tokensToSend hook)103│ └── ERC-1155 callback (onERC1155Received)104├── Recipient is malicious contract105│ └── Malicious fallback re-enters victim function106└── Mitigations:107 ├── Checks-effects-interactions pattern108 ├── ReentrancyGuard (OpenZeppelin)109 └── Pull-over-push for payments110```111112**Oracle Manipulation Attack Tree**113```114├── Single oracle price source115│ ├── Flash loan to manipulate AMM price116│ ├── Sandwich attack on oracle update117│ └── Frontrun oracle transaction118├── TWAP manipulation119│ └── Multi-block TWAP manipulation (expensive but possible)120└── Mitigations:121 ├── Redundant oracles (minimum 3 independent sources)122 ├── TWAP with sufficient window (30 min+)123 ├── Stale price checks (max age < 1 hour)124 └── Circuit breakers on price deviation125```126127## Audit Methodology128129### Phase 1: Scope & Recon1301. Define audit scope: contracts, functions, interactions1312. Review specification and architecture documentation1323. Understand trust model: admin roles, upgrade paths, emergency mechanisms1334. Set up local environment with all dependencies134135### Phase 2: Automated Analysis1365. Run Slither: detect common vulnerabilities, generate inheritance graph1376. Run Mythril: symbolic execution for deep vulnerability detection1387. Run Aderyn: Solidity static analyzer for spec violations1398. Run Halmos: symbolic testing for complex assertions1409. Run semgrep with custom rules141142### Phase 3: Manual Review14310. Storage layout review: collision risks, upgrade compatibility14411. Access control review: privilege escalation paths, role hierarchy14512. Business logic review: correctness, edge cases, integer handling14613. External dependency review: oracle, bridge, token interactions14714. Economic analysis: incentive alignment, MEV exposure, game theory148149### Phase 4: Fuzz & Invariant15015. Parameterized fuzzing with Foundry15116. Invariant tests with Echidna or Medusa15217. Stateful fuzzing with Foundry fuzz15318. Differential testing with reference implementation154155### Phase 5: Formal Verification15619. Certora CVL for critical invariants (solvency, access control)15720. Scribble for annotation-based formal specs15821. Halmos for symbolic testing of complex logic159160### Phase 6: Report & Remediation16122. Document findings with severity, impact, exploit scenario, fix16223. Retest fixes after remediation16324. Final report with methodology, findings, and risk assessment164165## Common Vulnerability Examples166167### Reentrancy168```solidity169// VULNERABLE170function withdraw(uint256 amount) external {171 require(balances[msg.sender] >= amount);172 (bool ok, ) = msg.sender.call{value: amount}(""); // external call BEFORE state173 require(ok);174 balances[msg.sender] -= amount; // state update AFTER175}176177// FIXED: CEI pattern178function withdraw(uint256 amount) external {179 require(balances[msg.sender] >= amount);180 balances[msg.sender] -= amount; // state update FIRST181 (bool ok, ) = msg.sender.call{value: amount}(""); // then external call182 require(ok);183}184```185186### Access Control187```solidity188// VULNERABLE: init function unprotected189function initialize(address _owner) external {190 owner = _owner; // anyone can call this191}192193// FIXED194function initialize(address _owner) external initializer {195 __Ownable_init(_owner);196}197```198199## Rules2001. Always start with threat modeling before writing any code — identify assets, trust boundaries, attack surfaces2012. Audit pipeline: scope → manual review → automated tooling → fuzz/invariant → formal verification → report2023. Economic security is as important as code security — analyze game theory and incentive alignment2034. Bug bounty programs follow Immunefi severity: Critical (up to $1M+), High ($50K-$100K), Medium ($5K-$20K), Low ($1K-$5K)2045. Incident response: freeze/pause contract → assess damage → communicate → fork coordination → post-mortem → compensation2056. Formal verification complements but does NOT replace manual review and fuzz testing2067. Always verify signature malleability (low-s for ECDSA), nonce reuse, and signature replay protection2078. Cross-chain bridges require additional security layers: rate limiting, circuit breakers, tiered security208209## References210 - references/audit-methodology.md — Smart Contract Audit Methodology211 - references/blockchain-security-advanced.md — Blockchain Security Advanced Topics212 - references/blockchain-security-fundamentals.md — Blockchain Security Fundamentals213 - references/bug-bounty-program.md — Bug Bounty Programs for Blockchain Projects214 - references/economic-security.md — Economic Security in Blockchain Systems215 - references/formal-verification-deep.md — Formal Verification for Smart Contracts216 - references/incident-response.md — Blockchain Incident Response217 - references/smart-contract-security.md — Smart Contract Security218 - references/threat-modeling.md — Threat Modeling for Blockchain Systems219 - references/blockchain-vulnerability-catalog.md — Common Blockchain Vulnerabilities Catalog220 - references/cross-chain-security.md — Cross-Chain Security Considerations221222## Phase223blockchain → blockchain-security224225---226> Source: [j4flmao/agent-skills](https://github.com/j4flmao/agent-skills) — distributed by [TomeVault](https://tomevault.io).227<!-- tomevault:4.0:skill_md:2026-06-16 -->