Skip to content
Business logic Audit finding Intermediate

Slippage checks when adding liquidity are too strict

The addLiquidity function uses the contract's entire token balances and sets minimum amounts to 95% of those balances. If the balances are unbalanced relative to the Uniswap pool, the transaction reverts, and an attacker can force this by sending tokens to the contract, causing a griefing attack.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

When adding liquidity through UniswapHandler.addLiquidity, the entire contract balances are used to add liquidity and the min amounts are set to 95% of these balances. If the balances in this contract are unbalanced (the ratio is not similar to the current Uniswap pool reserve ratios) then this function will revert and no liquidity is added.

See UniswapHandler.buyMalt:

(maltUsed, rewardUsed, liquidityCreated) = router.addLiquidity(
  address(malt),
  address(rewardToken),
  maltBalance, // @audit-info amountADesired
  rewardBalance,
  // @audit assumes that whatever is in this contract is already balanced. good assumption?
  maltBalance.mul(95).div(100), // @audit-info amountAMin
  rewardBalance.mul(95).div(100),
  msg.sender, // transfer LP tokens to sender
  now
);

Impact

If the contract has unbalanced balances, then the router.addLiquidity call will revert. Note that an attacker could even send tokens to this contract to make them unbalanced and revert, resulting in a griefing attack.

Recommended Mitigation Steps

It needs to be ensured that the balances in the contract are always balanced and match the current reserve ratio. It might be better to avoid directly using the balances which can be manipulated by transferring tokens to the contract and accepting parameters instead of how many tokens to provide liquidity with from the caller side.

0xScotch (sponsor) confirmed

Alex the Entreprenerd (judge) commented:

Interestingly the warden highlights the other side of the “missing slippage check” argument. Slippage checks in general need to be calculated offChain (as you will get frontrun in the mempool, so the slippage check is a risk minimization tool more than anything else)

The warden also specified a griefing attack that can be used because of the hardcoded check. The sponsor confirms, I think medium severity is appropriate

The original report as published on Code4rena, by cmichel. 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

Likely the contract uses its own token balances as the desired amounts and sets minimums as a fixed percentage of those balances, without checking that the balances match the pool's reserve ratio.

Impact

An attacker could send tokens to the contract to unbalance it and cause addLiquidity to revert, resulting in a griefing attack that blocks liquidity additions.

What the attacker needed

Attacker can send tokens to the contract

The fix

The contract should ensure balances are always balanced and match the pool's reserve ratio, or better, accept the amounts as parameters from the caller instead of using its own balances.

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.

This is a smart contract that adds liquidity to a trading pool. It assumes the contract's token balances are always in the right proportion, but an attacker can send extra tokens to break that balance and make the function fail. That means no one can add liquidity until the balances are fixed.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by cmichel

View all

196 more disclosed reports, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.