Skip to content
Business logic Audit finding Intermediate

`USSDRebalancer.sol#SellUSSDBuyCollateral` the check of whether collateral is DAI is wrong

The SellUSSDBuyCollateral function uses a logical OR instead of AND when checking whether a collateral token is DAI, so the condition is always true. This can cause the function to attempt a swap with an empty path for DAI, leading to a revert and potential instability of USSD.

0xHati Follow with 0xlmanini, 0xyPhilic and 17 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-05-USSD-judging/issues/193

Found by

0xHati, 0xlmanini, 0xyPhilic, Angry_Mustache_Man, Bahurum, J4de, Vagner, WATCHPUG, ast3ros, auditsea, carrotsmuggler, curiousapple, innertia, nobody2018, qpzm, saidam017, sashik_eth, simon135, smiling_heretic, toshii

Summary

The SellUSSDBuyCollateral function use || instand of && to check whether the collateral is DAI. It is wrong and may cause SellUSSDBuyCollateral function revert.

Vulnerability Detail

Solidity
196       for (uint256 i = 0; i < collateral.length; i++) {
197         uint256 collateralval = IERC20Upgradeable(collateral[i].token).balanceOf(USSD) * 1e18 / (10**IERC20MetadataUpgradeable(collateral[i].token).decimals()) * collateral[i].oracle.getPriceUSD() / 1e18;
198         if (collateralval * 1e18 / ownval < collateral[i].ratios[flutter]) {
199 >>        if (collateral[i].token != uniPool.token0() || collateral[i].token != uniPool.token1()) {
200             // don't touch DAI if it's needed to be bought (it's already bought)
201             IUSSD(USSD).UniV3SwapInput(collateral[i].pathbuy, daibought/portions);
202           }
203         }
204       }

Line 199 should use && instand of || to ensure that the token is not DAI. If the token is DAI, the UniV3SwapInput function will revert because that DAI's pathbuy is empty.

Impact

The SellUSSDBuyCollateral will revert and USSD will become unstable.

Code Snippet

https://github.com/USSDofficial/ussd-contracts/blob/f44c726371f3152634bcf0a3e630802e39dec49c/contracts/USSDRebalancer.sol#L199

Tool used

Manual Review

Recommendation

Diff
      for (uint256 i = 0; i < collateral.length; i++) {
        uint256 collateralval = IERC20Upgradeable(collateral[i].token).balanceOf(USSD) * 1e18 / (10**IERC20MetadataUpgradeable(collateral[i].token).decimals()) * collateral[i].oracle.getPriceUSD() / 1e18;
        if (collateralval * 1e18 / ownval < collateral[i].ratios[flutter]) {
-         if (collateral[i].token != uniPool.token0() || collateral[i].token != uniPool.token1()) {
+         if (collateral[i].token != uniPool.token0() && collateral[i].token != uniPool.token1()) {
            // don't touch DAI if it's needed to be bought (it's already bought)
            IUSSD(USSD).UniV3SwapInput(collateral[i].pathbuy, daibought/portions);
          }
        }
      }

The original report as published on Sherlock, by 0xHati. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

Root cause

The condition uses logical OR instead of AND, making it always true and causing an attempt to swap DAI with an empty path.

Impact

The SellUSSDBuyCollateral function will revert, which could make USSD unstable.

What the attacker needed

None

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.

In a smart contract, a condition that checks if a token is not one of two pool tokens used the wrong logical operator. Using OR means the check is always true, so the code tries to swap DAI even when it shouldn't, which fails because DAI has no swap path set. This can break a function that is meant to keep the stablecoin balanced.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0xHati

View all

4 more disclosed reports, best first.

More from USSD - Autonomous Secure Dollar

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.