# ROLE
You are a Principal Smart Contract Security Engineer, Principal Rust Engineer, Principal Foundry Contributor, and Senior Blockchain Architect.Your task is to design and implement a production-ready, open-source MIT licensed Foundry extension named `forge-guard`.
The goal is NOT to build another static analyzer. The goal is to build the most comprehensive pre-deployment smart contract auditing framework for Foundry.
The project must be production-ready, extensible, modular, highly performant, and designed to become the standard security layer for Foundry.
---
# PROJECT GOALS
The framework must:
* perform comprehensive offline security auditinfg
* prevent unsafe deployments
* support multi-chain functionality
* support plugin-based architectures
* support future AI integrations
* support CI/CD pipelines
* support exploit simulations
* support fuzzing
* support invariant testing
* support deterministic deployment analysis
* support proxy analysis
* support bytecode analysis
* support AST analysis
* support gas analysis
* support dependency analysis
* support deployment simulations
The framework must support:
```text
Ethereum
Base
Arbitrum
Optimism
Polygon
BNB
Avalanche
Scroll
Linea
Unichain
ZKSync
HyperEVM
Monad
Sonic
Blast
Mantle
Robinhood
future support:
Solana
Tron
Sui
Aptos
```
The architecture MUST use:
```text
EVM Core
↓
Plugin Architecture
↓
Chain Plugins
↓
Security Engine
↓
Deployment Guard
↓
Report Engine
↓
Foundry Integration
↓
Future AI Layer
```
---
# LICENSE
Use:
```text
MIT
```
The entire project must be:
```text
100% Open Source
```
---
# MINIMUM REQUIREMENTS
Only support:
```text
Solidity >=0.8.20
```
Do NOT support legacy Solidity versions.
---
# TECH STACK
Use:
```text
Rust
```
for:
```text
security engine
AST analysis
bytecode analysis
dependency analysis
deployment guard
plugin system
report generation
CI integrations
multi-chain support
```
Use:
```text
Foundry
```
for:
```text
tests
fuzzing
invariants
deployment simulation
scripts
```
Use:
```text
Solc
```
for:
```text
AST generation
IR generation
YUL analysis
```
Use:
```text
LLVM
where useful.
```
Use:
```text
SQLite
```
for:
```text
caching
local databases
vulnerability indexes
```
---
# COMMANDS
Implement:
```bash
forge audit
forge deploy
forge deploy-safe
forge fuzz
forge invariant
forge simulate
forge gas
forge report
forge verify
forge doctor
forge watch
forge ci
forge benchmark
forge scan
forge upgrade-check
forge plugins
forge chain
forge security
```
Examples:
```bash
forge audit
forge audit --full
forge audit --chain ethereum
forge audit --chain base
forge audit --chain arbitrum
forge audit --chain solana
forge audit --json
forge audit --markdown
forge audit --exploit
forge audit --gas
forge audit --offline
forge audit --strict
forge audit --production
forge audit --report
```
---
# DEPLOYMENT GUARD
Unsafe deployments MUST be blocked by default.
Example:
```bash
forge deploy
```
must automatically execute:
```text
Compilation
↓
Tests
↓
Security Audit
↓
Fuzzing
↓
Invariant Testing
↓
Dependency Analysis
↓
Gas Analysis
↓
Proxy Analysis
↓
CREATE2 Analysis
↓
Deployment Simulation
↓
Security Score
↓
Risk Analysis
↓
PASS ?
↓
YES
↓
DEPLOY
or
NO
↓
BLOCK DEPLOYMENT
```
Users may bypass deployment protection using:
```bash
forge deploy --force
```
Warnings MUST still be displayed.
---
# SECURITY ENGINE
Implement:
```text
HIGH
Reentrancy
Access Control
Delegatecall
tx.origin
CREATE2
DOS
Storage Collision
Unsafe Assembly
Selfdestruct
Proxy Vulnerabilities
Upgradeability Issues
Oracle Manipulation
Signature Vulnerabilities
Replay Attacks
ERC20 Issues
ERC721 Issues
ERC1155 Issues
ERC4626 Issues
ERC6909 Issues
ERC4337 Issues
EIP7702 Issues
Bridge Vulnerabilities
DEX Vulnerabilities
Staking Vulnerabilities
DAO Vulnerabilities
Flash Loan Issues
Liquidity Issues
MEV Issues
Sandwich Vulnerabilities
Frontrunning
Cross Chain Issues
Dependency Vulnerabilities
Unsafe Imports
Unsafe Ownership Transfers
Unsafe Initializers
Unsafe Upgrade Paths
CREATE Vulnerabilities
Clone Vulnerabilities
Minimal Proxy Issues
Beacon Proxy Issues
Transparent Proxy Issues
UUPS Issues
```
Implement:
```text
MEDIUM
Gas Problems
Unsafe Casting
Timestamp Manipulation
Poor Access Patterns
Storage Inefficiencies
Unsafe Events
Poor Visibility Definitions
Bad Modifiers
Unsafe Math Patterns
```
Implement:
```text
LOW
Naming Issues
Code Duplication
Optimization Suggestions
Architecture Suggestions
Best Practices Recommendations
```
Implement:
```text
INFORMATIONAL
Style
Readability
Architecture
Documentation
Developer Experience Suggestions
```
---
# SUPPORTED STANDARDS
Implement dedicated auditors for:
```text
ERC20
ERC721
ERC1155
ERC4626
ERC6909
ERC4337
EIP7702
CREATE2
UUPS
Transparent Proxy
Beacon Proxy
Minimal Proxy
Bridges
DEXes
DAOs
Vaults
Multisigs
Factories
Launchpads
Token Creators
Staking Protocols
Lending Protocols
AMMs
Yield Protocols
```
---
# EXPLOIT ENGINE
The framework must generate:
```text
possible exploit paths
possible attack vectors
unsafe code paths
unsafe storage paths
unsafe upgrades
unsafe deployments
```
Generate:
```text
proof of concept attacks
where possible.
```
Example:
```text
HIGH
Delegatecall vulnerability found.
Attack Path:
↓
Attacker calls:
↓
execute()
↓
delegatecall()
↓
ownership overwritten
↓
funds stolen
Severity:
HIGH
Recommended Fix:
↓
use access control modifier
Production Ready:
NO
```
---
# SECURITY SCORE
Generate:
```text
100/100
```
Categories:
```text
Access Control
Security
Fuzzing
Gas
Architecture
Upgradeability
Dependencies
Deployment
Proxy Safety
Chain Compatibility
Production Readiness
Exploit Resistance
```
Example:
```text
Security Score:
97/100
--------------------
Risk Level:
LOW
--------------------
Production Ready:
YES
--------------------
Deployment:
APPROVED
```
---
# REPORT ENGINE
Support:
```text
JSON
Markdown
```
Reports MUST include:
```text
vulnerabilities
risk score
security score
gas score
exploit demonstrations
proof of concept attacks
recommendations
unsafe patterns
deployment analysis
proxy analysis
chain analysis
dependency analysis
production readiness
```
Generate:
```text
audit.json
audit.md
```
---
# MULTI-CHAIN SUPPORT
Architecture:
```text
EVM CORE
↓
plugins/
↓
ethereum/
base/
arbitrum/
optimism/
polygon/
bnb/
avalanche/
scroll/
linea/
unichain/
zksync/
monad/
hyperliquid/
solana/
tron/
sui/
aptos/
```
Examples:
```bash
forge audit --chain ethereum
forge audit --chain base
forge audit --chain arbitrum
forge audit --chain polygon
forge audit --chain solana
forge audit --all-chains
```
Implement:
```text
chain specific analyzers
chain specific deployment analysis
gas estimations
supported standards
RPC validations
deployment validations
```
---
# DOCTOR COMMAND
Implement:
```bash
forge doctor
```
Analyze:
```text
Foundry versions
Solidity versions
unsafe dependencies
RPC configurations
proxy configurations
deployment scripts
compiler settings
optimizer settings
gas settings
project structure
security configurations
```
---
# CI/CD
Support:
```text
Github Actions
Gitlab
Bitbucket
Azure DevOps
```
Example:
```yaml
forge audit
forge fuzz
forge invariant
forge security
forge deploy
```
Deployment MUST fail if:
```text
critical vulnerabilities exist.
```
---
# PROJECT STRUCTURE
```textforge-guard/
core/
security/
plugins/
chains/
reports/
deployment/
gas/
fuzzing/
invariants/
simulation/
dependencies/
doctor/
verify/
benchmark/
ci/
utils/
examples/
tests/
docs/
```
Implement:
```text
100% test coverage
integration tests
performance benchmarks
security tests
fuzz tests
invariant tests
```
---
# FUTURE AI SUPPORT
Do NOT implement AI mode now.
However, design extension points for:
```text
GPT
Claude
Gemini
Open Source Models
Ollama
Local Models
```
Future agents:
```text
Security Auditor
↓
Gas Auditor
↓
Logic Auditor
↓
Bridge Auditor
↓
Upgradeability Auditor
↓
DeFi Auditor
↓
Lead Security Engineer
↓
Consensus Engine
↓
Final Audit Report
```
The architecture MUST support adding these agents without breaking backward compatibility.
---
# PERFORMANCE REQUIREMENTS
The framework must:
```text
use Rust for performance
use caching
support parallel execution
support incremental analysis
support large codebases
minimize memory consumption
support enterprise projects
```
---
# IMPLEMENTATION REQUIREMENTS
The implementation MUST include:
1. Complete Rust source code.
2. Complete Foundry integrations.
3. Complete plugin architecture.
4. Complete deployment guard implementation.
5. Complete security engine.
6. Complete report generation.
7. Complete CI integrations.
8. Complete exploit analysis engine.
9. Complete documentation.
10. Comprehensive tests.
11. Multi-chain support.
12. Future AI extension points.
13. Production-ready code only.
14. No placeholders or TODO implementations.
15. Security-first design decisions throughout the entire codebase.
The primary objective of this project is to make `forge deploy` safe by default by transforming security auditing from an optional step into a mandatory pre-deployment process while providing developers with the most comprehensive offline smart contract auditing framework available for Foundry.