Skip to content
Business logic Audit finding Intermediate

Inaccurate collateral factor calculation due to missing collateral asset

The collateralFactor() function in the USSD smart contract fails to account for collateral assets that have been removed from the collateral list, leading to an inaccurate calculation of the protocol's collateral factor. This can cause the reported collateral factor to be lower than it should be, potentially affecting risk assessment and stability.

0xeix Follow with Angry_Mustache_Man, Bauer and 11 others

Originally disclosed on Sherlock

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

Found by

0xeix, Angry_Mustache_Man, Bauer, BugHunter101, Dug, PokemonAuditSimulator, TheNaubit, immeas, juancito, mahdikarimi, ravikiran.web3, sakshamguruji, shaka, theOwl

Summary

The function collateralFactor() in the smart contract calculates the collateral factor for the protocol but fails to account for the removal of certain collateral assets. As a result, the total value of the removed collateral assets is not included in the calculation, leading to an inaccurate collateral factor.

Vulnerability Detail

The collateralFactor() function calculates the current collateral factor for the protocol. It iterates through each collateral asset in the system and calculates the total value of all collateral assets in USD.

For each collateral asset, the function retrieves its balance and converts it to a USD value by multiplying it with the asset's price in USD obtained from the corresponding oracle. The balance is adjusted for the decimal precision of the asset. These USD values are accumulated to calculate the totalAssetsUSD.

Solidity
   function collateralFactor() public view override returns (uint256) {
        uint256 totalAssetsUSD = 0;
        for (uint256 i = 0; i < collateral.length; i++) {
            totalAssetsUSD +=
                (((IERC20Upgradeable(collateral[i].token).balanceOf(
                    address(this)
                ) * 1e18) /
                    (10 **
                        IERC20MetadataUpgradeable(collateral[i].token)
                            .decimals())) *
                    collateral[i].oracle.getPriceUSD()) /
                1e18;
        }

        return (totalAssetsUSD * 1e6) / totalSupply();
    }

However, when a collateral asset is removed from the collateral list, the collateralFactor function fails to account for its absence. This results in an inaccurate calculation of the collateral factor. Specifically, the totalAssetsUSD variable does not include the value of the removed collateral asset, leading to an underestimation of the total collateral value. The function SellUSSDBuyCollateral() in the smart contract is used for rebalancing. However, it relies on the collateralFactor calculation, which has been found to be inaccurate. The collateralFactor calculation does not accurately assess the portions of collateral assets to be bought or sold during rebalancing. This discrepancy can lead to incorrect rebalancing decisions and potentially impact the stability and performance of the protocol.

Solidity
    function removeCollateral(uint256 _index) public onlyControl {
        collateral[_index] = collateral[collateral.length - 1];
        collateral.pop();
    }

Impact

As a consequence, the reported collateral factor may be lower than it should be, potentially affecting the risk assessment and stability of the protocol.

Code Snippet

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

Tool used

Manual Review

Recommendation

Ensure accurate calculations and maintain the integrity of the collateral factor metric in the protocol's risk management system.

The original report as published on Sherlock, by 0xeix. 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

Likely the collateralFactor() function only iterates over the current collateral array, so any assets removed from that array are excluded from the total value calculation.

Impact

The reported collateral factor may be lower than it should be, potentially affecting the risk assessment and stability of the protocol.

What the attacker needed

Removal of a collateral asset

The fix

The collateralFactor calculation should be updated to include the value of removed collateral assets, or the removal process should ensure that such assets are properly accounted for.

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.

A smart contract calculates a 'collateral factor' by adding up the value of all assets it holds. If some assets are removed from the list but still held, the calculation ignores them, making the factor too low. This could mislead the protocol's risk management.

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 0xeix

View all

10 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.