`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.
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
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
Tool used
Manual Review
Recommendation
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);
}
}
}
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.