Skip to content
Smart contracts Write-up Intermediate

Devoured by Bots: How a Missing Parameter Enabled 100% MEV Leakag

The StableSwapZapIn contract performed an internal token swap without any slippage protection, so an attacker could sandwich the user's transaction and profit from the price movement. The user received far fewer tokens and LP tokens than expected, losing capital to the MEV bot.

Hacker MD Follow

Published on coinsbench.com

In the rapidly evolving world of Decentralized Finance (DeFi), User Experience (UX) is king. To make liquidity provision easier, protocols often introduce “Zap” contracts.

Hacker MD, on coinsbench.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The internal swap in the zap-in function lacked a minimum output amount or a meaningful price limit, so it accepted any exchange rate.

Impact

Users could lose most of the value of their deposit to an MEV bot, receiving far fewer LP tokens than they should.

What the attacker needed

User calls zapIn on the vulnerable contract; attacker can see pending transactions

The fix

The zapIn function should accept a user-defined minimum output for the internal swap and revert if the swap returns less.

How it was found

  1. The attacker sees the user's pending zapIn transaction in the mempool.
  2. The attacker pays a higher gas fee and buys the target token before the user, pushing its price up.
  3. The user's zapIn executes and the internal swap buys the token at the inflated price with no slippage protection.
  4. The attacker sells the token immediately after, profiting from the price difference.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A 'zap' contract lets you deposit one token into a two-token pool by swapping half of it automatically. This contract did the swap without a limit on how bad the exchange rate could be, so a bot could buy the token first, push the price up, let the user's swap happen at the bad price, then sell for a profit. The user ends up with much less than they should.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Hacker MD

View all

12 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.