The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Valid

Precision loss in calculation

Summary

Precision loss in calculation due to division before multiplication

Vulnerability Details

In the function distibuteAssets() while calculating value of costInEuros,

uint256 costInEuros = _portion * 10 ** (18 - asset.token.dec) * uint256(assetPriceUsd) / uint256(priceEurUsd)
* _hundredPC / _collateralRate;

first value obtained from (_portion * 10 ** (18 - asset.token.dec) * uint256(assetPriceUsd)) is divided by priceEurUsd and then multiplied by hundredPC which can cause rounding error.

Impact

Suppose value obtained from (_portion * 10 ** (18 - asset.token.dec) * uint256(assetPriceUsd)) < priceEurUsd in that case costInEuros will be 0.

Tools Used

Manually

Recommendations

In calculation of costInEuros first perform all multiplications and then division
uint256 costInEuros = (_portion * 10 ** (18 - asset.token.dec) * uint256(assetPriceUsd) * _hundredPC)/ uint256(priceEurUsd) / _collateralRate;

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

precision

Support

FAQs

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