You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.
sherlock-admin opened this issue
May 23, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
Attacker can manipulate the return value of USSDRebalancer.getOwnValuation for profit
Summary
Anyone can call USSDRebalancer.rebalance. The execution path of USSDRebalancer.rebalance depends on the return value of USSDRebalancer.getOwnValuation. By flash loan, attacker pumps the price of collateral, and affects the return value of USSDRebalancer.getOwnValuation, then makes profit.
Vulnerability Detail
getOwnValuation uses sqrtPriceX96 returned by uniPool.slot0() to calculate own value. Below I will call it value.
sqrtPriceX96 can be manipulated to affect value returned by getOwnValuation.
Bob deploys an attack contract A. The whole attack is completed in one tx, the process is as follows:
A initiates a flash loan to borrow a certain amount of DAI, which is divided into two parts, one part is used to affect uniPool (USSD-DAI), and the other part is used to buy various collateral tokens.
A calls uniRouter.exactInput to buy USSD in uniPool, so as to achieve the goal of value > 1e6 + threshold.
A calls uniRouter.exactInput (once for each collateral) to buy the collateral token in the specified pool for each collateral. This will pump the price of the collateral.
A calls USSDRebalancer.rebalance, and the flow enters SellUSSDBuyCollateral() due to the operation of the second step. Internally, this function will swap all USSD token in the USSD contract to DAI, and then use all DAI to buy various collaterals. This will further pump the price of the collateral.
A calls uniRouter.exactInput to sell all collateral tokens and USSD for profit.
A repays flash loan.
On the contrary, you can also trigger the execution of BuyUSSSellCollateral to make a profit.
Impact
Attacker profits. The protocol suffers a funds loss.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
nobody2018
high
Attacker can manipulate the return value of USSDRebalancer.getOwnValuation for profit
Summary
Anyone can call
USSDRebalancer.rebalance
. The execution path ofUSSDRebalancer.rebalance
depends on the return value ofUSSDRebalancer.getOwnValuation
. By flash loan, attacker pumps the price of collateral, and affects the return value ofUSSDRebalancer.getOwnValuation
, then makes profit.Vulnerability Detail
getOwnValuation
usessqrtPriceX96
returned byuniPool.slot0()
to calculate own value. Below I will call itvalue
.sqrtPriceX96
can be manipulated to affectvalue
returned bygetOwnValuation
.Bob deploys an attack contract A. The whole attack is completed in one tx, the process is as follows:
A initiates a flash loan to borrow a certain amount of DAI, which is divided into two parts, one part is used to affect uniPool (USSD-DAI), and the other part is used to buy various collateral tokens.
A calls
uniRouter.exactInput
to buy USSD in uniPool, so as to achieve the goal ofvalue > 1e6 + threshold
.A calls
uniRouter.exactInput
(once for each collateral) to buy the collateral token in the specified pool for each collateral. This will pump the price of the collateral.A calls
USSD.mintRebalancer
to mint some amount of USSD token for USSD contract. This will make the return value ofUSSD.collateralFactor
smaller.USSD.collateralFactor
is used in [SellUSSDBuyCollateral](https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/USSDRebalancer.sol#L178).A calls
USSDRebalancer.rebalance
, and the flow entersSellUSSDBuyCollateral()
due to the operation of the second step. Internally, this function will swap all USSD token in the USSD contract to DAI, and then use all DAI to buy various collaterals. This will further pump the price of the collateral.A calls
uniRouter.exactInput
to sell all collateral tokens and USSD for profit.A repays flash loan.
On the contrary, you can also trigger the execution of
BuyUSSSellCollateral
to make a profit.Impact
Attacker profits. The protocol suffers a funds loss.
Code Snippet
https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/USSDRebalancer.sol#L71-L80
Tool used
Manual Review
Recommendation
Use time-weighted prices, similar to the implementation in UniswapV3StaticOracle.sol.
Duplicate of #451
The text was updated successfully, but these errors were encountered: