Security Framework
Comprehensive Security Architecture
MonBridge implements multiple overlapping security layers to protect users and protocol integrity.
1. Reentrancy Prevention
The Reentrancy Vulnerability
Vulnerable Pattern:
1. Contract sends tokens to external address
2. External address (attacker) calls back into contract
3. Before token transfer complete, attacker exploits state
4. Attacker transfers funds multiple times
Result: Funds stolenMonBridge Protection: State Lock
bool private _locked
modifier nonReentrant() {
require(!_locked, "Reentrant call")
_locked = true
// ... execute logic
_locked = false
}How It Works:
Before any external call, set lock to true
If attacker tries recursive call, lock prevents re-entry
External call completes
Lock released
Protection Level: High - Prevents all reentrancy attacks
2. Access Control Framework
Role-Based Permissions
Owner Authority:
Add/remove routers
Configure slippage parameters
Configure liquidity requirements
Emergency pause/resume
Withdraw accumulated fees
User Capabilities:
Call swap functions (public)
Query pricing (public)
Check venue status (public)
View fees (public)
Access Control Enforcement
Protection Level: High - Sensitive operations protected
3. Oracle-Based Price Protection (TWAP)
Flash Loan Attack Vector
Attack Scenario:
TWAP Defense Mechanism
Time-Weighted Average Price:
Configuration
Protection Effect
Protection Level: High - Prevents flash loan exploitation
4. Liquidity Validation
Minimum Liquidity Requirements (Currently Disabled)
Purpose: Prevent trading through illiquid pools that cause extreme slippage.
Benefits:
Ensures quality venues
Reduces slippage
Prevents exploitation through illiquid venues
Current Status Since Monad is a newly launched L1 and many DEXs still have shallow liquidity, this feature is temporarily disabled to ensure swaps always execute reliably. Once ecosystem liquidity matures, the feature will be activated and the current 1M liquidity threshold will be reduced to support a wider range of trading pairs.
Venue Quality Assessment
Metrics:
Success/failure rates
Historical slippage
Total volume routed
Liquidity depth
Disable Venues:
Automatic suspension if exceeding failure threshold
Prevents cascading failures
Alternative venues still available
5. Smart Contract Risk Mitigation
Arithmetic Safety
Overflow/Underflow Protection:
Multi-Precision Calculations:
Prevent precision loss
Handle varying token decimals
Accurate fee calculations
State Management
Check-Effect-Interaction Pattern:
Immutable Deployment
Once deployed:
Code cannot be modified
Logic cannot be changed
Guarantees users' rules don't change
Prevents post-deployment compromises
6. Token-Specific Security
Fee-on-Transfer Token Handling
Risk: Standard ERC20 assumptions don't hold
MonBridge Protection:
Detect fee-on-transfer mechanism
Calculate net amounts correctly
Route through compatible venues
Account for fees in output calculations
Token Blacklisting
Malicious Token Detection:
Implementation:
Decimal Precision
Risk: Different tokens have different decimals
MonBridge Normalization:
Query token decimals
Convert to common base for comparison
Accurate price calculations across decimals
7. Transaction-Level Safety
Slippage Protection
User Specifies: "I accept maximum 1% slippage"
Execution:
Get quote: Token B amount = 990 (1% less than expected 1000)
Set minimum output: 990 Token B
Execute swap
Verify received >= 990
If not, transaction reverts (all changes undone)
Protection: User receives quoted amount or entire transaction fails
Deadline Protection
Risk: Transaction stuck in mempool, executed hours later at old price
MonBridge Solution:
If transaction not included before deadline, it reverts.
Amount Validation
Before Execution:
Verify user has sufficient input tokens
Verify MonBridge has router allowance
Check sufficient liquidity at venue
After Execution:
Verify output tokens received
Verify amount meets minimum threshold
Verify correct recipient
8. Venue-Level Protections
Router Health Tracking
Automatic Failover
Venue Selection Logic
Routes traffic to:
Active routers only (disabled routers skipped)
Best pricing (among active routers)
High health score (prefer reliable venues)
Sufficient liquidity (meets minimum requirements)
9. Circuit Breaker (Emergency Controls)
Pause Mechanism
Use Cases:
Security vulnerability discovered
Unusual market conditions detected
Exploitation attempt identified
Network consensus issues
Effect:
New swaps blocked
Existing state preserved
Can be resumed safely
10. Event Logging & Audit Trail
Comprehensive Event Recording
Recorded Information:
Who executed (user address)
Which router was used
Input/output tokens
Amounts involved
Fee collected
Slippage experienced
Type of swap
Auditability:
Every swap visible on-chain
Cannot be modified or hidden
Permanent record
Queryable by anyone
Security Trade-offs
What MonBridge Optimizes For
✅ Smart Contract Security: On-chain logic is immutable and transparent ✅ Flash Loan Protection: TWAP oracle prevents manipulation ✅ Reentrancy Safety: State lock prevents recursive attacks ✅ Access Control: Owner-gated sensitive operations ✅ Token Safety: Blacklisting and fee-on-transfer support
Inherent Limitations
⚠️ Venue Risk: Depends on quality of integrated DEX venues ⚠️ User Error: Cannot prevent user from setting wrong slippage tolerance
Risk Assessment
Bad Token
Medium
Blacklist + fee detection
Bad Venue
Medium
Health monitoring + failover
User Error
Low
Clear pricing display
Ongoing Security Practices
Code Auditing
Continuous monitoring for vulnerabilities
Transparent disclosure of findings
Upgrade Path
Smart contract proxy patterns (if needed)
Careful testing before deployment
Gradual rollout for major changes
Next: See Trade Execution Models for how execution happens within this security framework.
Last updated