Closed sherlock-admin closed 10 months ago
1 comment(s) were left on this issue during the judging contest.
auditsea commented:
$1e-6 can be freely minted, can't even compensate gas
1 comment(s) were left on this issue during the judging contest.
auditsea commented:
$1e-6 can be freely minted, can't even compensate gas
Varun_05
high
Any collateral index can be passed by the user which can cause loss of funds
Summary
A user can call mintDollar and redeemDollar with inputs for collateral index different for both mintDollar and redeemDollar which can lead loss of collateral tokens from the contract which are transferred from other users.
Vulnerability Detail
Following is the mintDollar function in UbiquityPoolFacet.sol
Which calls the mintDollar in LibUbiquityPool.sol which is as follows
main issue is in the function which is used to collateral needed in order to mint dollar
getDollarInCollateralIndex function is as follows
So lets assune missing decimals = 0 so the collateral needed will be calculated as follows
Lets assume collateral price = 20 dollars i.e poolStorage.collateralPrices[collateralIndex] = 20*10**6 = 2e7 and if dollar amount = 19 then collateral needed will be equal to 19.mul(e6).div(20e6) = 0 So the user can mint dollar tokens for free. Not only this now user has 19 dollar tokens - minting fees so lets assume user got 18 dollar tokens and if he calls the redeemDollar function which is as follows
As you can see there is no check on collateralIndex which asserts that the collateral index should be same as the one with which dollar has been minted. So the user can call the collateral index which has price less than the collateralIndex with which he minted the dollar For example now lets assume the price of new collateral = 10 dollars i.e 10e6 So now the redeemFunction is as follows
So now the dollar amount passed is reduced by the redemption fees that the user has to pay lets assume after redemption fees is applied the the token left = 16 dollar tokes Now the amount of collateral the user would get after redeeming the dollar tokens is calculated as follows
GetDollarIncollateral is same as before ,so now we have assumed the price of collateral = 10 dollars i.e 10e6 so the value returned which is collateralOut = 16.mul(e6).div(10e6) = 1 collateral token So from the above it can be seen not only a user can get dollar tokens for free, he can even get a collateral tokens for free. So whenever a there are two or more collaterals with different prices this situation can occur and as the sponsers are planning to use this currently for LUSD and DAI ,price of LUSD is more than that of DAI ,so this attack is feasible.
Impact
Can cause minting of dollar tokens for free and also can cause loss of collateral from the contract which is transferred by other genuine users.
Code Snippet
https://github.com/sherlock-audit/2023-12-ubiquity/blob/d9c39e8dfd5601e7e8db2e4b3390e7d8dff42a8e/ubiquity-dollar/packages/contracts/src/dollar/facets/UbiquityPoolFacet.sol#L92C1-L106C1 https://github.com/sherlock-audit/2023-12-ubiquity/blob/d9c39e8dfd5601e7e8db2e4b3390e7d8dff42a8e/ubiquity-dollar/packages/contracts/src/dollar/facets/UbiquityPoolFacet.sol#L77 https://github.com/sherlock-audit/2023-12-ubiquity/blob/d9c39e8dfd5601e7e8db2e4b3390e7d8dff42a8e/ubiquity-dollar/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol#L284
Tool used
Manual Review
Recommendation
Add some checks to enforce that the collateralIndexs are same in redeem and mint dollar functions
Duplicate of #7