The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: medium
Invalid

incorrect decimal handling could break liquidation

Summary

Wrong math is used when dealing with Chainlink price feeds of differing decimal places. This can result in inaccurate reward distribution and token accounting during the liquidation process..

Vulnerability Details

In the Liquidation process LiquidationPool.distributeAssets() is called. which distribute rewards of the liquidation between holders based on their staked value.

function distributeAssets(
ILiquidationPoolManager.Asset[] memory _assets,
uint256 _collateralRate,
uint256 _hundredPC
) external payable {
//...
for (uint256 j = 0; j < holders.length; j++) {
//...
if (_positionStake > 0) {
for (uint256 i = 0; i < _assets.length; i++) {
//...
if (asset.amount > 0) {
(, int256 assetPriceUsd, , , ) = Chainlink
.AggregatorV3Interface(asset.token.clAddr)
.latestRoundData();
uint256 _portion = (asset.amount * _positionStake) / stakeTotal;
uint256 costInEuros = (((_portion * 10 ** (18 - asset.token.dec) * uint256(assetPriceUsd)) / uint256(priceEurUsd)) * _hundredPC) / _collateralRate;
//...
}
}
}
positions[holders[j]] = _position;
}
//...
}

https://github.com/Cyfrin/2023-12-the-standard/blob/main/contracts/LiquidationPool.sol#L205

The issue arises when handling assetPriceUsd and priceEurUsd from Chainlink price feeds. The assumption that these prices will always share the same decimal places (8 decimals) is incorrect. If assetPriceUsd has more decimal places than priceEurUsd, it inflates costInEuros, causing issues in token accounting and reward distribution

Impact

The incorrect handling of decimal places between different Chainlink price feeds can lead to inflated or deflated values in calculations

Tools Used

Manual

Recommendations

Restrict the use of collateral tokens to those aligned with Chainlink price feeds having matching decimal places (e.g., 8 decimals).

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

chainlink-decimals

informational/invalid

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

chainlink-decimals

informational/invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.