DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Division by zero in `PerpetualVault::_totalAmount`

Summary

The function PerpetualVault::_totalAmount will return 0 if prices.shortTokenPrice.min is 0. This will lead to incorrect values that will impact the whole contract.

Vulnerability Details

PerpetualVault::_totalAmount function contains a division by zero vulnerability. In the else statement, there is no check for prices.shortTokenPrice.minwhether it is 0.

Impact

If PerpetualVault::_totalAmountreturns 0 due to the zero division, users will not be able to withdraw their funds. Also when a user deposits in the protocol, the amount of minted shares in PerpetualVault::_mint will be incorrect, because PerpetualVault::_totalAmount returns 0.

Tools Used

-manual review

Recommendations

Adding a check if prices.shortTokenPrice.min is not 0 before the calculation.

function _totalAmount(MarketPrices memory prices) internal view returns (uint256) {
if (positionIsClosed) {
return collateralToken.balanceOf(address(this));
} else {
+ if (prices.shortTokenPrice.min == 0) {
+ revert Error.ZeroValue();
+ }
IVaultReader.PositionData memory positionData = vaultReader.getPositionInfo(curPositionKey, prices);
uint256 total = IERC20(indexToken).balanceOf(address(this)) * prices.indexTokenPrice.min / prices.shortTokenPrice.min
+ collateralToken.balanceOf(address(this))
+ positionData.netValue / prices.shortTokenPrice.min;
return total;
}
}
Updates

Lead Judging Commences

n0kto Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Suppositions

There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.

Support

FAQs

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