समाचार·8 min का पठन·Solingo द्वारा

Front-Running और MEV — बॉट्स आपके Transactions का कैसे फायदा उठाते हैं

Ethereum के dark forest में MEV bots कैसे काम करते हैं और अपने transactions को कैसे बचाएं।

# Front-Running और MEV — बॉट्स आपके Transactions का कैसे फायदा उठाते हैं

Ethereum एक public mempool है जहाँ हर transaction confirm होने से पहले visible होता है। Sophisticated bots इस transparency का फायदा उठाते हैं।

MEV क्या है?

Maximal Extractable Value — block producers (validators) या bots जो block में transactions reorder करके profit कमा सकते हैं।

2023 में extracted MEV: $700M+

Front-Running का Example

आप Uniswap पर 10 ETH से USDC buy करना चाहते हैं:

  • आपका transaction mempool में जाता है
  • Bot आपका transaction देखता है
  • Bot higher gas fee से अपना transaction पहले भेजता है
  • Bot's transaction पहले execute होता है, price बढ़ जाती है
  • आपका transaction higher price पर execute होता है
  • Bot profit में tokens बेच देता है
  • आपका loss: 2-5% slippage

    MEV के प्रकार

    1. Sandwich Attacks

    सबसे common। Bot आपके transaction के आगे और पीछे orders place करता है:

    Bot Buy → Your Buy → Bot Sell

    2. Arbitrage

    Different DEXs के बीच price differences का फायदा:

    // Simplified arbitrage
    

    function arbitrage() external {

    uint price1 = dex1.getPrice(token);

    uint price2 = dex2.getPrice(token);

    if (price1 < price2) {

    dex1.buy(token, amount);

    dex2.sell(token, amount);

    }

    }

    3. Liquidation Front-Running

    Lending protocols में collateral liquidate करने के लिए race:

    User's health factor < 1.0
    

    → Bot detects liquidation opportunity

    → Bot front-runs other liquidators

    → Bot claims liquidation bonus

    Real Attack Case Study

    2022 का एक incident:

    • User ने 50 ETH का NFT purchase transaction भेजा
    • MEV bot ने transaction copy किया और higher gas fee दी
    • Bot ने NFT buy किया
    • User का transaction fail हुआ
    • Bot ने NFT 55 ETH में बेच दिया

    Bot profit: 5 ETH (~$8,000)

    अपने Transactions को कैसे बचाएं

    1. Flashbots Protect

    Private mempool जो front-running से बचाता है:

    const provider = new providers.JsonRpcProvider(
    

    'https://rpc.flashbots.net'

    );

    2. Slippage Tolerance Set करें

    function swapWithProtection(
    

    uint amountIn,

    uint minAmountOut // minimum acceptable output

    ) external {

    uint amountOut = dex.swap(tokenA, tokenB, amountIn);

    require(amountOut >= minAmountOut, "Slippage too high");

    }

    3. Commit-Reveal Pattern

    Sensitive operations के लिए:

    // Step 1: Commit
    

    function commit(bytes32 hash) external {

    commits[msg.sender] = hash;

    }

    // Step 2: Reveal (बाद में)

    function reveal(uint value, bytes32 salt) external {

    require(keccak256(abi.encode(value, salt)) == commits[msg.sender]);

    // अब value use करें

    }

    4. Private RPCs

    Services जो direct validator connection देती हैं:

    • Flashbots Protect
    • bloXroute
    • Eden Network

    Developer Perspective

    अगर आप protocol build कर रहे हैं:

    // ❌ MEV vulnerable
    

    function liquidate(address user) external {

    require(healthFactor(user) < 1e18);

    // liquidation logic

    }

    // ✅ Better — time-delayed

    function queueLiquidation(address user) external {

    require(healthFactor(user) < 1e18);

    liquidationQueue.push(LiquidationRequest({

    user: user,

    timestamp: block.timestamp

    }));

    }

    function executeLiquidation(uint index) external {

    LiquidationRequest memory req = liquidationQueue[index];

    require(block.timestamp >= req.timestamp + DELAY);

    // liquidation logic

    }

    MEV का Positive Side

    सभी MEV bad नहीं है:

    • Arbitrage markets को efficient रखता है
    • Liquidations lending protocols को solvent रखते हैं

    निष्कर्ष

    MEV Ethereum की transparency से inevitable है। Users को:

  • Flashbots/private RPCs इस्तेमाल करें
  • Slippage limits set करें
  • Large trades को split करें
  • MEV-aware protocols चुनें
  • Blockchain के dark forest में जागरूकता ही बचाव है।

    Practice में लगाने के लिए तैयार हैं?

    Solingo पर interactive exercises के साथ इन concepts को apply करें।

    मुफ्त में शुरू करें