web3crit-scanner 7.0.1

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 (42) hide show
  1. package/README.md +685 -0
  2. package/bin/web3crit +10 -0
  3. package/package.json +59 -0
  4. package/src/analyzers/control-flow.js +256 -0
  5. package/src/analyzers/data-flow.js +720 -0
  6. package/src/analyzers/exploit-chain.js +751 -0
  7. package/src/analyzers/immunefi-classifier.js +515 -0
  8. package/src/analyzers/poc-validator.js +396 -0
  9. package/src/analyzers/solodit-enricher.js +1122 -0
  10. package/src/cli.js +546 -0
  11. package/src/detectors/access-control-enhanced.js +458 -0
  12. package/src/detectors/base-detector.js +213 -0
  13. package/src/detectors/callback-reentrancy.js +362 -0
  14. package/src/detectors/cross-contract-reentrancy.js +697 -0
  15. package/src/detectors/delegatecall.js +167 -0
  16. package/src/detectors/deprecated-functions.js +62 -0
  17. package/src/detectors/flash-loan.js +408 -0
  18. package/src/detectors/frontrunning.js +553 -0
  19. package/src/detectors/gas-griefing.js +701 -0
  20. package/src/detectors/governance-attacks.js +366 -0
  21. package/src/detectors/integer-overflow.js +487 -0
  22. package/src/detectors/oracle-manipulation.js +524 -0
  23. package/src/detectors/permit-exploits.js +368 -0
  24. package/src/detectors/precision-loss.js +408 -0
  25. package/src/detectors/price-manipulation-advanced.js +548 -0
  26. package/src/detectors/proxy-vulnerabilities.js +651 -0
  27. package/src/detectors/readonly-reentrancy.js +473 -0
  28. package/src/detectors/rebasing-token-vault.js +416 -0
  29. package/src/detectors/reentrancy-enhanced.js +359 -0
  30. package/src/detectors/selfdestruct.js +259 -0
  31. package/src/detectors/share-manipulation.js +412 -0
  32. package/src/detectors/signature-replay.js +409 -0
  33. package/src/detectors/storage-collision.js +446 -0
  34. package/src/detectors/timestamp-dependence.js +494 -0
  35. package/src/detectors/toctou.js +427 -0
  36. package/src/detectors/token-standard-compliance.js +465 -0
  37. package/src/detectors/unchecked-call.js +214 -0
  38. package/src/detectors/vault-inflation.js +421 -0
  39. package/src/index.js +42 -0
  40. package/src/package-lock.json +2874 -0
  41. package/src/package.json +39 -0
  42. package/src/scanner-enhanced.js +816 -0
package/README.md ADDED
@@ -0,0 +1,685 @@
1
+ # WEB3CRIT Scanner
2
+
3
+ <p align="center">
4
+ <img src="web3crit-scanner_animated.gif" alt="WEB3CRIT Scanner Gif" width="250">
5
+ </p>
6
+
7
+ **Production-grade smart contract vulnerability scanner for $5M+ TVL protocols and Immunefi High/Critical bounties**
8
+
9
+ Web3CRIT Scanner is an exploit-driven static analysis tool for Solidity smart contracts. **v6.0.0** introduces **Production Mode** - a strict PoC-gating system that only emits HIGH/CRITICAL findings when a Foundry PoC compiles, executes, and proves real impact (fund drain, unauthorized transfer, role takeover, invariant break, or permanent DoS).
10
+
11
+ ## Production Mode (NEW in v6.0.0)
12
+
13
+ For bug bounty submissions and professional audits, use `--production` to enforce:
14
+
15
+ ```bash
16
+ web3crit scan ./contracts --production --foundry-root /path/to/foundry-project
17
+ ```
18
+
19
+ **Hard Rules Enforced:**
20
+ - HIGH/CRITICAL only emitted if Foundry PoC compiles, executes, and proves impact
21
+ - Impact must be: fund drain, unauthorized transfer, role takeover, invariant break, or permanent DoS
22
+ - If PoC fails to compile, run, or show impact → discarded silently
23
+ - Severity derived from observed PoC results, not heuristics
24
+ - No placeholder PoCs, no symbolic-only exploits
25
+
26
+ ## Key Features
27
+
28
+ - **Production Mode (NEW)** - Strict PoC-gating for HIGH/CRITICAL with proven impact verification
29
+ - **Control Flow Graph Analysis** - Tracks execution paths and function call relationships across contracts
30
+ - **Data Flow Analysis** - Traces tainted user inputs to dangerous operations (delegatecall, selfdestruct, etc.)
31
+ - **Oracle → Value Flow Tracking** - Detects oracle reads flowing into value-moving operations (transfer/mint/burn/refunds)
32
+ - **Immunefi Classification** - Maps findings to Immunefi payout categories (Direct Theft, Protocol Insolvency, etc.)
33
+ - **Exploit Chain Modeling** - Models attack assumptions (flash loans, MEV, malicious contracts)
34
+ - **Foundry PoC Execution** - Compiles and runs PoCs with impact extraction from forge output
35
+ - **Fork Testing Support** - `--fork-url` enables on-chain state verification
36
+ - **Multi-Contract Scanning** - Scan entire directories of Solidity files at once
37
+ - **Enhanced Reentrancy Detection** - Detects classic, cross-function, callback, and cross-contract reentrancy
38
+ - **Access Control Validation** - Analyzes what modifiers actually do, not just that they exist
39
+ - **npm Installable** - Install globally and use alongside Slither, Mythril, Aderyn, Manticore
40
+ - **Multiple Output Formats** - JSON, Markdown, Table, or Plain Text
41
+
42
+ ## Installation
43
+
44
+ ### Quick Install (Recommended)
45
+
46
+ ```bash
47
+ git clone https://github.com/critfinds/Web3CRIT-Scanner
48
+ cd Web3CRIT-Scanner
49
+ ./install.sh
50
+ ```
51
+
52
+ The install script will:
53
+ - Check Node.js and npm versions
54
+ - Install all dependencies
55
+ - Install web3crit globally
56
+ - Verify the installation
57
+
58
+ ### Manual Installation
59
+
60
+ ```bash
61
+ git clone https://github.com/critfinds/Web3CRIT-Scanner
62
+ cd Web3CRIT-Scanner
63
+ npm install
64
+ npm install -g .
65
+ ```
66
+
67
+ ### From npm (when published)
68
+
69
+ ```bash
70
+ npm install -g web3crit-scanner
71
+ ```
72
+
73
+ ### Using npx (no installation)
74
+
75
+ ```bash
76
+ npx web3crit-scanner scan contract.sol
77
+ ```
78
+
79
+ See [INSTALL.md](INSTALL.md) for detailed installation instructions and troubleshooting.
80
+
81
+ ## Usage
82
+
83
+ ### Single Contract
84
+
85
+ ```bash
86
+ # Basic scan
87
+ web3crit scan MyContract.sol
88
+
89
+ # JSON output
90
+ web3crit scan MyContract.sol --format json
91
+
92
+ # Critical issues only
93
+ web3crit scan MyContract.sol --severity critical
94
+
95
+ # Exploit-driven (attach exploit chains + Immunefi classification)
96
+ web3crit scan MyContract.sol --exploit-driven
97
+
98
+ # Strict Immunefi mode (High/Critical payout-eligible only)
99
+ web3crit scan MyContract.sol --immunefi-only
100
+ ```
101
+
102
+ ### Multiple Contracts
103
+
104
+ ```bash
105
+ # Scan entire directory
106
+ web3crit scan contracts/
107
+
108
+ # Scan with JSON output and save to file
109
+ web3crit scan contracts/ --format json --output results.json
110
+
111
+ # Show only high and critical issues
112
+ web3crit scan contracts/ --severity high
113
+ ```
114
+
115
+ ### Integration with Other Tools
116
+
117
+ ```bash
118
+ # Use alongside Slither
119
+ slither contracts/ --json slither-results.json
120
+ web3crit scan contracts/ --format json --output web3crit-results.json
121
+
122
+ # Compare findings
123
+ cat web3crit-results.json | jq '.stats'
124
+ cat slither-results.json | jq '.results.detectors | length'
125
+ ```
126
+
127
+ ## Vulnerability Detectors
128
+
129
+ Web3CRIT v6.0.0 includes enhanced detectors with logic-based analysis, plus specialized detectors for high-value TVL contracts and exploit-driven gating.
130
+
131
+ ### Core Enhanced Detectors
132
+
133
+ Web3CRIT v4.0.0+ includes 5 enhanced detectors with logic-based analysis:
134
+
135
+ ### 1. Reentrancy (Enhanced) - CRITICAL
136
+
137
+ Detects reentrancy vulnerabilities using control flow and data flow analysis:
138
+ - **Classic Reentrancy** - External calls before state updates
139
+ - **Cross-Function Reentrancy** - Reentrancy across multiple functions
140
+ - **Read-Only Reentrancy** - State reads after external calls in view functions
141
+ - **Reentrancy Guard Validation** - Verifies guards actually work (not just named correctly)
142
+ - **Exploitability Check** - Only reports if publicly accessible and no effective protection
143
+
144
+ **Example Vulnerable Code:**
145
+ ```solidity
146
+ function withdraw() public {
147
+ uint256 amount = balances[msg.sender];
148
+ (bool success, ) = msg.sender.call{value: amount}("");
149
+ require(success);
150
+ balances[msg.sender] = 0; // State update AFTER external call
151
+ }
152
+ ```
153
+
154
+ ### 2. Access Control (Enhanced) - CRITICAL
155
+
156
+ Validates access control logic instead of just checking for modifier presence:
157
+ - **Missing Access Control** - Sensitive functions without protection
158
+ - **Broken Modifiers** - Empty modifiers or always-true conditions
159
+ - **Weak Patterns** - Balance-based or timestamp-based access control
160
+ - **tx.origin Usage** - Detects vulnerable phishing patterns in modifiers
161
+ - **Modifier Logic Analysis** - Analyzes require statements to verify actual protection
162
+
163
+ **Example Vulnerable Code:**
164
+ ```solidity
165
+ // Missing access control
166
+ function setOwner(address newOwner) public {
167
+ owner = newOwner;
168
+ }
169
+
170
+ // Broken modifier
171
+ modifier onlyOwner() {
172
+ require(true); // Always passes!
173
+ _;
174
+ }
175
+ ```
176
+
177
+ ### 3. Unchecked External Calls - HIGH
178
+
179
+ Detects external calls where return values are not properly checked:
180
+ - Low-level `.call()` without checking success
181
+ - `.send()` without checking return value
182
+ - `.delegatecall()` without error handling
183
+
184
+ **Example Vulnerable Code:**
185
+ ```solidity
186
+ function unsafeTransfer(address payable recipient, uint256 amount) public {
187
+ recipient.send(amount); // Return value not checked
188
+ }
189
+ ```
190
+
191
+ ### 4. Dangerous Delegatecall - CRITICAL
192
+
193
+ Identifies user-controlled delegatecall targets:
194
+ - Detects delegatecall with user-controlled addresses
195
+ - Warns about storage layout compatibility issues
196
+ - Validates if proper access control exists
197
+
198
+ **Example Vulnerable Code:**
199
+ ```solidity
200
+ function upgrade(address newImpl, bytes memory data) public {
201
+ newImpl.delegatecall(data); // User-controlled target
202
+ }
203
+ ```
204
+
205
+ ### 5. Unprotected Selfdestruct - CRITICAL
206
+
207
+ Finds selfdestruct operations without proper access control:
208
+ - Detects public selfdestruct without modifiers
209
+ - Validates access control effectiveness
210
+
211
+ **Example Vulnerable Code:**
212
+ ```solidity
213
+ function destroy(address payable recipient) public {
214
+ selfdestruct(recipient); // Anyone can destroy contract
215
+ }
216
+ ```
217
+
218
+ ### High-Value TVL Contract Detectors (v5.2.0+)
219
+
220
+ These detectors are specifically designed for high-value contracts (>$1M TVL) and provide deeper coverage:
221
+
222
+ ### 6. Proxy Contract Vulnerabilities - CRITICAL
223
+
224
+ Detects critical issues in upgradeable contracts (UUPS, Transparent Proxies, EIP-1967):
225
+ - **Unprotected Initializers** - Missing initialization protection allowing re-initialization
226
+ - **Unauthorized Upgrades** - Upgrade functions without access control
227
+ - **Missing _authorizeUpgrade** - UUPS pattern without required authorization
228
+ - **Storage Collision** - Potential storage layout conflicts in upgrades
229
+ - **Unprotected Delegatecall** - Delegatecall without implementation validation
230
+ - **EIP-1967 Storage Access** - Direct storage slot manipulation without protection
231
+
232
+ **Example Vulnerable Code:**
233
+ ```solidity
234
+ // Unprotected initializer
235
+ function initialize(address _owner) public {
236
+ owner = _owner; // Can be called multiple times!
237
+ }
238
+
239
+ // Unauthorized upgrade
240
+ function upgrade(address newImpl) public {
241
+ implementation = newImpl; // Anyone can upgrade!
242
+ }
243
+ ```
244
+
245
+ **Testing Strategy:**
246
+ - Unit tests with vulnerable proxy patterns
247
+ - Integration tests with OpenZeppelin proxy contracts
248
+ - Foundry PoCs demonstrating initialization and upgrade exploits
249
+
250
+ ### 7. Signature Replay - HIGH
251
+
252
+ Detects missing replay protection in contracts using off-chain signatures:
253
+ - **Missing Nonce** - Signatures can be reused multiple times
254
+ - **Missing Expiration** - Old signatures remain valid indefinitely
255
+ - **Missing Chain ID** - Cross-chain replay attacks possible
256
+ - **Weak Validation** - Direct ecrecover without EIP-712
257
+
258
+ **Example Vulnerable Code:**
259
+ ```solidity
260
+ function permitTransfer(address from, address to, uint256 amount, bytes memory sig) public {
261
+ address signer = ecrecover(...);
262
+ require(signer == from);
263
+ // No nonce check - signature can be replayed!
264
+ balances[from] -= amount;
265
+ balances[to] += amount;
266
+ }
267
+ ```
268
+
269
+ **Testing Strategy:**
270
+ - Unit tests with signature verification functions
271
+ - Integration tests with EIP-2612 permit patterns
272
+ - Foundry PoCs demonstrating signature replay attacks
273
+
274
+ ### 8. Cross-Contract Reentrancy - CRITICAL
275
+
276
+ Detects complex reentrancy attacks involving multiple contracts:
277
+ - **Multi-Contract Reentrancy** - Reentrancy across multiple contracts in same transaction
278
+ - **State-Dependent Reentrancy** - State changes in one contract affecting another
279
+ - **Delegatecall Reentrancy** - Reentrancy via delegatecall patterns
280
+ - **Missing Guards** - Cross-contract interactions without reentrancy protection
281
+
282
+ **Example Vulnerable Code:**
283
+ ```solidity
284
+ function withdrawFromBoth() public {
285
+ uint256 balanceA = balances[msg.sender];
286
+ contractA.withdraw(); // External call
287
+ balances[msg.sender] = 0; // State update after call
288
+ contractB.deposit{value: balanceB}(); // Another external call
289
+ }
290
+ ```
291
+
292
+ **Testing Strategy:**
293
+ - Unit tests with multiple contract interactions
294
+ - Integration tests with complex DeFi protocols
295
+ - Foundry PoCs demonstrating cross-contract reentrancy
296
+
297
+ ### 9. Token Standard Compliance - HIGH
298
+
299
+ Ensures tokens strictly follow ERC standards (ERC20, ERC721, ERC1155):
300
+ - **Missing Required Functions** - Functions required by standard not implemented
301
+ - **Missing Events** - Transfer, Approval events not emitted
302
+ - **Incorrect Signatures** - Function signatures don't match standard
303
+ - **Non-Standard Return Values** - Missing bool return values
304
+
305
+ **Example Vulnerable Code:**
306
+ ```solidity
307
+ // ERC20 missing Transfer event
308
+ function transfer(address to, uint256 amount) public returns (bool) {
309
+ balances[msg.sender] -= amount;
310
+ balances[to] += amount;
311
+ // Missing: emit Transfer(msg.sender, to, amount);
312
+ return true;
313
+ }
314
+ ```
315
+
316
+ **Testing Strategy:**
317
+ - Unit tests against ERC20/721/1155 standard specifications
318
+ - Integration tests with DEXs and wallets
319
+ - Compliance verification against OpenZeppelin implementations
320
+
321
+ ### 10. TOCTOU (Time-of-Check to Time-of-Use) - HIGH
322
+
323
+ Detects race conditions where contract state changes between check and use:
324
+ - **Balance Check Before Transfer** - Balance checked, then external call, then transfer
325
+ - **Allowance Check Before Transfer** - Allowance checked, then external call, then transferFrom
326
+ - **State Check Before Use** - State variable checked, then external call, then used
327
+
328
+ **Example Vulnerable Code:**
329
+ ```solidity
330
+ function withdraw() public {
331
+ uint256 balance = balances[msg.sender]; // Check
332
+ (bool success, ) = msg.sender.call{value: balance}(""); // External call
333
+ balances[msg.sender] = 0; // Use (state update after call)
334
+ }
335
+ ```
336
+
337
+ **Testing Strategy:**
338
+ - Unit tests with check-use patterns
339
+ - Integration tests with callback patterns
340
+ - Foundry PoCs demonstrating TOCTOU exploits
341
+
342
+ ## Output Formats
343
+
344
+ ### JSON (for tool integration)
345
+
346
+ ```bash
347
+ web3crit scan contracts/ --format json --output results.json
348
+ ```
349
+
350
+ ```json
351
+ {
352
+ "findings": [
353
+ {
354
+ "detector": "Reentrancy Vulnerability (Enhanced)",
355
+ "severity": "CRITICAL",
356
+ "confidence": "HIGH",
357
+ "exploitable": true,
358
+ "title": "Classic Reentrancy Vulnerability",
359
+ "description": "Function 'withdraw' performs external call before updating state...",
360
+ "location": "Contract: MyContract, Function: withdraw",
361
+ "fileName": "contracts/MyContract.sol",
362
+ "line": 42,
363
+ "column": 4,
364
+ "code": "function withdraw() public { ... }",
365
+ "recommendation": "Move state updates before external calls...",
366
+ "references": [...]
367
+ }
368
+ ],
369
+ "stats": {
370
+ "filesScanned": 5,
371
+ "totalFindings": 12,
372
+ "critical": 3,
373
+ "high": 5,
374
+ "medium": 2,
375
+ "low": 2,
376
+ "exploitable": 6
377
+ },
378
+ "analysis": {
379
+ "engine": "enhanced",
380
+ "version": "4.0.0",
381
+ "features": [
382
+ "Control Flow Analysis",
383
+ "Data Flow Analysis",
384
+ "Cross-Function Reentrancy Detection",
385
+ "Modifier Logic Validation",
386
+ "Exploitability Verification"
387
+ ]
388
+ }
389
+ }
390
+ ```
391
+
392
+ ### Markdown (for reports)
393
+
394
+ ```bash
395
+ web3crit scan contracts/ --format markdown --output audit-report.md
396
+ ```
397
+
398
+ ### Table (CLI output)
399
+
400
+ ```bash
401
+ web3crit scan contracts/
402
+ ```
403
+
404
+ ## Architecture
405
+
406
+ ```
407
+ Web3CRIT-Scanner/
408
+ ├── src/
409
+ │ ├── analyzers/
410
+ │ │ ├── control-flow.js # Control flow graph builder
411
+ │ │ └── data-flow.js # Data flow and taint analysis
412
+ │ ├── detectors/
413
+ │ │ ├── reentrancy-enhanced.js
414
+ │ │ ├── access-control-enhanced.js
415
+ │ │ ├── unchecked-call.js
416
+ │ │ ├── delegatecall.js
417
+ │ │ └── selfdestruct.js
418
+ │ ├── scanner-enhanced.js # Main scanner with CFG/dataflow
419
+ │ └── cli.js # CLI interface
420
+ ├── bin/
421
+ │ └── web3crit # Global executable
422
+ ├── package.json
423
+ ├── INSTALL.md
424
+ └── README.md
425
+ ```
426
+
427
+ ## How It Works
428
+
429
+ ### Control Flow Graph (CFG) Analysis
430
+
431
+ The scanner builds a complete control flow graph of your contracts:
432
+ 1. Maps all functions, modifiers, and state variables
433
+ 2. Tracks function call relationships (call graph)
434
+ 3. Identifies external calls and their locations
435
+ 4. Maps state variable reads and writes
436
+
437
+ ### Data Flow Analysis
438
+
439
+ Performs taint tracking to identify exploitable data flows:
440
+ 1. Identifies taint sources (user inputs, function parameters)
441
+ 2. Propagates taint through assignments and calls
442
+ 3. Checks if tainted data reaches dangerous operations
443
+ 4. Verifies if protections (access control) are in place
444
+
445
+ ### Enhanced Detection
446
+
447
+ Unlike pattern-matching tools, Web3CRIT validates:
448
+ - **Exploitability** - Is the vulnerability actually exploitable?
449
+ - **Access Control** - Does the modifier logic actually work?
450
+ - **Protection** - Are reentrancy guards effective?
451
+ - **Reachability** - Can users actually trigger the vulnerable path?
452
+
453
+ ## Comparison to v3.0.0
454
+
455
+ | Aspect | v3.0.0 (Pattern Matching) | v4.0.0 (Logic Analysis) |
456
+ |--------|---------------------------|-------------------------|
457
+ | Detectors | 23 pattern-based | 5 logic-based |
458
+ | False Positives | High | Low |
459
+ | Reentrancy | Basic pattern only | Classic + cross-function + read-only |
460
+ | Access Control | Checks if modifier exists | Validates modifier logic |
461
+ | Modifier Analysis | Name only | Analyzes require statements |
462
+ | Exploitability | Assumed | Verified |
463
+ | Cross-Function | Not detected | Fully detected |
464
+ | Multi-Contract | No | Yes |
465
+
466
+ ## Use Cases
467
+
468
+ ### Development Workflow
469
+
470
+ ```bash
471
+ # During development
472
+ web3crit scan contracts/
473
+
474
+ # Before committing
475
+ web3crit scan contracts/ --severity critical
476
+
477
+ # Pre-audit cleanup
478
+ web3crit scan contracts/ --format json --output pre-audit.json
479
+ ```
480
+
481
+ ### CI/CD Integration
482
+
483
+ ```yaml
484
+ # GitHub Actions example
485
+ - name: Security Scan
486
+ run: |
487
+ npm install -g web3crit-scanner
488
+ web3crit scan contracts/ --severity high
489
+ ```
490
+
491
+ ### Audit Preparation
492
+
493
+ ```bash
494
+ # Generate comprehensive report
495
+ web3crit scan contracts/ --format markdown --output security-audit.md
496
+
497
+ # Compare with other tools
498
+ slither contracts/ --json slither.json
499
+ mythril analyze contracts/Token.sol -o mythril.json
500
+ web3crit scan contracts/ --format json --output web3crit.json
501
+ ```
502
+
503
+ ## Limitations
504
+
505
+ Web3CRIT Scanner provides advanced static analysis but has limitations:
506
+
507
+ - **No Symbolic Execution** - Cannot prove all execution paths (use Mythril for this)
508
+ - **Single-File Analysis** - Limited cross-contract dependency tracking
509
+ - **No Formal Verification** - Cannot prove mathematical properties (use Certora for this)
510
+ - **Heuristic-Based** - Some edge cases may be missed
511
+
512
+ ### Recommended Multi-Tool Approach
513
+
514
+ For high-value contracts (>$1M TVL), use multiple tools:
515
+
516
+ 1. **Web3CRIT** - Logic-based analysis with low false positives
517
+ 2. **Slither** - Comprehensive pattern detection (90+ detectors)
518
+ 3. **Mythril** - Symbolic execution for exploit proofs
519
+ 4. **Manticore/Echidna** - Dynamic analysis and fuzzing
520
+ 5. **Professional Audit** - Human expert review
521
+ 6. **Formal Verification** - Mathematical proofs (Certora, K Framework)
522
+
523
+ ## Requirements
524
+
525
+ - Node.js >= 14.0.0
526
+ - npm >= 6.0.0
527
+
528
+ ## Command Line Options
529
+
530
+ ```
531
+ Usage: web3crit scan <file|directory> [options]
532
+
533
+ Options:
534
+ -s, --severity <level> Minimum severity (critical|high|medium|low|info|all) (default: "all")
535
+ -o, --output <file> Save report to file
536
+ -f, --format <format> Output format (table|json|markdown|text) (default: "table")
537
+ -v, --verbose Verbose output
538
+ --exploit-driven Enable exploit-driven analysis (attach exploit chains + Immunefi classification)
539
+ --immunefi-only Strict Immunefi mode (only keep High/Critical payout-eligible findings)
540
+ --poc-validate Validate attached Foundry PoCs (drop findings whose PoCs fail validation)
541
+ --poc-require-pass Require PoCs to compile+pass under forge (requires foundry.toml + forge installed)
542
+ --poc-mode <mode> PoC validation mode: test|build (default: test)
543
+ --foundry-root <path> Path to Foundry project root (directory containing foundry.toml)
544
+ --poc-keep-temp Keep temporary test files written during PoC validation
545
+ --no-banner Disable banner
546
+ -h, --help Display help
547
+ ```
548
+
549
+ ## Foundry PoC Validation (Important)
550
+
551
+ The scanner repo is **not** a Foundry project. `--poc-require-pass` is intended to be run **inside the target protocol repo** (or with `--foundry-root`) so PoCs can be compiled and executed via `forge test`.
552
+
553
+ ## Examples
554
+
555
+ ### Example 1: Quick Scan
556
+
557
+ ```bash
558
+ web3crit scan MyContract.sol
559
+ ```
560
+
561
+ ### Example 2: Multi-Contract with JSON
562
+
563
+ ```bash
564
+ web3crit scan ./contracts --format json --output scan-results.json
565
+ ```
566
+
567
+ ### Example 3: Critical Issues Only
568
+
569
+ ```bash
570
+ web3crit scan ./contracts --severity critical
571
+ ```
572
+
573
+ ### Example 4: Integration with Slither
574
+
575
+ ```bash
576
+ slither contracts/ && web3crit scan contracts/
577
+ ```
578
+
579
+ ## Contributing
580
+
581
+ Contributions are welcome! Please:
582
+ 1. Add tests for new detectors
583
+ 2. Follow existing code patterns
584
+ 3. Update documentation
585
+ 4. Include references to vulnerability resources
586
+
587
+ ## Security Researchers
588
+
589
+ If you find vulnerabilities in this tool or have suggestions for new detectors, please open an issue or submit a pull request.
590
+
591
+ ## Testing Strategy
592
+
593
+ ### Unit Tests
594
+
595
+ Each detector includes comprehensive unit tests:
596
+ - **Vulnerable Contracts**: Test contracts demonstrating each vulnerability pattern
597
+ - **Secure Contracts**: Test contracts with proper mitigations (should produce minimal findings)
598
+ - **Edge Cases**: Boundary conditions and complex scenarios
599
+
600
+ Run tests:
601
+ ```bash
602
+ npm test
603
+ ```
604
+
605
+ ### Integration Tests
606
+
607
+ Integration tests verify detectors work together:
608
+ - Multi-contract scanning
609
+ - Complex protocol interactions
610
+ - Real-world contract patterns
611
+
612
+ ### Foundry PoCs
613
+
614
+ High-confidence findings (confidence: HIGH, exploitability score ≥ 70) automatically generate Foundry PoC templates:
615
+
616
+ ```bash
617
+ web3crit scan contracts/ --format json --output results.json
618
+ # PoCs included in findings with foundryPoC field
619
+ ```
620
+
621
+ Generate complete Foundry test file:
622
+ ```javascript
623
+ const scanner = new Web3CRITScanner();
624
+ await scanner.scanDirectory('contracts/');
625
+ const testFile = scanner.generateFoundryTestFile('VulnerabilityExploits');
626
+ // Save to test/VulnerabilityExploits.t.sol
627
+ ```
628
+
629
+ ### Testing Priority for High-Value TVL Contracts
630
+
631
+ For contracts with >$1M TVL, recommended testing order:
632
+
633
+ 1. **Proxy Vulnerabilities** (CRITICAL) - Test first for upgradeable contracts
634
+ 2. **Cross-Contract Reentrancy** (CRITICAL) - Test for multi-contract protocols
635
+ 3. **Signature Replay** (HIGH) - Test for meta-transaction/permit patterns
636
+ 4. **Token Standard Compliance** (HIGH) - Test for token contracts
637
+ 5. **TOCTOU** (HIGH) - Test for complex state management
638
+
639
+ ## Version History
640
+
641
+ ### v5.2.0 - High-Value TVL Detectors (Current)
642
+
643
+ - **NEW**: Proxy Contract Vulnerabilities detector (UUPS, Transparent Proxies)
644
+ - **NEW**: Signature Replay detector for meta-transactions
645
+ - **NEW**: Cross-Contract Reentrancy detector
646
+ - **NEW**: Token Standard Compliance detector (ERC20/721/1155)
647
+ - **NEW**: TOCTOU (Time-of-Check to Time-of-Use) detector
648
+ - Enhanced Foundry PoC generation for high-confidence findings
649
+ - Comprehensive test suite with vulnerable contract examples
650
+ - Improved exploitability scoring (0-100)
651
+
652
+ ### v4.0.0 - Enhanced Analysis Engine
653
+
654
+ - Control flow graph (CFG) builder
655
+ - Data flow and taint analysis
656
+ - Enhanced reentrancy detector (classic + cross-function + read-only)
657
+ - Enhanced access control detector (validates modifier logic)
658
+ - Exploitability verification
659
+ - Multi-contract directory scanning
660
+ - Reduced false positives
661
+ - npm installable globally
662
+
663
+ ### v3.0.0 - Production Patterns
664
+
665
+ - 23 pattern-matching detectors
666
+ - Flash loan detection
667
+ - Signature replay detection
668
+ - High false positive rate
669
+
670
+ ### v1.0.0 - Initial Release
671
+
672
+ - 10 basic pattern-matching detectors
673
+ - AST-based analysis
674
+
675
+ ## License
676
+
677
+ MIT
678
+
679
+ ## References
680
+
681
+ - [Smart Contract Weakness Classification (SWC)](https://swcregistry.io/)
682
+ - [ConsenSys Smart Contract Best Practices](https://consensys.github.io/smart-contract-best-practices/)
683
+ - [OpenZeppelin Security](https://docs.openzeppelin.com/contracts/4.x/api/security)
684
+ - [Slither Documentation](https://github.com/crytic/slither)
685
+ - [Trail of Bits Resources](https://github.com/crytic)
package/bin/web3crit ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Web3CRIT Scanner - Global Executable
5
+ * Can be installed globally with: npm install -g web3crit-scanner
6
+ * Or via pip3: pip3 install web3crit-scanner
7
+ */
8
+
9
+ const path = require('path');
10
+ const cli = require(path.join(__dirname, '..', 'src', 'cli.js'));