The Standard

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

Division before Multiplication vulnerability in `distributeAssets` function in `LiquidationPool.sol` contract

Summary

The distributeAssets function in LiquidationPool.sol contract has Division before Multiplication vulnerability in it which may lead to the imprecise calculation due to round of decimals as evm can't handle decimal number

Vulnerability Details

The distributeAssets function calculates costInEuros by doing a calculation which involves division and multiplication. The vulnerability arises due to wrong calculation of costInEuros which occurs due to rounding of decimal numbers.

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

As we can see in the above code snippet we are dividing with assetPriceUsd before multiplying with _hundredPC which may lead to imprecise calculations sometimes.

Impact

The impact of the vulnerablity is low as wrong calculation of costInEuros can directly impact the rewards of the stakers

Tools Used

Manual Review

Recommendations

Change the order of operations so that multiplication is performed before division

diff --git a/contracts/LiquidationPool.sol b/contracts/LiquidationPool.sol
index 9b8e593..c8fc905 100644
--- a/contracts/LiquidationPool.sol
+++ b/contracts/LiquidationPool.sol
@@ -217,8 +217,7 @@ contract LiquidationPool is ILiquidationPool {
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;
+ uint256 costInEuros = _portion * 10 ** (18 - asset.token.dec) * uint256(assetPriceUsd) * _hundredPC / uint256(priceEurUsd)/ _collateralRate;
if (costInEuros > _position.EUROs) {
_portion = _portion * _position.EUROs / costInEuros;
costInEuros = _position.EUROs;
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.

Give us feedback!