Skip to content
Smart contracts Audit finding Intermediate

Missing slippage protection in AerodromeDexter.sol swapExactTokensForTokens()

The swap function in AerodromeDexter.sol hardcodes the minimum output amount to zero, so the swap always executes regardless of market conditions. An attacker could exploit this by manipulating the market to cause the user to receive far less than expected, potentially losing a significant portion of their funds.

alix40 Follow with 0xKann, 0xlucky and 32 others

Originally disclosed on Code4rena

Submitted by alix40, also found by 0xKann, 0xlucky, 0xpetern, 0xvd, ABAIKUNANBAEV, Abhan, air_0x, zanderbyte, bharg4v, DharkArtz, dic0de, Hajime, hals, inh3l, John_Femi, kodyvim, lightoasis, Matin, mgf15, MSaptarshi, Mushow, newspacexyz, NexusAudits, PolarizedLight, Rhaydden, Shinobi, smbv-1923, Sparrow, tpiliposian, Tumelo_Crypto, udo, vesko210, waydou, and y51r

Finding description and impact

Even though there is no frontrunning on L2s, which could mitigate some of the MEV attacks, without defined slippage and in case of congestions the swap could be executed at unfavorable conditions presenting losses for users.

https://github.com/code-423n4/2024-12-flex-perpetuals/blob/b84a0812c3368866964b8a16e7c36f6e7a50b655/src/extensions/dexters/AerodromeDexter.sol#L54-L56

        uint256 _balanceBefore = ERC20(_tokenOut).balanceOf(address(this));
@>>        router.swapExactTokensForTokens(_amountIn, 0, routeOf[_tokenIn][_tokenOut], address(this), block.timestamp);

Having the minAmountOut set to 0, will make sure that the swap will always be executed no matter the market condions.

Recommended mitigation steps

We recommend allowing users to set their desired slippage params.

    function run(
        address _tokenIn,
        address _tokenOut,
        uint256 _amountIn,
+        uint256 _minAmountOut,
+        uint64 _deadline
    ) external override returns (uint256 _amountOut) {
        uint256 _balanceBefore = ERC20(_tokenOut).balanceOf(address(this));
-        router.swapExactTokensForTokens(_amountIn, 0, routeOf[_tokenIn][_tokenOut], address(this), block.timestamp);
+        router.swapExactTokensForTokens(_amountIn, _minAmountOut, routeOf[_tokenIn][_tokenOut], address(this), _deadline);

0xRobocop (validator) commented:

As the minimum output is hardcoded to zero, the loss for users that use this function can be of 100% of their funds.

fpcrypto-y (Flex Perpetuals) disputed and commented:

More detailed clarification was given by the Aerodrome team:

The MEV created by Aerodrome isn’t being captured by the Base sequencer currently. As in, the Base sequencer isn’t being used to sandwich attack/frontrun, deposit JIT liquidity, or use its privilege to arb pools/backrun. So there is no sandwiching or proper JIT liquidity attacks occurring at all, due to the Base sequencer choosing not to do this, which is sensible because these attacks are adversarial and would scare users away (I’m not aware of any sandwiching/JIT attacks happening on any centralized sequencer L2s). The Base sequencer isn’t backrunning either, so arbitrage profits are captured by regular arb bots with no special privileges.

The dynamic fee upgrade is expected to greatly reduce the amount of arbitrage profits created by Aerodrome by increasing fees during volatility, essentially allowing regular CL LPs to behave more like professional market makers, because increasing fees during volatility effectively does the same thing as market makers widening their spreads in the order book during volatility. So in essence, the dynamic fee upgrade will hopefully take 80+% of the $ currently being extracted by Aerodrome arb bots and instead allocate it as fees to veAERO voters. I think this is a cleaner and much less centralized solution than creating an appchain with a centralized sequencer and running a privileged arb bot that then redistributes its profits to tokenholders or LPs or traders or whatever it may be.”

0xsomeone (judge) commented:

The Warden and its duplicates have demonstrated that the code lacks proper slippage checks in its AMM interaction within the AerodromeDexter::run function. To clarify a few discussion points:

  • The AMM will consistently result in a non-zero output, so 100% of the funds cannot be captured in a money-efficient manner.
  • While the sequencer does not permit arbitrage opportunities to be arbitrarily captured, the code will continue to result in uncontrollable outputs that might ultimately not result in the output that the caller expects.

Combining the above two points, I believe a medium-risk severity rating is more appropriate for this submission. Users are directly impacted albeit the funds that they might lose would realistically be consistently lower than if arbitrage opportunities could be captured by sandwich attacks.


The original report as published on Code4rena, by alix40. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

How it worked

Root cause

The contract hardcodes the minimum output amount to zero in the call to the router's swap function, removing any slippage protection.

Impact

Users could suffer losses because swaps execute at unfavourable prices, though the judge noted that 100% loss is not realistically achievable and rated it medium risk.

What the attacker needed

User calls the swap function; market conditions are unfavourable

The fix

The function should be changed to accept a user-supplied minimum output amount and deadline, and pass them to the router instead of zero and block.timestamp.

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 report has not been written yet. The Original tab links to the source.

When you swap tokens, you usually set a minimum amount you are willing to receive to protect against sudden price changes. Here, the code always sets that minimum to zero, so the swap goes through no matter how bad the price is. This means someone could manipulate the market and you could get much less than you expected.

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 alix40

View all

2 more disclosed reports, best first.

More from Flex Perpetuals

View all

The newest disclosed reports for this program.

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.