The Standard

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

Precision loss leads to users paying less for liquidated tokens.

Summary

Current calculation of costInEuros in distributeAssets incurs an unnecessary precision loss due to division before multiplication.

Vulnerability details

uint256 _portion = (asset.amount * _positionStake) /
stakeTotal;
uint256 costInEuros = (((_portion *
10 ** (18 - asset.token.dec) *
uint256(assetPriceUsd)) / uint256(priceEurUsd)) *
_hundredPC) / _collateralRate;
if (costInEuros > _position.EUROs) {
_portion =
(_portion * _position.EUROs) /
costInEuros;
costInEuros = _position.EUROs;
}

Impact

User will have to pay less in EURO for the tokens.

Tools used

VScode, Manual Review

Recommendations

Consider changing it to

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

Lead Judging Commences

hrishibhat Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

precision

Support

FAQs

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