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,307 @@
|
|
|
1
|
+
# DeFi Invariants Catalog
|
|
2
|
+
|
|
3
|
+
tags: #invariants #defi #catalog #security
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
This catalog documents common invariants in DeFi protocols. Each invariant represents a property that must always hold true. Breaking an invariant typically indicates a vulnerability.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Lending Protocol Invariants
|
|
13
|
+
|
|
14
|
+
### LI-01: Collateralization Ratio
|
|
15
|
+
```
|
|
16
|
+
invariant: total_collateral >= total_debt * liquidation_threshold / 100
|
|
17
|
+
violation: Undercollateralized positions not liquidated
|
|
18
|
+
severity: CRITICAL
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### LI-02: Solvency
|
|
22
|
+
```
|
|
23
|
+
invariant: contract_token_balance >= total_user_deposits
|
|
24
|
+
violation: Users cannot withdraw deposits
|
|
25
|
+
severity: CRITICAL
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### LI-03: Interest Accumulation
|
|
29
|
+
```
|
|
30
|
+
invariant: debt_amount only increases (or stays same) over time
|
|
31
|
+
violation: Debt incorrectly calculated
|
|
32
|
+
severity: HIGH
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### LI-04: Liquidation Economics
|
|
36
|
+
```
|
|
37
|
+
invariant: liquidation_incentive > 0 && liquidation_incentive < 100%
|
|
38
|
+
violation: Liquidators lose money or can extract excessive value
|
|
39
|
+
severity: HIGH
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## DEX/AMM Invariants
|
|
45
|
+
|
|
46
|
+
### DEX-01: Constant Product (x*y=k)
|
|
47
|
+
```
|
|
48
|
+
invariant: reserve0 * reserve1 >= k (approximately, before fees)
|
|
49
|
+
violation: Pool manipulation, price manipulation
|
|
50
|
+
severity: CRITICAL
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### DEX-02: Price Consistency
|
|
54
|
+
```
|
|
55
|
+
invariant: spot_price ≈ time_weighted_average_price (within reasonable bounds)
|
|
56
|
+
violation: Oracle manipulation, flash loan attacks
|
|
57
|
+
severity: CRITICAL
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### DEX-03: LP Token Value
|
|
61
|
+
```
|
|
62
|
+
invariant: total_lp_supply <= total_reserves (in value terms)
|
|
63
|
+
violation: LP tokens minted without backing
|
|
64
|
+
severity: CRITICAL
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### DEX-04: K Invariant Monotonicity
|
|
68
|
+
```
|
|
69
|
+
invariant: k only increases with fees
|
|
70
|
+
violation: Fees not properly collected
|
|
71
|
+
severity: MEDIUM
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Staking Protocol Invariants
|
|
77
|
+
|
|
78
|
+
### ST-01: Staked Balance
|
|
79
|
+
```
|
|
80
|
+
invariant: user_staked_balance <= user_token_balance (at deposit time)
|
|
81
|
+
violation: Can stake more than owned
|
|
82
|
+
severity: CRITICAL
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### ST-02: Reward Accrual
|
|
86
|
+
```
|
|
87
|
+
invariant: pending_rewards >= 0 && monotonically increasing
|
|
88
|
+
violation: Rewards incorrectly calculated
|
|
89
|
+
severity: HIGH
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### ST-03: Unstaking Period
|
|
93
|
+
```
|
|
94
|
+
invariant: unstake_time >= stake_time + lock_duration
|
|
95
|
+
violation: Early withdrawal possible
|
|
96
|
+
severity: HIGH
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### ST-04: Total Staked
|
|
100
|
+
```
|
|
101
|
+
invariant: sum(user_stakes) == total_staked
|
|
102
|
+
violation: Accounting discrepancy
|
|
103
|
+
severity: CRITICAL
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Governance Token Invariants
|
|
109
|
+
|
|
110
|
+
### GOV-01: Voting Power
|
|
111
|
+
```
|
|
112
|
+
invariant: voting_power <= token_balance (or delegated amount)
|
|
113
|
+
violation: Double voting
|
|
114
|
+
severity: CRITICAL
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### GOV-02: Proposal Threshold
|
|
118
|
+
```
|
|
119
|
+
invariant: proposal_creator_votes >= proposal_threshold
|
|
120
|
+
violation: Spam proposals
|
|
121
|
+
severity: MEDIUM
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### GOV-03: Execution Delay
|
|
125
|
+
```
|
|
126
|
+
invariant: execution_time >= creation_time + voting_period + timelock
|
|
127
|
+
violation: Premature execution
|
|
128
|
+
severity: HIGH
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### GOV-04: Quorum
|
|
132
|
+
```
|
|
133
|
+
invariant: for votes + against votes + abstain votes >= quorum (for valid proposals)
|
|
134
|
+
violation: Proposals pass without sufficient participation
|
|
135
|
+
severity: CRITICAL
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Vault/Yield Aggregator Invariants
|
|
141
|
+
|
|
142
|
+
### VAULT-01: Share Price
|
|
143
|
+
```
|
|
144
|
+
invariant: share_price >= 1e18 (or base value)
|
|
145
|
+
violation: First depositor / inflation attack
|
|
146
|
+
severity: CRITICAL
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### VAULT-02: Deposit/Withdraw Ratio
|
|
150
|
+
```
|
|
151
|
+
invariant: assets_withdrawn ≈ shares_burned * share_price (with tolerance)
|
|
152
|
+
violation: Price manipulation, rounding error exploitation
|
|
153
|
+
severity: HIGH
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### VAULT-03: Strategy Allocation
|
|
157
|
+
```
|
|
158
|
+
invariant: sum(strategy_allocations) == 100%
|
|
159
|
+
violation: Funds lost or locked
|
|
160
|
+
severity: CRITICAL
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### VAULT-04: Harvest Timing
|
|
164
|
+
```
|
|
165
|
+
invariant: harvest_profit > harvest_gas_cost (or harvest blocked)
|
|
166
|
+
violation: Loss through excessive harvests
|
|
167
|
+
severity: MEDIUM
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Bridge/Cross-Chain Invariants
|
|
173
|
+
|
|
174
|
+
### BRIDGE-01: Token Conservation
|
|
175
|
+
```
|
|
176
|
+
invariant: tokens_locked_on_source == tokens_minted_on_target (per user)
|
|
177
|
+
violation: Double minting, unbacked tokens
|
|
178
|
+
severity: CRITICAL
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### BRIDGE-02: Verification
|
|
182
|
+
```
|
|
183
|
+
invariant: message must be signed by threshold of validators
|
|
184
|
+
violation: Unauthorized minting/burning
|
|
185
|
+
severity: CRITICAL
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### BRIDGE-03: Nonce Uniqueness
|
|
189
|
+
```
|
|
190
|
+
invariant: each bridge transaction has unique nonce
|
|
191
|
+
violation: Replay attacks
|
|
192
|
+
severity: CRITICAL
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Token Standard Invariants
|
|
198
|
+
|
|
199
|
+
### ERC20-01: Balance Conservation
|
|
200
|
+
```
|
|
201
|
+
invariant: sum(all_balances) == total_supply (with allowances caveat)
|
|
202
|
+
violation: Inflation bugs, minting exploits
|
|
203
|
+
severity: CRITICAL
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### ERC20-02: Approval
|
|
207
|
+
```
|
|
208
|
+
invariant: transferFrom succeeds only if allowance >= amount
|
|
209
|
+
violation: Unauthorized transfers
|
|
210
|
+
severity: CRITICAL
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### ERC721-01: Ownership
|
|
214
|
+
```
|
|
215
|
+
invariant: ownerOf(tokenId) returns single address
|
|
216
|
+
violation: Double ownership
|
|
217
|
+
severity: CRITICAL
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Insurance Protocol Invariants
|
|
223
|
+
|
|
224
|
+
### INS-01: Capital Pool
|
|
225
|
+
```
|
|
226
|
+
invariant: capital_pool >= total_coverage_amount * risk_factor
|
|
227
|
+
violation: Insufficient funds for claims
|
|
228
|
+
severity: CRITICAL
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### INS-02: Claim Validity
|
|
232
|
+
```
|
|
233
|
+
invariant: claim_amount <= coverage_amount && claim_approved == true
|
|
234
|
+
violation: Fraudulent claims
|
|
235
|
+
severity: HIGH
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### INS-03: Premium Calculation
|
|
239
|
+
```
|
|
240
|
+
invariant: premium >= expected_claims / capital_pool (simplified)
|
|
241
|
+
violation: Underpricing, insolvency
|
|
242
|
+
severity: HIGH
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Derivatives/Options Invariants
|
|
248
|
+
|
|
249
|
+
### DER-01: Collateralization
|
|
250
|
+
```
|
|
251
|
+
invariant: collateral >= max_payout (for sellers)
|
|
252
|
+
violation: Unable to pay out
|
|
253
|
+
severity: CRITICAL
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### DER-02: Exercise Validity
|
|
257
|
+
```
|
|
258
|
+
invariant: option_exercisable only if strike_price conditions met
|
|
259
|
+
violation: Invalid exercise
|
|
260
|
+
severity: HIGH
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### DER-03: Settlement
|
|
264
|
+
```
|
|
265
|
+
invariant: settlement_price >= 0 && settlement_price <= market_price * max_multiple
|
|
266
|
+
violation: Oracle manipulation
|
|
267
|
+
severity: CRITICAL
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Using This Catalog
|
|
273
|
+
|
|
274
|
+
### During Audit
|
|
275
|
+
1. Identify protocol type
|
|
276
|
+
2. Review relevant invariants
|
|
277
|
+
3. Test each invariant with property-based tests
|
|
278
|
+
4. Document any violations
|
|
279
|
+
|
|
280
|
+
### Hypothesis Generation
|
|
281
|
+
```
|
|
282
|
+
Pattern: "What if [INVARIANT] is violated via [ATTACK_VECTOR]?"
|
|
283
|
+
Example: "What if total_collateral < total_debt via flash loan manipulation?"
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Tool Integration
|
|
287
|
+
Use with:
|
|
288
|
+
- Echidna: Define as `invariant()` functions
|
|
289
|
+
- Foundry: Write as `testInvariant_*` tests
|
|
290
|
+
- Certora: Specify as `invariant` rules
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Solana-Specific Additions
|
|
295
|
+
|
|
296
|
+
See [[solana-invariants]] for invariants specific to Solana/Anchor programs:
|
|
297
|
+
- Account model invariants (ownership, discrimination, uniqueness)
|
|
298
|
+
- PDA derivation invariants (canonical bump, seed validation)
|
|
299
|
+
- CPI invariants (program ID validation, return check, reentrancy)
|
|
300
|
+
- SPL token invariants (ownership, mint authority, balance conservation)
|
|
301
|
+
- State machine invariants (discriminator, initialization, close)
|
|
302
|
+
|
|
303
|
+
## Links
|
|
304
|
+
- [[attack-patterns/state-inconsistency]] — Many invariants enforce state consistency
|
|
305
|
+
- [[test-strategies/invariant-testing]] — How to test these
|
|
306
|
+
- [[novel-patterns/pattern-mutation-framework]] — Combine invariants for novel attacks
|
|
307
|
+
- [[solana-invariants]] — Solana/Anchor-specific invariants
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Solana Program Invariants Catalog
|
|
2
|
+
|
|
3
|
+
tags: #invariants #solana #anchor #catalog #security
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
This catalog documents invariants specific to Solana/Anchor programs. These must ALWAYS hold for secure operation.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Account Model Invariants
|
|
13
|
+
|
|
14
|
+
### SOL-ACC-01: Account Discrimination
|
|
15
|
+
```
|
|
16
|
+
invariant: every instruction verifies the account discriminator before reading data
|
|
17
|
+
violation: account data misinterpreted, reinitialization attacks
|
|
18
|
+
severity: CRITICAL
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### SOL-ACC-02: Account Ownership
|
|
22
|
+
```
|
|
23
|
+
invariant: account.owner == expected_program_id for all program-owned accounts
|
|
24
|
+
violation: unauthorized account access, fake accounts
|
|
25
|
+
severity: CRITICAL
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### SOL-ACC-03: Account Uniqueness
|
|
29
|
+
```
|
|
30
|
+
invariant: no two accounts of same type in an instruction can be the same pubkey
|
|
31
|
+
(unless explicitly designed for it)
|
|
32
|
+
violation: account confusion, self-dealing
|
|
33
|
+
severity: HIGH
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### SOL-ACC-04: Signer Verification
|
|
37
|
+
```
|
|
38
|
+
invariant: every privileged action requires a Signer check
|
|
39
|
+
violation: unauthorized state modification
|
|
40
|
+
severity: CRITICAL
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### SOL-ACC-05: Writable Permissions
|
|
44
|
+
```
|
|
45
|
+
invariant: accounts whose data is modified must be marked `mut`
|
|
46
|
+
violation: failed transactions, unexpected behavior
|
|
47
|
+
severity: HIGH
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## PDA Invariants
|
|
53
|
+
|
|
54
|
+
### SOL-PDA-01: Deterministic Derivation
|
|
55
|
+
```
|
|
56
|
+
invariant: PDA seeds produce deterministic, unique addresses
|
|
57
|
+
violation: two users share same PDA, fund confusion
|
|
58
|
+
severity: CRITICAL
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### SOL-PDA-02: Canonical Bump
|
|
62
|
+
```
|
|
63
|
+
invariant: only the canonical (highest valid) bump seed is used
|
|
64
|
+
violation: multiple valid bumps create ambiguity
|
|
65
|
+
severity: MEDIUM
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### SOL-PDA-03: Seed Validation
|
|
69
|
+
```
|
|
70
|
+
invariant: seeds used in PDA derivation are validated against instruction data
|
|
71
|
+
violation: arbitrary PDA signing, forged authority
|
|
72
|
+
severity: CRITICAL
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### SOL-PDA-04: PDA Signing
|
|
76
|
+
```
|
|
77
|
+
invariant: PDA signs via `invoke_signed` with correct seeds and bump
|
|
78
|
+
violation: CPI with wrong authority, unauthorized transfers
|
|
79
|
+
severity: CRITICAL
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## CPI Invariants
|
|
85
|
+
|
|
86
|
+
### SOL-CPI-01: Program ID Validation
|
|
87
|
+
```
|
|
88
|
+
invariant: program_id in CPI is validated against expected constant
|
|
89
|
+
violation: arbitrary CPI execution, malicious program calls
|
|
90
|
+
severity: CRITICAL
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### SOL-CPI-02: CPI Return Check
|
|
94
|
+
```
|
|
95
|
+
invariant: CPI return value is checked for errors
|
|
96
|
+
violation: silent failure, incorrect state transition
|
|
97
|
+
severity: HIGH
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### SOL-CPI-03: CPI Reentrancy Protection
|
|
101
|
+
```
|
|
102
|
+
invariant: contract state is committed before CPI to untrusted program
|
|
103
|
+
violation: reentrancy via CPI callback
|
|
104
|
+
severity: CRITICAL
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Token (SPL) Invariants
|
|
110
|
+
|
|
111
|
+
### SOL-TOK-01: Token Account Ownership
|
|
112
|
+
```
|
|
113
|
+
invariant: token account owner matches expected authority
|
|
114
|
+
violation: unauthorized transfers, token theft
|
|
115
|
+
severity: CRITICAL
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### SOL-TOK-02: Mint Authority
|
|
119
|
+
```
|
|
120
|
+
invariant: only authorized programs/users can mint new tokens
|
|
121
|
+
violation: token inflation, unbacked minting
|
|
122
|
+
severity: CRITICAL
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### SOL-TOK-03: Balance Conservation
|
|
126
|
+
```
|
|
127
|
+
invariant: sum(token_balances) == total_supply (per mint)
|
|
128
|
+
violation: token creation/destruction outside mint/burn
|
|
129
|
+
severity: CRITICAL
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### SOL-TOK-04: Close Account Destination
|
|
133
|
+
```
|
|
134
|
+
invariant: closed token account lamports go to the correct owner
|
|
135
|
+
violation: rent theft, fund loss
|
|
136
|
+
severity: HIGH
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## State Machine Invariants
|
|
142
|
+
|
|
143
|
+
### SOL-SM-01: Discriminator Immutability
|
|
144
|
+
```
|
|
145
|
+
invariant: account discriminator (first 8 bytes) never changes after init
|
|
146
|
+
violation: account reinterpretation, type confusion
|
|
147
|
+
severity: CRITICAL
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### SOL-SM-02: Initialization Check
|
|
151
|
+
```
|
|
152
|
+
invariant: initialized accounts cannot be reinitialized
|
|
153
|
+
violation: reinitialization attack, privilege escalation
|
|
154
|
+
severity: HIGH
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### SOL-SM-03: Close Protection
|
|
158
|
+
```
|
|
159
|
+
invariant: closed accounts cannot be used without reinitialization
|
|
160
|
+
violation: use-after-close, stale data access
|
|
161
|
+
severity: HIGH
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Economic Invariants
|
|
167
|
+
|
|
168
|
+
### SOL-ECO-01: Solvency
|
|
169
|
+
```
|
|
170
|
+
invariant: program-owned token balance >= user deposits tracked in program state
|
|
171
|
+
violation: insolvency, inability to withdraw
|
|
172
|
+
severity: CRITICAL
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### SOL-ECO-02: Rent Exemption
|
|
176
|
+
```
|
|
177
|
+
invariant: all program accounts remain rent-exempt
|
|
178
|
+
violation: account purged, data loss
|
|
179
|
+
severity: MEDIUM
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### SOL-ECO-03: Fee Correctness
|
|
183
|
+
```
|
|
184
|
+
invariant: protocol fees are correctly calculated and cannot be bypassed
|
|
185
|
+
violation: revenue loss, attacker profit at protocol expense
|
|
186
|
+
severity: HIGH
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Using This Catalog
|
|
192
|
+
|
|
193
|
+
### During Audit
|
|
194
|
+
1. Identify program type (AMM, lending, staking, etc.)
|
|
195
|
+
2. Review relevant Solana invariants
|
|
196
|
+
3. Test each invariant with Anchor test suite
|
|
197
|
+
4. Document any violations
|
|
198
|
+
|
|
199
|
+
### Hypothesis Generation
|
|
200
|
+
```
|
|
201
|
+
Pattern: "What if [SOL-INVARIANT] is violated via [ATTACK_VECTOR]?"
|
|
202
|
+
Example: "What if SOL-ACC-02 (account ownership) is violated via account confusion?"
|
|
203
|
+
Example: "What if SOL-CPI-03 (CPI reentrancy) is violated via malicious program callback?"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Links
|
|
209
|
+
- [[../vulnerabilities/solana-account-confusion]]
|
|
210
|
+
- [[../vulnerabilities/solana-cpi-attacks]]
|
|
211
|
+
- [[../vulnerabilities/solana-signer-authorization]]
|
|
212
|
+
- [[../vulnerabilities/solana-close-account]]
|
|
213
|
+
- [[defi-invariants]] (general DeFi invariants)
|