The Standard

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

Precision Loss in distributeAssets() function

Summary

The contract has precision loss issue in the distributeAssets() function. The contract performs division before multiplication(Decimal Normalization).

Vulnerability Details

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

Impact

This results in a loss in precision. Specifically, the costInEuros wont be as accurate

Tools Used

Manual review

Recommendations

Rearrange the operation to perform multiplication before division. This can help prevent the loss of precision.
The correct line should therefore be:

uint256 costInEuros = ((_portion * 10 ** (18 - asset.token.dec)) * uint256(assetPriceUsd) / uint256(priceEurUsd)) * _hundredPC / _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.