β½ Gas Validation System
SuperSafe Wallet implements a comprehensive gas validation system that protects users from malicious transactions, scams, and uneconomical swaps.
Overviewβ
The gas validation system provides real-time protection by:
- π° Insufficient Balance Detection: Ensures users have enough native tokens to pay gas fees
- π¨ Scam Detection: Identifies malicious contracts with abnormally high gas costs
- π Network Congestion Awareness: Warns users about high network congestion
- β οΈ Uneconomical Swap Prevention: Alerts when gas fees exceed reasonable percentages of swap value
Key Featuresβ
- β Real-time Gas Monitoring: Fetches current network gas prices via Moralis RPC
- β Dual Validation: Compares network gas vs quote gas to detect anomalies
- β Multi-Network Support: Network-specific thresholds for 6 EVM chains
- β Progressive Alerts: 5-level alert system (NONE β BLOCKING)
- β Button-Integrated UI: Alerts shown directly on swap button
- β Automatic Blocking: Disables swap when insufficient balance or gas > 50% of value
Alert Levelsβ
The gas validation system uses a 5-level alert system:
| Level | Condition | Button Action |
|---|---|---|
| BLOCKING | Insufficient balance for gas | β Button Disabled |
| BLOCKING | Gas > 50% of swap value (scam indicator) | β Button Disabled |
| CRITICAL | Gas anomalous or > 20% of value | β Enabled (logged warning) |
| WARNING | Gas > 5% or high network congestion | β Enabled (logged warning) |
| INFO | Moderate network congestion | β Enabled (logged info) |
| NONE | All clear | β Enabled |
Only BLOCKING level alerts disable the swap button and change the button text. Lower levels are logged but don't interrupt your swap flow.
Gas Price Thresholdsβ
Based on Q4 2025 market data from official explorers and wallet providers:
| Network | Low | Medium | High | Extreme |
|---|---|---|---|---|
| Ethereum | 5 Gwei | 20 Gwei | 60 Gwei | 120 Gwei |
| Optimism | 0.001 Gwei | 0.01 Gwei | 0.1 Gwei | 0.5 Gwei |
| Arbitrum | 0.01 Gwei | 0.1 Gwei | 1 Gwei | 5 Gwei |
| Base | 0.001 Gwei | 0.01 Gwei | 0.1 Gwei | 0.5 Gwei |
| BSC | 0.05 Gwei | 0.5 Gwei | 2 Gwei | 5 Gwei |
| SuperSeed | 0.001 Gwei | 0.01 Gwei | 0.1 Gwei | 0.5 Gwei |
These thresholds are updated quarterly based on current market conditions.
How It Worksβ
Three-Layer Validationβ
1. Balance Validationβ
Ensures you can afford gas + swap value:
For native token swaps (ETH, BNB, etc.):
totalNeeded = gasEstimate + swapValue
For ERC20 swaps:
totalNeeded = gasEstimate only (swap value is ERC20)
If userBalance < totalNeeded:
β BLOCKING: "Insufficient ETH for Gas"
2. Gas Price Analysis (Scam Detection)β
Compares the gas price in the quote against current network prices:
- Calculates implied gas price from swap quote
- Fetches current network gas price from Moralis RPC
- Flags anomalous prices (significantly higher than network average)
If quote gas price >> network gas price:
β Possible scam contract detected
3. Percentage Analysisβ
Ensures gas cost is economical relative to swap value:
| Gas % of Swap Value | Alert Level |
|---|---|
| > 50% | BLOCKING - "Gas Fee Too High - Possible Scam" |
| > 20% | CRITICAL - Strong warning |
| > 5% | WARNING - Gas fee notice |
| β€ 5% | NONE - All clear |
Coverageβ
Protected Transactionsβ
The gas validation system protects you across:
- Internal Swaps: BebopSwapPanel, RelaySwapPanel
- External dApp Transactions: Any
eth_sendTransactionfrom dApps (Uniswap, PancakeSwap, Velodrome, etc.) - Token Approvals: ERC20 approve calls
- NFT Mints: ERC-721, ERC-1155 operations
- Complex Interactions: Multicall, batch operations
- Native Transfers: ETH, BNB, etc.
Not Covered (No Gas Needed)β
personal_sign- Off-chain signatureseth_signTypedData- Off-chain typed data- Permit2 signatures - Gasless approvals
User Interfaceβ
Swap Panelβ
When gas validation detects an issue, the swap button reflects the alert:
- Normal: "Swap" or "Confirm Swap" (green, enabled)
- Insufficient Gas: "Insufficient ETH for Gas" (red, disabled)
- Scam Detected: "Gas Fee Too High - Possible Scam" (red, disabled)
Transaction Confirmation Screenβ
For dApp transactions, the gas section shows:
- Color-coded background: Red (BLOCKING), Orange (CRITICAL), Yellow (WARNING)
- Expandable details: Network gas price, transaction gas price, congestion level
- Automatic button blocking: Unsafe transactions are blocked
Frequently Asked Questionsβ
Why is my swap blocked?β
Your swap may be blocked if:
- Insufficient balance: You don't have enough native tokens (ETH, BNB, etc.) to pay gas fees
- Scam detection: The gas cost is more than 50% of your swap value, indicating a potentially malicious contract
How do I fix "Insufficient ETH for Gas"?β
Ensure you have enough native tokens in your wallet to cover gas fees. The exact amount needed is shown in the error details.
What if I'm sure it's not a scam?β
If you believe the transaction is legitimate but gas validation is blocking it:
- Check if network congestion is unusually high
- Wait for gas prices to normalize
- Try a smaller swap amount
SuperSafe blocks transactions with gas > 50% of swap value for your protection. This threshold cannot be bypassed.
Technical Detailsβ
For developers, the gas validation system consists of:
- Backend Service:
GasPriceService.js- Fetches and caches gas prices - Stream Handler:
GasStreamHandler.js- Validates balance and provides gas data - Frontend Utility:
gasMonitor.js- Performs comprehensive validation - Configuration:
gasConstants.js- Network-specific thresholds
Document Status: β
Current
Version: v3.1.4
Last Updated: December 18, 2025