Skip to content
Business logic Audit finding Intermediate

User specified slippage allows frontrunning

The rebalance and rebalanceLite functions let any caller name the account whose approved funds are used, and the caller also controls the minimum output amount. A frontrunner could copy a pending rebalance call, raise the gas, set the minimum output to zero, and sandwich the Uniswap swap to profit while the named account loses value.

zeroknots Follow with minhtrng, keccak123 and 9 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-uxd-judging/issues/192

Found by

zeroknots, minhtrng, keccak123, peanuts, ck, HollaDieWaldfee, HonorLt, koxuan, GimelSec, wagmi, yixxas, jonatascm

Summary

rebalance and rebalanceLite can be called by any user. Assets are taken from a user specified account address which has approved PerpDepository. If an address has a non-zero approval for PerpDepository, a frontrunner can use rebalance to transfer funds and profit by sandwiching the Uniswap pool swap.

Vulnerability Detail

When mint or redeem is called in UXDController, msg.sender is where the value is coming from. But rebalance allows for the caller to specify the account where funds are coming from. This means msg.sender can be any address. This allows for different scenarios where a frontrunner can profit with these steps.

  1. a frontrunner detects a call of rebalance transaction in the mempool for a certain account address
  2. the frontrunner duplicates the transaction but increases the gas amount (to allow frontrunning the original transaction) and changes the amountOutMinimum value to zero
  3. the frontrunner can profit by sandwiching the Uniswap swap which now has no slippage setting
  4. The user will lose value

Impact

An account that is used in rebalance can lose value

Code Snippet

rebalance can be frontrun https://github.com/sherlock-audit/2023-01-uxd/blob/main/contracts/integrations/perp/PerpDepository.sol#L446

Tool used

Manual Review

Recommendation

rebalance and rebalanceLite should use msg.sender to replace the function argument account address.

Discussion

WarTech9

This is a duplicate of #288

IAm0x52

Fixed in same PR as #288

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

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 function trusts a caller-supplied account address instead of msg.sender and lets the caller set the slippage limit, so anyone can spend an approved account's funds with no price protection.

Impact

An account named in a rebalance call could lose value, though only if it has a non-zero approval to the depository.

What the attacker needed

Target account approved PerpDepository; attacker can see pending transactions

The fix

The functions should use msg.sender instead of the caller-supplied account argument; the text says it was fixed in the same PR as another issue.

How it was found

  1. Watch the mempool for a rebalance call naming a certain account.
  2. Resubmit the same call with higher gas and a minimum output of zero.
  3. Sandwich the Uniswap swap to profit from the missing slippage limit.

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.

A smart contract lets someone move another person's approved tokens, and the person starting the move chooses how little they are willing to get back. An attacker watching pending transactions can jump ahead, accept a terrible exchange rate, and take the difference. The victim's approved funds are spent at a bad price.

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 from UXD Protocol

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.