audit-system 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +351 -0
  3. package/agents/AGENT_REGISTRY.md +150 -0
  4. package/agents/assumption-analyzer.json +7 -0
  5. package/agents/assumption-analyzer.md +37 -0
  6. package/agents/composition-attacker.json +7 -0
  7. package/agents/composition-attacker.md +46 -0
  8. package/agents/economic-attacker.json +7 -0
  9. package/agents/economic-attacker.md +43 -0
  10. package/agents/exploit-writer.json +7 -0
  11. package/agents/exploit-writer.md +48 -0
  12. package/agents/orchestrator.json +16 -0
  13. package/agents/orchestrator.md +46 -0
  14. package/agents/report-writer.json +7 -0
  15. package/agents/report-writer.md +52 -0
  16. package/agents/state-machine-hacker.json +7 -0
  17. package/agents/state-machine-hacker.md +43 -0
  18. package/agents/test-generator.json +7 -0
  19. package/agents/test-generator.md +49 -0
  20. package/cli.js +93 -0
  21. package/config.json +74 -0
  22. package/lib/detect-lang.js +109 -0
  23. package/lib/install.js +229 -0
  24. package/lib/utils.js +41 -0
  25. package/obsidian-vault/README.md +103 -0
  26. package/obsidian-vault/attack-patterns/state-inconsistency.md +90 -0
  27. package/obsidian-vault/exploits/_index.md +109 -0
  28. package/obsidian-vault/exploits/beanstalk-2022.md +334 -0
  29. package/obsidian-vault/exploits/nomad-2022.md +295 -0
  30. package/obsidian-vault/exploits/ronin-2022.md +251 -0
  31. package/obsidian-vault/exploits/wormhole-2022.md +284 -0
  32. package/obsidian-vault/failed-hypotheses/_template.md +77 -0
  33. package/obsidian-vault/hypotheses/_template.md +43 -0
  34. package/obsidian-vault/hypotheses/bridge-protocol-template.md +254 -0
  35. package/obsidian-vault/hypotheses/dex-protocol-template.md +185 -0
  36. package/obsidian-vault/hypotheses/governance-protocol-template.md +263 -0
  37. package/obsidian-vault/hypotheses/lending-protocol-template.md +218 -0
  38. package/obsidian-vault/hypotheses/staking-protocol-template.md +223 -0
  39. package/obsidian-vault/invariant-catalog/defi-invariants.md +307 -0
  40. package/obsidian-vault/invariant-catalog/solana-invariants.md +213 -0
  41. package/obsidian-vault/novel-patterns/pattern-mutation-framework.md +316 -0
  42. package/obsidian-vault/reports/_template.md +92 -0
  43. package/obsidian-vault/research/cross-protocol-analysis/.gitkeep +0 -0
  44. package/obsidian-vault/research/emerging-threats/.gitkeep +0 -0
  45. package/obsidian-vault/research/protocol-specific/.gitkeep +0 -0
  46. package/obsidian-vault/test-strategies/fuzzing.md +75 -0
  47. package/obsidian-vault/vulnerabilities/access-control.md +122 -0
  48. package/obsidian-vault/vulnerabilities/flash-loan-attack.md +66 -0
  49. package/obsidian-vault/vulnerabilities/oracle-manipulation.md +135 -0
  50. package/obsidian-vault/vulnerabilities/reentrancy.md +141 -0
  51. package/obsidian-vault/vulnerabilities/rust-unsafe-deserialization.md +128 -0
  52. package/obsidian-vault/vulnerabilities/solana-account-confusion.md +125 -0
  53. package/obsidian-vault/vulnerabilities/solana-close-account.md +141 -0
  54. package/obsidian-vault/vulnerabilities/solana-cpi-attacks.md +131 -0
  55. package/obsidian-vault/vulnerabilities/solana-signer-authorization.md +119 -0
  56. package/package.json +56 -0
  57. package/skills/audit-connect.md +385 -0
  58. package/skills/auditor.md +280 -0
  59. package/skills/exploit-generator.md +394 -0
  60. package/skills/novel-discovery.md +551 -0
  61. package/skills/test-generator.md +511 -0
package/lib/install.js ADDED
@@ -0,0 +1,229 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+ import { getPackagePath, getProjectPath, getAuditSystemDir, getClaudeDir, copyDir, writeJson } from './utils.js';
5
+ import { detectLanguageSync, formatLanguage } from './detect-lang.js';
6
+
7
+ const AGENTS_LIST = [
8
+ 'orchestrator',
9
+ 'assumption-analyzer',
10
+ 'economic-attacker',
11
+ 'state-machine-hacker',
12
+ 'composition-attacker',
13
+ 'exploit-writer',
14
+ 'test-generator',
15
+ 'report-writer',
16
+ ];
17
+
18
+ const SKILLS_LIST = [
19
+ 'audit-connect',
20
+ 'auditor',
21
+ 'novel-discovery',
22
+ 'exploit-generator',
23
+ 'test-generator',
24
+ ];
25
+
26
+ export async function install(options = {}) {
27
+ const projectPath = options.projectPath || getProjectPath();
28
+ const forceLang = options.lang || null;
29
+ const auditDir = getAuditSystemDir(projectPath);
30
+ const claudeDir = getClaudeDir(projectPath);
31
+ const packagePath = getPackagePath();
32
+
33
+ console.log(chalk.blue.bold('\n=== Audit System Installer ===\n'));
34
+
35
+ // 1. Detect language
36
+ let lang = forceLang || detectLanguageSync(projectPath);
37
+ if (!lang) {
38
+ console.log(chalk.yellow('⚠ Nenhuma linguagem detectada automaticamente.'));
39
+ console.log(chalk.yellow(' Use --lang=solidity ou --lang=rust para forçar.\n'));
40
+ }
41
+ console.log(chalk.white(`📂 Projeto: ${projectPath}`));
42
+ console.log(chalk.white(`🌐 Linguagem: ${formatLanguage(lang)}\n`));
43
+
44
+ // 2. Create .audit-system directory
45
+ console.log(chalk.yellow('1. Criando .audit-system/...'));
46
+ await fs.ensureDir(auditDir);
47
+
48
+ // 3. Copy agents
49
+ console.log(chalk.yellow('2. Copiando agents...'));
50
+ const agentsDest = path.join(auditDir, 'agents');
51
+ await copyDir(path.join(packagePath, 'agents'), agentsDest);
52
+ console.log(chalk.green(` ✓ ${AGENTS_LIST.length} agents copiados`));
53
+
54
+ // 4. Copy skills
55
+ console.log(chalk.yellow('3. Copiando skills...'));
56
+ const skillsDest = path.join(auditDir, 'skills');
57
+ await copyDir(path.join(packagePath, 'skills'), skillsDest);
58
+ console.log(chalk.green(` ✓ ${SKILLS_LIST.length} skills copiadas`));
59
+
60
+ // 5. Copy vault
61
+ console.log(chalk.yellow('4. Copiando knowledge base...'));
62
+ const vaultDest = path.join(auditDir, 'vault');
63
+ await copyDir(path.join(packagePath, 'obsidian-vault'), vaultDest);
64
+ console.log(chalk.green(' ✓ Knowledge base copiada'));
65
+
66
+ // 6. Copy config
67
+ console.log(chalk.yellow('5. Copiando configuração...'));
68
+ const configSrc = path.join(packagePath, 'config.json');
69
+ const configDest = path.join(auditDir, 'config.json');
70
+ await fs.copy(configSrc, configDest);
71
+ console.log(chalk.green(' ✓ Configuração copiada'));
72
+
73
+ // 7. Write .env file with paths
74
+ console.log(chalk.yellow('6. Configurando variáveis...'));
75
+ const envContent = [
76
+ `AUDIT_SYSTEM_PATH="${auditDir}"`,
77
+ `AUDIT_AGENTS_PATH="${path.join(auditDir, 'agents')}"`,
78
+ `AUDIT_SKILLS_PATH="${path.join(auditDir, 'skills')}"`,
79
+ `AUDIT_VAULT_PATH="${path.join(auditDir, 'vault')}"`,
80
+ `AUDIT_LANG="${lang || 'auto'}"`,
81
+ `AUDIT_OUTPUT_PATH="${path.join(projectPath, 'audit-output')}"`,
82
+ `AUDIT_MODEL="auto-detect"`,
83
+ ``,
84
+ ].join('\n');
85
+ await fs.writeFile(path.join(auditDir, '.env'), envContent);
86
+ console.log(chalk.green(' ✓ Variáveis configuradas'));
87
+
88
+ // 8. Create .claude/ configuration
89
+ console.log(chalk.yellow('7. Configurando Claude Code...'));
90
+ const claudeSkillsDir = path.join(claudeDir, 'skills');
91
+ await fs.ensureDir(claudeSkillsDir);
92
+
93
+ // Copy the main skill to .claude/skills/
94
+ const mainSkillSrc = path.join(skillsDest, 'audit-connect.md');
95
+ const mainSkillDest = path.join(claudeSkillsDir, 'audit-connect.md');
96
+ if (await fs.pathExists(mainSkillSrc)) {
97
+ await fs.copy(mainSkillSrc, mainSkillDest);
98
+ }
99
+
100
+ // Create settings.json
101
+ const settingsPath = path.join(claudeDir, 'settings.json');
102
+ const settings = {
103
+ skills: {
104
+ 'audit-connect': {
105
+ description: 'Connect audit-system to current project and activate all resources',
106
+ type: 'prompt',
107
+ file: 'skills/audit-connect.md',
108
+ },
109
+ 'audit-agent': {
110
+ description: 'Execute specific audit agent',
111
+ type: 'prompt',
112
+ file: 'skills/audit-connect.md',
113
+ },
114
+ 'audit-status': {
115
+ description: 'Show audit-system connection status',
116
+ type: 'prompt',
117
+ file: 'skills/audit-connect.md',
118
+ },
119
+ 'audit-agents': {
120
+ description: 'List all available audit agents',
121
+ type: 'prompt',
122
+ file: 'skills/audit-connect.md',
123
+ },
124
+ },
125
+ };
126
+ await writeJson(settingsPath, settings);
127
+ console.log(chalk.green(' ✓ Claude Code configurado'));
128
+
129
+ // 9. Summary
130
+ console.log(chalk.blue.bold('\n=== Instalação Completa! ===\n'));
131
+ console.log(chalk.white('Resumo:'));
132
+ console.log(chalk.cyan(` 📁 .audit-system/ → Agents, skills, vault, config`));
133
+ console.log(chalk.cyan(` 📁 .claude/ → Configuração do Claude Code`));
134
+ console.log(chalk.cyan(` 🌐 Linguagem → ${formatLanguage(lang)}`));
135
+ console.log(chalk.cyan(` 🤖 Agents → ${AGENTS_LIST.length} especialistas`));
136
+ console.log(chalk.cyan(` 📝 Skills → ${SKILLS_LIST.length} prompts`));
137
+ console.log(chalk.cyan(` 📚 Vault → Knowledge base completo\n`));
138
+
139
+ console.log(chalk.white('Próximo passo:'));
140
+ console.log(chalk.green(' No Claude Code, digite: /audit-connect\n'));
141
+
142
+ return { lang, auditDir, claudeDir };
143
+ }
144
+
145
+ export async function showStatus(options = {}) {
146
+ const projectPath = options.projectPath || getProjectPath();
147
+ const auditDir = getAuditSystemDir(projectPath);
148
+ const claudeDir = getClaudeDir(projectPath);
149
+
150
+ const hasAuditDir = await fs.pathExists(auditDir);
151
+ const hasClaudeDir = await fs.pathExists(claudeDir);
152
+ const lang = detectLanguageSync(projectPath);
153
+
154
+ console.log(chalk.blue.bold('\n=== Audit System Status ===\n'));
155
+ console.log(chalk.white(`📂 Projeto: ${projectPath}`));
156
+ console.log(chalk.white(`🌐 Linguagem: ${formatLanguage(lang)}`));
157
+ console.log(chalk.white(`📁 .audit-system/: ${hasAuditDir ? chalk.green('✓') : chalk.red('✗')}`));
158
+ console.log(chalk.white(`📁 .claude/: ${hasClaudeDir ? chalk.green('✓') : chalk.red('✗')}`));
159
+ console.log();
160
+
161
+ if (hasAuditDir && hasClaudeDir) {
162
+ console.log(chalk.green('✓ Sistema instalado e configurado.'));
163
+ console.log(chalk.cyan(' Abra o Claude Code e digite /audit-connect\n'));
164
+ } else {
165
+ console.log(chalk.yellow('⚠ Sistema não está instalado neste projeto.'));
166
+ console.log(chalk.cyan(' Execute: npx audit-system connect\n'));
167
+ }
168
+ }
169
+
170
+ export async function listAgents() {
171
+ console.log(chalk.blue.bold('\n=== Audit System Agents ===\n'));
172
+ const agents = [
173
+ ['orchestrator', 'Coordinator', 'Coordena workflows multi-agente'],
174
+ ['assumption-analyzer', 'Specialist', 'Phase 1: Quebra de suposições'],
175
+ ['economic-attacker', 'Specialist', 'Phase 3: Modelagem econômica'],
176
+ ['state-machine-hacker', 'Specialist', 'Phase 4: Máquina de estados'],
177
+ ['composition-attacker', 'Specialist', 'Phase 5: Ataques por composição'],
178
+ ['exploit-writer', 'Implementer', 'PoCs em Solidity ou Rust/Anchor'],
179
+ ['test-generator', 'Implementer', 'Testes Foundry ou Anchor'],
180
+ ['report-writer', 'Documenter', 'Relatórios profissionais'],
181
+ ];
182
+ for (const [name, type, desc] of agents) {
183
+ console.log(chalk.cyan(` ${name.padEnd(22)} ${type.padEnd(14)} ${desc}`));
184
+ }
185
+ console.log(chalk.white('\n LANG-aware: ajustam análise para Solidity ou Rust.\n'));
186
+ }
187
+
188
+ export async function doctor(options = {}) {
189
+ const projectPath = options.projectPath || getProjectPath();
190
+ const auditDir = getAuditSystemDir(projectPath);
191
+ let allOk = true;
192
+
193
+ console.log(chalk.blue.bold('\n=== Audit System Doctor ===\n'));
194
+
195
+ // Check Node version
196
+ const nodeVer = process.version;
197
+ const major = parseInt(nodeVer.slice(1).split('.')[0]);
198
+ const nodeOk = major >= 16;
199
+ console.log(`${nodeOk ? chalk.green('✓') : chalk.red('✗')} Node.js: ${nodeVer} ${nodeOk ? '' : '(requer >= 16)'}`);
200
+ if (!nodeOk) allOk = false;
201
+
202
+ // Check audit-system directory
203
+ const hasAudit = await fs.pathExists(auditDir);
204
+ console.log(`${hasAudit ? chalk.green('✓') : chalk.red('✗')} .audit-system/: ${hasAudit ? 'Encontrado' : 'Não encontrado'}`);
205
+ if (!hasAudit) allOk = false;
206
+
207
+ // Check agents
208
+ if (hasAudit) {
209
+ const agentsDir = path.join(auditDir, 'agents');
210
+ const hasAgents = await fs.pathExists(agentsDir);
211
+ console.log(`${hasAgents ? chalk.green('✓') : chalk.red('✗')} Agents: ${hasAgents ? 'Presentes' : 'Ausentes'}`);
212
+ if (!hasAgents) allOk = false;
213
+ }
214
+
215
+ // Check Claude config
216
+ const hasClaude = await fs.pathExists(getClaudeDir(projectPath));
217
+ console.log(`${hasClaude ? chalk.green('✓') : chalk.yellow('⚠')} .claude/: ${hasClaude ? 'Configurado' : 'Não configurado (necessário para Claude Code)'}`);
218
+
219
+ // Check language
220
+ const lang = detectLanguageSync(projectPath);
221
+ console.log(`${lang ? chalk.green('✓') : chalk.yellow('⚠')} Linguagem: ${formatLanguage(lang) || 'Não detectada (use --lang=)'}`);
222
+
223
+ console.log();
224
+ if (allOk) {
225
+ console.log(chalk.green('✓ Tudo OK! Sistema pronto para uso.\n'));
226
+ } else {
227
+ console.log(chalk.yellow('⚠ Alguns problemas encontrados. Execute: npx audit-system connect\n'));
228
+ }
229
+ }
package/lib/utils.js ADDED
@@ -0,0 +1,41 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ const PACKAGE_ROOT = path.resolve(__dirname, '..');
8
+
9
+ export function getPackagePath() {
10
+ return PACKAGE_ROOT;
11
+ }
12
+
13
+ export function getProjectPath() {
14
+ return process.cwd();
15
+ }
16
+
17
+ export function getAuditSystemDir(projectPath) {
18
+ return path.join(projectPath, '.audit-system');
19
+ }
20
+
21
+ export function getClaudeDir(projectPath) {
22
+ return path.join(projectPath, '.claude');
23
+ }
24
+
25
+ export async function copyDir(src, dest) {
26
+ await fs.ensureDir(dest);
27
+ await fs.copy(src, dest, {
28
+ filter: (srcPath) => {
29
+ const basename = path.basename(srcPath);
30
+ return basename !== 'node_modules';
31
+ }
32
+ });
33
+ }
34
+
35
+ export async function writeJson(filePath, obj) {
36
+ await fs.writeFile(filePath, JSON.stringify(obj, null, 2) + '\n');
37
+ }
38
+
39
+ export function resolvePath(...segments) {
40
+ return path.resolve(...segments);
41
+ }
@@ -0,0 +1,103 @@
1
+ # Audit System — Knowledge Base
2
+
3
+ tags: #index #home
4
+
5
+ ---
6
+
7
+ ## Structure
8
+
9
+ ```
10
+ obsidian-vault/
11
+ ├── vulnerabilities/ ← Known vulnerability types with PoC
12
+ ├── attack-patterns/ ← Abstract attack patterns
13
+ ├── hypotheses/ ← Active attack hypotheses per audit
14
+ ├── poc/ ← Completed proof of concepts
15
+ ├── test-strategies/ ← Testing methodologies
16
+ ├── reports/ ← Completed audit reports
17
+ ├── failed-hypotheses/ ← What didn't work + why
18
+ ├── invariant-catalog/ ← DeFi invariants that can be violated
19
+ ├── novel-patterns/ ← Novel discovery frameworks
20
+ └── research/ ← Research materials
21
+ ├── emerging-threats/ ← New attack research
22
+ ├── protocol-specific/ ← Protocol-specific knowledge
23
+ └── cross-protocol-analysis/ ← Multi-protocol studies
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Vulnerability Index
29
+
30
+ | Vulnerability | Severity | Notes |
31
+ |---|---|---|
32
+ | [[vulnerabilities/reentrancy]] | CRITICAL | CEI pattern |
33
+ | [[vulnerabilities/access-control]] | CRITICAL/HIGH | Modifiers |
34
+ | [[vulnerabilities/oracle-manipulation]] | CRITICAL | TWAP |
35
+ | [[vulnerabilities/flash-loan-attack]] | CRITICAL | Atomicity |
36
+
37
+ ---
38
+
39
+ ## Attack Patterns
40
+
41
+ - [[attack-patterns/state-inconsistency]] — Root cause of many bugs
42
+ - [[attack-patterns/privilege-escalation]] — Access control bypass
43
+ - [[attack-patterns/price-manipulation]] — Oracle attacks
44
+
45
+ ---
46
+
47
+ ## Novel Discovery Resources
48
+
49
+ - [[invariant-catalog/defi-invariants]] — Common invariants to test
50
+ - [[novel-patterns/pattern-mutation-framework]] — Mutate patterns for novel attacks
51
+ - [[failed-hypotheses/_template]] — Learn from failed attempts
52
+
53
+ ---
54
+
55
+ ## Test Strategies
56
+
57
+ - [[test-strategies/fuzzing]] — Automated random testing
58
+ - [[test-strategies/invariant-testing]] — Property-based testing
59
+
60
+ ---
61
+
62
+ ## Workflow
63
+
64
+ ### Standard Audit
65
+ ```
66
+ New Audit
67
+
68
+ Create hypothesis in hypotheses/
69
+
70
+ Cross-reference vulnerabilities/
71
+
72
+ Build PoC in Foundry
73
+
74
+ Save result (confirmed → poc/, refuted → failed-hypotheses/)
75
+
76
+ Write report entry in reports/
77
+ ```
78
+
79
+ ### Novel Discovery Audit
80
+ ```
81
+ Standard Audit Pass
82
+
83
+ Apply novel discovery (see skills/novel-discovery.md)
84
+
85
+ Map assumptions → Break assumptions → Economic model
86
+
87
+ State machine analysis → Composition attacks
88
+
89
+ Generate novel hypotheses
90
+
91
+ Test and document in hypotheses/
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Skills Reference
97
+
98
+ | Skill | Purpose |
99
+ |---|---|
100
+ | [[../skills/auditor]] | Full contract analysis |
101
+ | [[../skills/exploit-generator]] | PoC creation |
102
+ | [[../skills/test-generator]] | Test suite generation |
103
+ | [[../skills/novel-discovery]] | Novel vulnerability discovery |
@@ -0,0 +1,90 @@
1
+ # State Inconsistency Pattern
2
+
3
+ tags: #pattern #state #reentrancy #critical
4
+
5
+ ---
6
+
7
+ ## Description
8
+ State becomes inconsistent when multiple variables must be updated atomically but aren't. This is the root cause behind reentrancy, cross-function attacks, and many logic bugs.
9
+
10
+ ---
11
+
12
+ ## Hypothesis Framework
13
+
14
+ ```
15
+ Given: Variable A and Variable B must always satisfy: A == f(B)
16
+
17
+ Attack vector:
18
+ 1. Read A (stale value)
19
+ 2. External interaction happens
20
+ 3. B is updated
21
+ 4. A is NOT updated
22
+ 5. Invariant A == f(B) broken
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Common Manifestations
28
+
29
+ ### Reentrancy Root Cause
30
+ ```
31
+ balance[user] → not zeroed before external call
32
+ External call → re-enters → reads stale balance
33
+ Withdraws again using stale balance
34
+ ```
35
+
36
+ ### Cross-Function State Bug
37
+ ```
38
+ Function A: sets state = PROCESSING
39
+ External call in A
40
+ Function B: checks state == IDLE (stale) and executes
41
+ State becomes inconsistent
42
+ ```
43
+
44
+ ### Snapshot Manipulation
45
+ ```
46
+ Snapshot taken at block N
47
+ Attacker front-runs to inflate balance
48
+ Snapshot shows inflated balance
49
+ Attacker claims reward/vote based on fake snapshot
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Detection Questions
55
+
56
+ ```
57
+ 1. Are there multiple state variables that must be updated together?
58
+ 2. Is there any external call between reads and writes?
59
+ 3. Can state be read between partial updates?
60
+ 4. Is there a time gap where state is inconsistent?
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Test Strategy
66
+
67
+ ```solidity
68
+ function test_stateConsistency() public {
69
+ // Record state at point A
70
+ uint256 stateA = target.variableA();
71
+ uint256 stateB = target.variableB();
72
+
73
+ // Verify invariant holds before
74
+ assertTrue(checkInvariant(stateA, stateB));
75
+
76
+ // Perform operation
77
+ target.operation();
78
+
79
+ // Verify invariant holds after
80
+ stateA = target.variableA();
81
+ stateB = target.variableB();
82
+ assertTrue(checkInvariant(stateA, stateB));
83
+ }
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Links
89
+ - [[vulnerabilities/reentrancy]]
90
+ - [[vulnerabilities/access-control]]
@@ -0,0 +1,109 @@
1
+ # Real-World Exploit Index
2
+
3
+ This directory contains detailed analyses of real-world smart contract exploits. Use these as reference when auditing similar protocols.
4
+
5
+ ---
6
+
7
+ ## Bridge Exploits
8
+
9
+ | Exploit | Year | Loss | Vector | Relevance |
10
+ |---------|------|------|--------|-----------|
11
+ | [[ronin-2022]] | 2022 | $625M | Validator compromise | High - Multi-sig bridges |
12
+ | [[wormhole-2022]] | 2022 | $325M | Signature verification | High - All signature-based bridges |
13
+ | [[nomad-2022]] | 2022 | $190M | Replay/Merkle root | Medium - Optimistic verification |
14
+ | [[harmony-2022]] | 2022 | $100M | Multi-sig compromise | High - Multi-sig bridges |
15
+
16
+ ---
17
+
18
+ ## Governance Exploits
19
+
20
+ | Exploit | Year | Loss | Vector | Relevance |
21
+ |---------|------|------|--------|-----------|
22
+ | [[beanstalk-2022]] | 2022 | $182M | Flash loan governance | High - Token-based governance |
23
+ | [[dao-2016]] | 2016 | $60M | Reentrancy | Medium - Historical reference |
24
+
25
+ ---
26
+
27
+ ## DEX Exploits
28
+
29
+ | Exploit | Year | Loss | Vector | Relevance |
30
+ |---------|------|------|--------|-----------|
31
+ | [[bancor-2018]] | 2018 | $13.5M | Reentrancy + oracle | Medium - AMM DEXs |
32
+ | [[uni-v1-2021]] | 2021 | Multiple | Price manipulation | High - Spot price reliance |
33
+
34
+ ---
35
+
36
+ ## Lending Exploits
37
+
38
+ | Exploit | Year | Loss | Vector | Relevance |
39
+ |---------|------|------|--------|-----------|
40
+ | [[cream-2021]] | 2021 | $130M | Flash loan manipulation | High - Lending protocols |
41
+ | [[euler-2023]] | 2023 | $200M | Donation attack | High - Lending protocols |
42
+
43
+ ---
44
+
45
+ ## How to Use This Index
46
+
47
+ ### During Audit Preparation
48
+ 1. Identify protocol type (DEX, lending, bridge, governance)
49
+ 2. Review relevant exploits
50
+ 3. Add exploit patterns to hypothesis generation
51
+
52
+ ### During Hypothesis Generation
53
+ 1. For each hypothesis, ask: "Has this happened before?"
54
+ 2. If yes, study the exploit details
55
+ 3. Adapt the attack vector to current protocol
56
+
57
+ ### During PoC Development
58
+ 1. Use exploit code as template
59
+ 2. Adapt to current protocol's specifics
60
+ 3. Test if same vulnerability exists
61
+
62
+ ---
63
+
64
+ ## Common Patterns Across Exploits
65
+
66
+ ### 1. Signature/Verification Failures
67
+ - [[ronin-2022]] - Validator key compromise
68
+ - [[wormhole-2022]] - Signature not bound to message
69
+ - [[harmony-2022]] - Multi-sig key compromise
70
+
71
+ **Detection:** Always verify signature binding, key management
72
+
73
+ ### 2. Replay Attacks
74
+ - [[nomad-2022]] - Merkle proof replay
75
+ - Multiple bridges - Cross-chain replay
76
+
77
+ **Detection:** Nonce tracking, chain ID inclusion
78
+
79
+ ### 3. Governance Capture
80
+ - [[beanstalk-2022]] - Flash loan voting
81
+ - Various - Whale manipulation
82
+
83
+ **Detection:** Lockup requirements, vote caps
84
+
85
+ ### 4. Oracle Manipulation
86
+ - Multiple exploits - Price feed manipulation
87
+
88
+ **Detection:** TWAP, multiple sources, sanity checks
89
+
90
+ ---
91
+
92
+ ## Hypothesis Templates by Exploit Type
93
+
94
+ Use these when starting an audit:
95
+
96
+ ```
97
+ Given [PROTOCOL TYPE], could [EXPLOIT TYPE] from [[EXPLOIT NAME]] happen here?
98
+
99
+ Example:
100
+ Given this lending protocol, could flash loan manipulation
101
+ from [[cream-2021]] happen here?
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Related Resources
107
+ - [[../hypotheses/]] - Protocol-specific hypothesis templates
108
+ - [[../vulnerabilities/]] - Vulnerability pattern documentation
109
+ - [[../attack-patterns/]] - Attack pattern catalog