Skip to Content
Native FeaturesMEV Protection

MEV Protection

TOS provides native MEV (Maximal Extractable Value) protection to defend users against front-running, sandwich attacks, and other transaction ordering exploits.

Implementation Status

FeatureStatus
Deferral mechanism (max 3 delays)Implemented
FIFO transaction orderingImplemented
Slippage protectionImplemented
Encrypted mempoolPlanned
Commit-reveal schemePlanned

What is MEV?

MEV = Maximal Extractable Value Attacks enabled by transaction ordering: 1. Sandwich Attack - Attacker sees user's DEX trade - Buys before user (raises price) - User buys at higher price - Attacker sells (profits) 2. Front-running - Attacker copies profitable transaction - Pays higher gas to execute first - Steals the profit 3. Back-running - Attacker executes immediately after - Exploits price impact of large trades

MEV Impact

ChainMEV ProblemEstimated Annual Loss
EthereumSevere$1B+
BSCSevere$100M+
SolanaModeratePartial protection
TRONLighterLess DEX activity
TOSProtectedMinimal

Protection Mechanisms

1. FIFO Ordering

/// Transactions ordered by arrival time /// Not by gas price pub struct TransactionOrder { /// When validator received transaction arrival_time: u64, /// Transaction data tx: Transaction, } // Validators cannot reorder for profit // Validator transactions go last

2. Deferral Mechanism

/// Large transactions automatically deferred pub const MAX_DEFERRALS: u8 = 3; fn should_defer(tx: &Transaction) -> bool { // Large DEX swaps get deferred if is_dex_swap(tx) && get_usd_value(tx) > 10_000 { return true; } false }

3. Slippage Protection

pub struct SwapProtection { /// Max acceptable slippage (basis points) pub max_slippage_bps: u16, /// Minimum output amount pub min_output: u64, /// Price quote validity pub price_valid_until: u64, } fn check_slippage(swap: &Swap, actual_price: u64) -> Result<(), SwapError> { let expected = get_oracle_price(swap.pair); let slippage = (expected - actual_price) * 10000 / expected; if slippage > swap.protection.max_slippage_bps { return Err(SwapError::SlippageTooHigh); } Ok(()) }

4. Same-Block Limits

/// Limit same-direction trades in single block fn check_same_block_trades(pool: Address, direction: SwapDirection) -> bool { let trades = get_block_trades(pool); let same_dir = trades.iter() .filter(|t| t.direction == direction) .count(); // Max 3 same-direction trades per block same_dir < 3 }

Future: Encrypted Mempool

/// Threshold-encrypted transaction pub struct EncryptedTransaction { /// Encrypted transaction data pub encrypted_data: Vec<u8>, /// Threshold key ID pub threshold_key_id: u64, /// Earliest execution block pub min_block: u64, } // Flow: // 1. User encrypts tx with threshold public key // 2. Tx enters encrypted mempool // 3. After block finalized, validators decrypt // 4. Execute in decrypted order // Result: No one knows tx content before execution

Future: Commit-Reveal

/// Two-phase transaction pub struct CommitRevealTx { /// Phase 1: Submit hash pub commit: Hash, // hash(tx_data + salt) /// Phase 2: Reveal pub reveal: Option<RevealData>, } // Block N: User commits hash(swap + salt) // Block N+1: User reveals full transaction // Block N+1: Transaction executes // Attackers can't front-run unknown content

DEX Integration

/// Protected DEX swap let swap = protected_swap( Swap { token_in: USDT, token_out: TOS, amount_in: 1000_00000000, }, SwapProtection { max_slippage_bps: 100, // 1% min_output: 950_00000000, price_valid_until: now() + 60, }, )?;

Protection Effectiveness

MetricWithout ProtectionWith Protection
Sandwich success rate90%+Under 5%
Average slippage loss2-5%Under 0.5%
User transaction costHighLow

Comparison

ChainMEV ProtectionLevel
EthereumFlashbots (optional)Medium
BSCNoneNone
SolanaJito (partial)Medium
TOSNative, comprehensiveHigh

Gas Costs

ProtectionAdditional Cost
FIFO orderingNone
Slippage check$0.001
Commit-reveal$0.005
Encrypted tx$0.01
Delayed execution$0.002

Best Practices

  1. Always set slippage limits on DEX trades
  2. Use price validity windows to prevent stale quotes
  3. Consider commit-reveal for large trades
  4. Monitor execution prices against quotes
Last updated on