Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 1.52 KB

081.md

File metadata and controls

33 lines (22 loc) · 1.52 KB

kiki_dev

medium

Underflow when there is more dai than ussd

Summary

rebalance() will revert if ownValue is below threshold and DAI amount is greater than USSD.

Vulnerability Detail

In rebalance() there is a if ownVal is below the threshhold then it will enter the if block. In here BuyUSSDSellCollateral() is called and USSDamount - DAIamount / 1e12)/2 is passed in as a parameter. The problem here is that if DAIamount is greater than USSDamount then a underflow will occur and the transaction will revert. DAI amount can become greater than ussd through the natural progression of the protocol. Or becasue it is a erc20 token and DAIamount is retrieved by getting the direct balance of DAI a user can just send DAI to the contract and force it to revert for all other users.

uint256 vol2 = IERC20Upgradeable(uniPool.token1()).balanceOf(address(uniPool));

Here is the math to support the function reverting.

(USSDamount - DAIamount / 1e12)/2 (1e6 - 2e18 / 1e12) / 2 (1e6 - 2e6) / 2 (-1e6) / 2 <----- underflow, transaction will revert.

The same can be said for when USSD is greater than DAI and rebalance() enters the else block.

Impact

rebalance() will revert and prevent the protocol from working.

Code Snippet

https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/USSDRebalancer.sol#L97

Tool used

Manual Review

Recommendation

Have a check in place to checks if DAI is greater and if it is use a work around to prevent the functionality from breaking.