Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

blockdev - Rebalancing is open to flashloan attack #39

Closed
sherlock-admin opened this issue May 23, 2023 · 0 comments
Closed

blockdev - Rebalancing is open to flashloan attack #39

sherlock-admin opened this issue May 23, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented May 23, 2023

blockdev

high

Rebalancing is open to flashloan attack

Summary

Rebalancing begins by fetching USSD's spot price relative to DAI from its Uniswap pool. Anyone can imbalance the pool through a flash loan before rebalancing begins which leads to a wrong USSD price. This results in incorrect rebalancing, even more so because of the fact that rebalance() function can be called by anyone.

Vulnerability Detail

rebalance() calls getOwnValuation() to determine USSD price relative to DAI:

function getOwnValuation() public view returns (uint256 price) {
  (uint160 sqrtPriceX96,,,,,,) =  uniPool.slot0();
  if(uniPool.token0() == USSD) {
    price = uint(sqrtPriceX96)*(uint(sqrtPriceX96))/(1e6) >> (96 * 2);
  } else {
    price = uint(sqrtPriceX96)*(uint(sqrtPriceX96))*(1e18 /* 1e12 + 1e6 decimal representation */) >> (96 * 2);
    // flip the fraction
    price = (1e24 / price) / 1e12;
  }
}

uniPool.slot() returns the spot price's square root which is susceptible to flash loan attack as explained above.

Impact

High. Almost all rebalancing transactions will result in loss for the protocol.

Code Snippet

function getOwnValuation() public view returns (uint256 price) {
  (uint160 sqrtPriceX96,,,,,,) =  uniPool.slot0();
  if(uniPool.token0() == USSD) {
    price = uint(sqrtPriceX96)*(uint(sqrtPriceX96))/(1e6) >> (96 * 2);
  } else {
    price = uint(sqrtPriceX96)*(uint(sqrtPriceX96))*(1e18 /* 1e12 + 1e6 decimal representation */) >> (96 * 2);
    // flip the fraction
    price = (1e24 / price) / 1e12;
  }
}

Tool used

Manual Review

Recommendation

Use a TWAP price which will result in inaccurate price (due to being an average over time) but more resistant towards price manipulation.

Duplicate of #451

@github-actions github-actions bot closed this as completed Jun 5, 2023
@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jun 5, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant