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.
- package/LICENSE +21 -0
- package/README.md +351 -0
- package/agents/AGENT_REGISTRY.md +150 -0
- package/agents/assumption-analyzer.json +7 -0
- package/agents/assumption-analyzer.md +37 -0
- package/agents/composition-attacker.json +7 -0
- package/agents/composition-attacker.md +46 -0
- package/agents/economic-attacker.json +7 -0
- package/agents/economic-attacker.md +43 -0
- package/agents/exploit-writer.json +7 -0
- package/agents/exploit-writer.md +48 -0
- package/agents/orchestrator.json +16 -0
- package/agents/orchestrator.md +46 -0
- package/agents/report-writer.json +7 -0
- package/agents/report-writer.md +52 -0
- package/agents/state-machine-hacker.json +7 -0
- package/agents/state-machine-hacker.md +43 -0
- package/agents/test-generator.json +7 -0
- package/agents/test-generator.md +49 -0
- package/cli.js +93 -0
- package/config.json +74 -0
- package/lib/detect-lang.js +109 -0
- package/lib/install.js +229 -0
- package/lib/utils.js +41 -0
- package/obsidian-vault/README.md +103 -0
- package/obsidian-vault/attack-patterns/state-inconsistency.md +90 -0
- package/obsidian-vault/exploits/_index.md +109 -0
- package/obsidian-vault/exploits/beanstalk-2022.md +334 -0
- package/obsidian-vault/exploits/nomad-2022.md +295 -0
- package/obsidian-vault/exploits/ronin-2022.md +251 -0
- package/obsidian-vault/exploits/wormhole-2022.md +284 -0
- package/obsidian-vault/failed-hypotheses/_template.md +77 -0
- package/obsidian-vault/hypotheses/_template.md +43 -0
- package/obsidian-vault/hypotheses/bridge-protocol-template.md +254 -0
- package/obsidian-vault/hypotheses/dex-protocol-template.md +185 -0
- package/obsidian-vault/hypotheses/governance-protocol-template.md +263 -0
- package/obsidian-vault/hypotheses/lending-protocol-template.md +218 -0
- package/obsidian-vault/hypotheses/staking-protocol-template.md +223 -0
- package/obsidian-vault/invariant-catalog/defi-invariants.md +307 -0
- package/obsidian-vault/invariant-catalog/solana-invariants.md +213 -0
- package/obsidian-vault/novel-patterns/pattern-mutation-framework.md +316 -0
- package/obsidian-vault/reports/_template.md +92 -0
- package/obsidian-vault/research/cross-protocol-analysis/.gitkeep +0 -0
- package/obsidian-vault/research/emerging-threats/.gitkeep +0 -0
- package/obsidian-vault/research/protocol-specific/.gitkeep +0 -0
- package/obsidian-vault/test-strategies/fuzzing.md +75 -0
- package/obsidian-vault/vulnerabilities/access-control.md +122 -0
- package/obsidian-vault/vulnerabilities/flash-loan-attack.md +66 -0
- package/obsidian-vault/vulnerabilities/oracle-manipulation.md +135 -0
- package/obsidian-vault/vulnerabilities/reentrancy.md +141 -0
- package/obsidian-vault/vulnerabilities/rust-unsafe-deserialization.md +128 -0
- package/obsidian-vault/vulnerabilities/solana-account-confusion.md +125 -0
- package/obsidian-vault/vulnerabilities/solana-close-account.md +141 -0
- package/obsidian-vault/vulnerabilities/solana-cpi-attacks.md +131 -0
- package/obsidian-vault/vulnerabilities/solana-signer-authorization.md +119 -0
- package/package.json +56 -0
- package/skills/audit-connect.md +385 -0
- package/skills/auditor.md +280 -0
- package/skills/exploit-generator.md +394 -0
- package/skills/novel-discovery.md +551 -0
- package/skills/test-generator.md +511 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Cross-Program Invocation (CPI) Attacks
|
|
2
|
+
|
|
3
|
+
tags: #vulnerability #solana #cpi #critical
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Summary
|
|
8
|
+
Cross-Program Invocation (CPI) allows Solana programs to call other programs. If not properly secured, CPIs can lead to reentrancy, unauthorized actions, and privilege escalation.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Pattern Recognition
|
|
13
|
+
|
|
14
|
+
### Code Signals
|
|
15
|
+
- `invoke()` or `invoke_signed()` calls
|
|
16
|
+
- CPI to programs whose address comes from user input
|
|
17
|
+
- Missing return value checks on CPI
|
|
18
|
+
- PDA signing with uncontrolled seeds
|
|
19
|
+
- Programs that call back (callbacks via CPI)
|
|
20
|
+
|
|
21
|
+
### Detection Query
|
|
22
|
+
```
|
|
23
|
+
Is the CPI target program address hardcoded or user-provided?
|
|
24
|
+
Is the CPI return value checked?
|
|
25
|
+
Can the called program reenter the caller?
|
|
26
|
+
Are PDA seeds validated before signing?
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Variants
|
|
32
|
+
|
|
33
|
+
### CPI Reentrancy
|
|
34
|
+
```
|
|
35
|
+
Program A calls Program B via CPI
|
|
36
|
+
Program B calls back into Program A
|
|
37
|
+
Program A's state is in an inconsistent mid-transaction state
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Arbitrary CPI
|
|
41
|
+
```
|
|
42
|
+
Attacker controls which program is called
|
|
43
|
+
Malicious program returns fabricated data
|
|
44
|
+
Caller trusts unchecked CPI result
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### PDA Signing Bypass
|
|
48
|
+
```
|
|
49
|
+
Program B expects PDA-signed CPI from Program A
|
|
50
|
+
Program A's seeds can be manipulated
|
|
51
|
+
Attacker signs for wrong PDA
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### CPI Return Value Manipulation
|
|
55
|
+
```
|
|
56
|
+
Program A calls Program B for a price
|
|
57
|
+
Program B returns manipulated price
|
|
58
|
+
Program A acts on false data
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Attack Strategy
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
1. Find a CPI that calls an external program
|
|
67
|
+
2. Check if the program address is validated
|
|
68
|
+
3. If yes, check if reentrancy is possible
|
|
69
|
+
4. If the called program can call back during CPI:
|
|
70
|
+
- Enter the first function
|
|
71
|
+
- CPI triggers callback
|
|
72
|
+
- Callback reenters caller before state update
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Detection Signals
|
|
78
|
+
- CPI with user-provided `program_id`
|
|
79
|
+
- No `require_keys_eq!` on program address
|
|
80
|
+
- `invoke` instead of `invoke_signed` where PDA signing needed
|
|
81
|
+
- Missing `Ok(())` return check from CPI
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## PoC Template (Rust)
|
|
86
|
+
|
|
87
|
+
```rust
|
|
88
|
+
#[program]
|
|
89
|
+
pub fn exploit(ctx: Context<ExploitCpi>) -> Result<()> {
|
|
90
|
+
// Call target which will CPI back to us
|
|
91
|
+
let target = &ctx.accounts.target_program;
|
|
92
|
+
let ix = target::instruction::vulnerable_fn(
|
|
93
|
+
ctx.accounts.target_data.key(),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
invoke(&ix, &[/* accounts */])?; // Callback triggers reentrancy
|
|
97
|
+
Ok(())
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Fix
|
|
104
|
+
|
|
105
|
+
```rust
|
|
106
|
+
// 1. Validate program ID
|
|
107
|
+
require_keys_eq!(
|
|
108
|
+
ctx.accounts.target_program.key(),
|
|
109
|
+
EXPECTED_PROGRAM_ID
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// 2. Check CPI return
|
|
113
|
+
let result = invoke(&ix, &accounts);
|
|
114
|
+
require!(result.is_ok(), MyError::CpiFailed);
|
|
115
|
+
|
|
116
|
+
// 3. Use reentrancy guard
|
|
117
|
+
// Update state BEFORE CPI call
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Real World Examples
|
|
123
|
+
- Solana Wormhole bridge (2022) — $320M lost via CPI validation bypass
|
|
124
|
+
- Cashio App (2022) — Arbitrary CPI allowed minting unbacked tokens
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Links
|
|
129
|
+
- [[solana-account-confusion]]
|
|
130
|
+
- [[solana-signer-authorization]]
|
|
131
|
+
- [[reentrancy]] (Solana variant)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Signer & Authorization Vulnerabilities (Solana)
|
|
2
|
+
|
|
3
|
+
tags: #vulnerability #solana #signer #authorization #critical
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Summary
|
|
8
|
+
Solana requires explicit signer checks on every account that needs authorization. Missing or incorrect signer checks allow attackers to impersonate any user.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Pattern Recognition
|
|
13
|
+
|
|
14
|
+
### Code Signals (Anchor)
|
|
15
|
+
- `AccountInfo` without `Signer` type
|
|
16
|
+
- `UncheckedAccount` used where authorization is needed
|
|
17
|
+
- Missing `#[account(signer)]` constraint
|
|
18
|
+
- Missing `owner` field check on token accounts
|
|
19
|
+
- Authority check done AFTER state modification
|
|
20
|
+
|
|
21
|
+
### Detection Query
|
|
22
|
+
```
|
|
23
|
+
Does every state-modifying instruction check msg.signer equivalent?
|
|
24
|
+
Are `Signer` types used for all authorized actors?
|
|
25
|
+
Is the authority check performed BEFORE state mutation?
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Variants
|
|
31
|
+
|
|
32
|
+
### Missing Signer Check
|
|
33
|
+
```
|
|
34
|
+
Instruction accepts any account as "authority"
|
|
35
|
+
No Signer constraint → attacker passes any pubkey
|
|
36
|
+
State modified without real authorization
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Owner Check Bypass
|
|
40
|
+
```
|
|
41
|
+
Token account owner not verified
|
|
42
|
+
Attacker passes someone else's token account
|
|
43
|
+
Funds transferred from wrong account
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Delegate Authorization
|
|
47
|
+
```
|
|
48
|
+
SPL token delegate permissions not checked
|
|
49
|
+
Attacker uses own delegation to move other's tokens
|
|
50
|
+
Missing `delegated_amount` verification
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Attack Strategy
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
1. Find instruction with authority-like account parameter
|
|
59
|
+
2. Check if `Signer` constraint or `is_signer` check exists
|
|
60
|
+
3. If missing, call instruction with victim's pubkey
|
|
61
|
+
4. State is modified as if victim authorized it
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Detection Signals
|
|
67
|
+
- `Account` type without `Signer` for authority roles
|
|
68
|
+
- `has_one = authority` but no `Signer` constraint
|
|
69
|
+
- Manual `owner` field check not followed by `require_signer`
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## PoC Template (Anchor/TS)
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
it("missing signer check", async () => {
|
|
77
|
+
// Attacker calls without being the authority
|
|
78
|
+
const tx = await program.methods
|
|
79
|
+
.adminAction()
|
|
80
|
+
.accounts({
|
|
81
|
+
authority: victim.publicKey, // Not a signer!
|
|
82
|
+
// ... other accounts
|
|
83
|
+
})
|
|
84
|
+
.signers([attacker]) // Only attacker signs
|
|
85
|
+
.rpc();
|
|
86
|
+
|
|
87
|
+
// Assert: unauthorized action succeeded
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Fix
|
|
94
|
+
|
|
95
|
+
```rust
|
|
96
|
+
// Anchor: use Signer type
|
|
97
|
+
#[derive(Accounts)]
|
|
98
|
+
pub struct AdminAction<'info> {
|
|
99
|
+
#[account(signer)] // <-- REQUIRED
|
|
100
|
+
pub authority: Signer<'info>,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Or manual:
|
|
104
|
+
require!(ctx.accounts.authority.is_signer, MyError::NotSigner);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Real World Examples
|
|
110
|
+
- Multiple Solana bridge hacks
|
|
111
|
+
- Solend protocol — initial admin key lacked proper signer constraints
|
|
112
|
+
- Various Solana NFT projects with missing owner checks
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Links
|
|
117
|
+
- [[solana-account-confusion]]
|
|
118
|
+
- [[solana-cpi-attacks]]
|
|
119
|
+
- [[access-control]]
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "audit-system",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Multi-agent smart contract security auditing framework for Solidity (EVM) and Rust (Solana/Anchor) — installable via npx",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"audit-system": "./cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"cli.js",
|
|
11
|
+
"lib/",
|
|
12
|
+
"agents/",
|
|
13
|
+
"skills/",
|
|
14
|
+
"obsidian-vault/",
|
|
15
|
+
"config.json"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"setup": "node scripts/setup.js",
|
|
19
|
+
"test": "node scripts/test.js",
|
|
20
|
+
"prepublishOnly": "node scripts/test.js"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"smart-contracts",
|
|
24
|
+
"security",
|
|
25
|
+
"auditing",
|
|
26
|
+
"vulnerability",
|
|
27
|
+
"blockchain",
|
|
28
|
+
"solidity",
|
|
29
|
+
"rust",
|
|
30
|
+
"solana",
|
|
31
|
+
"anchor",
|
|
32
|
+
"claude-code",
|
|
33
|
+
"multi-agent"
|
|
34
|
+
],
|
|
35
|
+
"author": "Jorge Paim",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/MrAiKen007/audit-system.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/MrAiKen007/audit-system/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/MrAiKen007/audit-system#readme",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=16.0.0"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"chalk": "^5.6.2",
|
|
50
|
+
"fs-extra": "^11.3.4",
|
|
51
|
+
"minimist": "^1.2.8"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^20.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Connects current audited project to audit-system resources and activates the multi-agent audit framework using claude-opus-4-6 model
|
|
3
|
+
type: skill
|
|
4
|
+
commands:
|
|
5
|
+
- audit-connect
|
|
6
|
+
- audit-init
|
|
7
|
+
- use-audit-system
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Audit Connect Skill
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
|
|
14
|
+
Ativa o audit-system a partir de qualquer diretório de projeto, conectando TODOS os recursos (skills, agents, obsidian-vault) ao projeto atual.
|
|
15
|
+
|
|
16
|
+
## Modelo Utilizado
|
|
17
|
+
|
|
18
|
+
**Modelo Padrão:** `claude-opus-4-6`
|
|
19
|
+
|
|
20
|
+
Todos os agents são executados com o modelo mais poderoso disponível para garantir análises complexas de vulnerabilidades.
|
|
21
|
+
|
|
22
|
+
## Detecção Automática de Linguagem
|
|
23
|
+
|
|
24
|
+
O sistema detecta automaticamente se o projeto alvo usa **Solidity** (EVM) ou **Rust** (Solana/Anchor/ink!):
|
|
25
|
+
|
|
26
|
+
| Sinal | Linguagem Detectada |
|
|
27
|
+
|-------|-------------------|
|
|
28
|
+
| Arquivos `*.sol` | Solidity |
|
|
29
|
+
| `Anchor.toml` + `Cargo.toml` | Rust (Solana/Anchor) |
|
|
30
|
+
| `Cargo.toml` com dependência `ink` | Rust (ink!/Polkadot) |
|
|
31
|
+
| `Cargo.toml` + pastas `programs/` ou `src/` com `*.rs` | Rust (genérico) |
|
|
32
|
+
| Ambos presentes | Pergunta ao usuário ou roda em modo `both` |
|
|
33
|
+
|
|
34
|
+
**Override manual:**
|
|
35
|
+
```
|
|
36
|
+
/audit-connect --lang=solidity
|
|
37
|
+
/audit-connect --lang=rust
|
|
38
|
+
/audit-connect --lang=both
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
A variável `AUDIT_LANG` é definida e todos os agents a consultam para ajustar seus prompts.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
Quando estiver no diretório de um projeto a ser auditado, execute:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
/audit-connect
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Ou com parâmetros:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
/audit-connect --phase=assumption-analysis --target=./contracts
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## O que este skill faz (Integração Completa)
|
|
58
|
+
|
|
59
|
+
### 1. **Carrega Configuração**
|
|
60
|
+
- Lê `config.json` do audit-system
|
|
61
|
+
- Configura `default_model: "claude-opus-4-6"`
|
|
62
|
+
- Registra todos os caminhos (agents, skills, vault)
|
|
63
|
+
|
|
64
|
+
### 2. **Registra 8 Agents Especializados**
|
|
65
|
+
```
|
|
66
|
+
Agents carregados de: $AUDIT_SYSTEM_PATH/agents/
|
|
67
|
+
|
|
68
|
+
✓ orchestrator.json - Coordenador de workflows
|
|
69
|
+
✓ assumption-analyzer.json - Phase 1: Quebra de suposições
|
|
70
|
+
✓ economic-attacker.json - Phase 3: Modelagem econômica
|
|
71
|
+
✓ state-machine-hacker.json - Phase 4: Máquina de estados
|
|
72
|
+
✓ composition-attacker.json - Phase 5: Ataques por composição
|
|
73
|
+
✓ exploit-writer.json - Criação de PoCs
|
|
74
|
+
✓ test-generator.json - Geração de testes
|
|
75
|
+
✓ report-writer.json - Compilação de relatórios
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. **Carrega 5 Skills no Contexto**
|
|
79
|
+
```
|
|
80
|
+
Skills disponíveis:
|
|
81
|
+
|
|
82
|
+
✓ auditor.md - Workflow de auditoria padrão
|
|
83
|
+
✓ novel-discovery.md - Framework 6 fases COMPLETO
|
|
84
|
+
✓ exploit-generator.md - Templates de exploits
|
|
85
|
+
✓ test-generator.md - Templates de testes Foundry
|
|
86
|
+
✓ audit-connect.md - Este skill (recursivo)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. **Indexa Obsidian-Vault (Knowledge Base)**
|
|
90
|
+
```
|
|
91
|
+
Knowledge base carregado:
|
|
92
|
+
|
|
93
|
+
✓ vulnerabilities/ (4 arquivos)
|
|
94
|
+
- reentrancy.md
|
|
95
|
+
- access-control.md
|
|
96
|
+
- oracle-manipulation.md
|
|
97
|
+
- flash-loan-attack.md
|
|
98
|
+
|
|
99
|
+
✓ hypotheses/ (1 template)
|
|
100
|
+
- _template.md
|
|
101
|
+
|
|
102
|
+
✓ invariant-catalog/ (1 catálogo)
|
|
103
|
+
- defi-invariants.md
|
|
104
|
+
|
|
105
|
+
✓ novel-patterns/ (1 framework)
|
|
106
|
+
- pattern-mutation-framework.md
|
|
107
|
+
|
|
108
|
+
✓ attack-patterns/ (1 padrão)
|
|
109
|
+
- state-inconsistency.md
|
|
110
|
+
|
|
111
|
+
✓ test-strategies/ (1 estratégia)
|
|
112
|
+
- fuzzing.md
|
|
113
|
+
|
|
114
|
+
✓ reports/ (1 template)
|
|
115
|
+
- _template.md
|
|
116
|
+
|
|
117
|
+
✓ research/ (3 diretórios)
|
|
118
|
+
- emerging-threats/
|
|
119
|
+
- protocol-specific/
|
|
120
|
+
- cross-protocol-analysis/
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 5. **Detecta Linguagem do Projeto**
|
|
124
|
+
- Busca por arquivos `*.sol`, `Anchor.toml`, `Cargo.toml`, `*.rs`
|
|
125
|
+
- Define `AUDIT_LANG = solidity | rust | both`
|
|
126
|
+
- Se `both` e nenhum `--lang` passado, pergunta ao usuário
|
|
127
|
+
|
|
128
|
+
### 6. **Cria Estrutura de Output**
|
|
129
|
+
```
|
|
130
|
+
No projeto atual:
|
|
131
|
+
./audit-output/
|
|
132
|
+
├── findings/
|
|
133
|
+
├── exploits/
|
|
134
|
+
├── tests/
|
|
135
|
+
└── report.md
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Se `AUDIT_LANG == rust`:
|
|
139
|
+
```
|
|
140
|
+
./audit-output/
|
|
141
|
+
├── rust/
|
|
142
|
+
│ ├── findings/
|
|
143
|
+
│ ├── exploits/
|
|
144
|
+
│ ├── tests/
|
|
145
|
+
│ └── report.md
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 7. **Configura Variáveis de Ambiente**
|
|
149
|
+
```
|
|
150
|
+
AUDIT_SYSTEM_PATH="<diretório do .audit-system/>"
|
|
151
|
+
AUDIT_AGENTS_PATH="$AUDIT_SYSTEM_PATH/agents"
|
|
152
|
+
AUDIT_SKILLS_PATH="$AUDIT_SYSTEM_PATH/skills"
|
|
153
|
+
AUDIT_VAULT_PATH="$AUDIT_SYSTEM_PATH/vault"
|
|
154
|
+
AUDIT_MODEL="claude-opus-4-6"
|
|
155
|
+
AUDIT_PROJECT_PATH="<diretório atual>"
|
|
156
|
+
AUDIT_OUTPUT_PATH="./audit-output"
|
|
157
|
+
AUDIT_LANG="solidity | rust | both"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Workflow de Integração
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
[Projeto Auditado]
|
|
164
|
+
↓
|
|
165
|
+
/audit-connect ← SKILL de ativação
|
|
166
|
+
↓
|
|
167
|
+
[Carrega Config] ← config.json (model: claude-opus-4-6)
|
|
168
|
+
↓
|
|
169
|
+
[Detecta Linguagem] ← .sol → solidity | Cargo.toml+Anchor.toml → rust
|
|
170
|
+
↓
|
|
171
|
+
[Registra Agents] ← 8 agents de ./agents/ (modo LANG-aware)
|
|
172
|
+
↓
|
|
173
|
+
[Carrega Skills] ← 5 skills de ./skills/
|
|
174
|
+
↓
|
|
175
|
+
[Indexa Vault] ← knowledge base de ./obsidian-vault/ (incl. Rust/Solana)
|
|
176
|
+
↓
|
|
177
|
+
[Cria Output Dir] ← ./audit-output/ (estrutura por linguagem)
|
|
178
|
+
↓
|
|
179
|
+
[Sistema Conectado] ← AUDIT_LANG=solidity|rust|both
|
|
180
|
+
↓
|
|
181
|
+
Escolha do agente → Execução → Resultados
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Agents Disponíveis
|
|
185
|
+
|
|
186
|
+
Após conectar, os seguintes agentes podem ser invocados:
|
|
187
|
+
|
|
188
|
+
| Agente | Comando | Descrição | Recursos Utilizados |
|
|
189
|
+
|--------|---------|-----------|---------------------|
|
|
190
|
+
| orchestrator | `/audit-agent full` | Coordena todos os agents (modo LANG-aware) | Todos os recursos |
|
|
191
|
+
| assumption-analyzer | `/audit-agent assumption` | Phase 1: Mapeia e quebra suposições | novel-discovery.md, invariant-catalog/, hypotheses/ |
|
|
192
|
+
| economic-attacker | `/audit-agent economic` | Phase 3: Modelagem econômica | novel-discovery.md, vulnerabilities/ |
|
|
193
|
+
| state-machine-hacker | `/audit-agent state` | Phase 4: Análise de máquina de estados | novel-discovery.md, attack-patterns/, invariant-catalog/ |
|
|
194
|
+
| composition-attacker | `/audit-agent composition` | Phase 5: Ataques por composição | novel-discovery.md, vulnerabilities/, novel-patterns/ |
|
|
195
|
+
| exploit-writer | `/audit-agent exploit` | Cria PoCs (Solidity/Foundry ou Rust/Anchor) | exploit-generator.md, test-strategies/ |
|
|
196
|
+
| test-generator | `/audit-agent test` | Gera testes (Foundry ou Anchor/cargo) | test-generator.md, test-strategies/ |
|
|
197
|
+
| report-writer | `/audit-agent report` | Compila relatórios multi-linguagem | reports/_template.md |
|
|
198
|
+
|
|
199
|
+
## Como os Recursos se Interligam
|
|
200
|
+
|
|
201
|
+
### Exemplo: assumption-analyzer em ação (Solidity)
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
1. Usuário: /audit-agent assumption --target=./contracts/Pool.sol
|
|
205
|
+
|
|
206
|
+
2. Agente assumption-analyzer ativa:
|
|
207
|
+
├── Config: agents/assumption-analyzer.json
|
|
208
|
+
├── Modelo: claude-opus-4-6
|
|
209
|
+
├── LANG: solidity (auto-detectado)
|
|
210
|
+
├── Prompts: skills/novel-discovery.md (Phase 1 - modo Solidity)
|
|
211
|
+
├── Contexto: obsidian-vault/invariant-catalog/defi-invariants.md
|
|
212
|
+
└── Template: obsidian-vault/hypotheses/_template.md
|
|
213
|
+
|
|
214
|
+
3. Agente analisa o contrato Pool.sol
|
|
215
|
+
|
|
216
|
+
4. Output gerado:
|
|
217
|
+
├── ./audit-output/assumptions-[timestamp].md
|
|
218
|
+
├── Referências a invariantes do vault
|
|
219
|
+
└── Hipóteses formatadas pelo template
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Exemplo: economic-attacker em ação (Rust/Solana)
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
1. Usuário: /audit-agent economic --target=./programs/amm/src/lib.rs
|
|
226
|
+
|
|
227
|
+
2. Agente economic-attacker ativa:
|
|
228
|
+
├── Config: agents/economic-attacker.json
|
|
229
|
+
├── Modelo: claude-opus-4-6
|
|
230
|
+
├── LANG: rust (auto-detectado por Anchor.toml)
|
|
231
|
+
├── Prompts: skills/novel-discovery.md (Phase 3 - modo Rust/Solana)
|
|
232
|
+
├── Contexto: obsidian-vault/vulnerabilities/solana-account-confusion.md
|
|
233
|
+
└── Contexto: obsidian-vault/invariant-catalog/solana-invariants.md
|
|
234
|
+
|
|
235
|
+
3. Agente analisa o programa AMM em Rust
|
|
236
|
+
|
|
237
|
+
4. Output gerado:
|
|
238
|
+
├── ./audit-output/rust/economic-analysis-[timestamp].md
|
|
239
|
+
├── Análise de ataques econômicos específicos Solana (CPI, PDA, SPL)
|
|
240
|
+
└── Vetores de ataque com Anchor/Sealevel
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
## Exemplos de Uso
|
|
246
|
+
|
|
247
|
+
### Exemplo 1: Conectar e verificar status
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
/user está em: ~/projetos/defi-protocol/
|
|
251
|
+
!pwd
|
|
252
|
+
/audit-connect
|
|
253
|
+
/audit-status
|
|
254
|
+
/audit-agents
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Exemplo 2: Executar Phase 1
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
/audit-connect
|
|
261
|
+
/audit-agent assumption --target=./src/
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Exemplo 3: Auditoria econômica rápida
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
/audit-connect
|
|
268
|
+
/audit-agent economic --target=./contracts/Pool.sol
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Exemplo 4: Auditoria completa (todos os agents)
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
/audit-connect
|
|
275
|
+
/audit-agent full --target=./contracts/ --output=./audit-results/
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Exemplo 5: Auditoria Rust/Solana
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
# Auto-detecção
|
|
282
|
+
/audit-connect
|
|
283
|
+
/audit-agent full --target=./programs/
|
|
284
|
+
|
|
285
|
+
# Ou forçando Rust
|
|
286
|
+
/audit-connect --lang=rust
|
|
287
|
+
/audit-agent assumption --target=./programs/amm/src/lib.rs
|
|
288
|
+
/audit-agent economic --target=./programs/amm/
|
|
289
|
+
/audit-agent exploit --target=./programs/amm/
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Exemplo 6: Workflow específico
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
/audit-connect
|
|
296
|
+
/audit-agent assumption # Gera hipóteses
|
|
297
|
+
/audit-agent economic # Valida viabilidade econômica
|
|
298
|
+
/audit-agent exploit # Cria PoC da hipótese mais promissora
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Configuração
|
|
302
|
+
|
|
303
|
+
### Configurar caminho do audit-system
|
|
304
|
+
|
|
305
|
+
Se o audit-system estiver em local diferente:
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
/audit-connect --config-path="<caminho-para-.audit-system>"
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Modos de operação
|
|
312
|
+
|
|
313
|
+
1. **Mode: connect** (padrão)
|
|
314
|
+
- Conecta e ativa todos os recursos
|
|
315
|
+
- Prepara ambiente para auditoria
|
|
316
|
+
|
|
317
|
+
2. **Mode: init**
|
|
318
|
+
- Inicializa estrutura de auditoria no projeto
|
|
319
|
+
- Cria pasta `audit-output/` completa
|
|
320
|
+
|
|
321
|
+
3. **Mode: full**
|
|
322
|
+
- Executa auditoria completa automaticamente
|
|
323
|
+
- Usa orchestrator para coordenar todos os agents
|
|
324
|
+
|
|
325
|
+
## Comandos Disponíveis
|
|
326
|
+
|
|
327
|
+
| Comando | Descrição |
|
|
328
|
+
|---------|-----------|
|
|
329
|
+
| `/audit-connect` | Ativa conexão com audit-system |
|
|
330
|
+
| `/audit-connect --config-path=X` | Define caminho customizado |
|
|
331
|
+
| `/audit-status` | Mostra status da conexão e recursos carregados |
|
|
332
|
+
| `/audit-agents` | Lista agents disponíveis |
|
|
333
|
+
| `/audit-agent <name>` | Executa agente específico |
|
|
334
|
+
| `/audit-phase <N>` | Executa fase específica do framework |
|
|
335
|
+
|
|
336
|
+
## Verificação de Conexão
|
|
337
|
+
|
|
338
|
+
Para confirmar que TODOS os recursos estão conectados:
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
/audit-connect
|
|
342
|
+
/audit-status
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Saída esperada (Solidity):
|
|
346
|
+
```
|
|
347
|
+
✓ Audit-System conectado
|
|
348
|
+
✓ Modelo: claude-opus-4-6
|
|
349
|
+
✓ Linguagem: solidity (auto-detectado)
|
|
350
|
+
✓ 8 agents registrados (modo EVM)
|
|
351
|
+
✓ 5 skills carregadas
|
|
352
|
+
✓ Vault indexado (14+ arquivos)
|
|
353
|
+
✓ Output directory: ./audit-output/
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Saída esperada (Rust/Solana):
|
|
357
|
+
```
|
|
358
|
+
✓ Audit-System conectado
|
|
359
|
+
✓ Modelo: claude-opus-4-6
|
|
360
|
+
✓ Linguagem: rust (auto-detectado via Anchor.toml)
|
|
361
|
+
✓ 8 agents registrados (modo Solana/Sealevel)
|
|
362
|
+
✓ 5 skills carregadas
|
|
363
|
+
✓ Vault indexado (14+ arquivos, incluindo Solana)
|
|
364
|
+
✓ Output directory: ./audit-output/rust/
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Related Resources
|
|
368
|
+
|
|
369
|
+
- [[../ARCHITECTURE.md]] - Arquitetura completa de integração
|
|
370
|
+
- [[../agents/AGENT_REGISTRY.md]] - Registro de todos os agents
|
|
371
|
+
- [[../config.json]] - Configuração do sistema
|
|
372
|
+
- [[../README.md]] - Documentação principal
|
|
373
|
+
|
|
374
|
+
## Notas Importantes
|
|
375
|
+
|
|
376
|
+
- O audit-system não precisa estar no mesmo diretório do projeto
|
|
377
|
+
- Todos os agents usam o modelo `claude-opus-4-6` por padrão
|
|
378
|
+
- Skills são carregadas automaticamente no contexto do Claude
|
|
379
|
+
- O vault é indexado para consulta rápida durante análises
|
|
380
|
+
- Resultados são salvos em `./audit-output/` por padrão
|
|
381
|
+
- Cada agente pode ser chamado individualmente após a conexão
|
|
382
|
+
- O orchestrator pode coordenar workflows multi-agente completos
|
|
383
|
+
- A linguagem é auto-detectada, mas pode ser forçada com `--lang`
|
|
384
|
+
- Em modo `rust`, agents focam em Solana/Anchor/Sealevel/ink!
|
|
385
|
+
- Em modo `solidity`, agents focam em EVM/Solidity/Foundry
|