Price calculation susceptible to flashloan exploits
The contract uses the instantaneous price from Uniswap's slot0 instead of a time-weighted average price (TWAP) to value USSD. An attacker can take a flash loan to manipulate the pool price and trigger a rebalance, potentially draining collateral through arbitrage.
0xHati Follow with Bauchibred, Bauer and 29 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-05-USSD-judging/issues/451
Found by
0xHati, Bauchibred, Bauer, BugBusters, Fanz, JohnnyTime, Kodyvim, Schpiel, SensoYard, VAD37, WATCHPUG, __141345__, blockdev, carrotsmuggler, chalex.eth, coincoin, immeas, juancito, kiki_dev, n33k, ni8mare, nobody2018, peanuts, qbs, qckhp, shaka, shogoki, simon135, smiling_heretic, tallo, theOwl, tsvetanovv
Summary
Contract uses uniswap slot0 price instead of TWAP price. slot0 price can be manipulated with flash loans.
Vulnerability Detail
The contract uses the uniswap DAI-USSD pool to get the price of USSD. It however uses the instantaneous price from slot0 instead of the TWAP price. The slot0 price is calculated from the ratios of the assets. This ratio can however be manipulated by buying/selling assets in the pool.
Thus any user can take a flashloan, use those funds to manipulate the price of USSD, and then trigger a rebalance. The attacks can be made profitable by providing just-in-time liquidity to the various pools that reabalance interacts with, draining the contract of collateral through arbitrage.
Impact
Price can be manipulated and rebalance can be called any time. Susceptible to flash loan exploits.
Code Snippet
Tool used
Manual Review
Recommendation
Use TWAP price instead of slot0 price. Here is an example implementation of TWAP.
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
Impact
An attacker could manipulate the price and call rebalance at will, potentially draining the contract's collateral through arbitrage.
What the attacker needed
Access to flash loan funds; ability to trade in the Uniswap pool; ability to call rebalance
The fix
The contract should use a TWAP price instead of the slot0 price.
How it was found
- Take a flash loan to obtain a large amount of funds.
- Use the funds to manipulate the price of USSD in the Uniswap DAI-USSD pool.
- Trigger the rebalance function.
- Provide just-in-time liquidity to the pools that rebalance interacts with to profit from arbitrage.
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 report is about a smart contract that reads the price of a token directly from a trading pool. Because that price can be changed quickly by large trades, an attacker can borrow a huge amount of money for a very short time (a flash loan) to push the price around and profit at the contract's expense.