Closed github-actions[bot] closed 1 year ago
This is invalid since the call to buyProtection using calculatePremium would have reverted here already: https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L816
@clems4ev3r yeah, this is not valid concern. By design, when leverage ratio is not within range, protocol will use min risk premium as it can't calculate risk factor.
Closing based on above comments
unforgiven
high
Function PremiumCalculator.calculatePremium() would use wrong premium rate when leverageRatio<Pool.leverageRatioFloor which can cause fund loss
Summary
Function calculatePremium() calculates premium and when the leverageRatio is not between the floor and ceiling code would use
Poll.minCarapaceRiskPremiumPercent
ascarapacePremiumRateToUse
and would return the minimum premium but whenleverageRatio < Pool.leverageRatioFloor
the risk is very high and code should return the highest premium.Vulnerability Detail
This is
calculatePremium()
code in PremiumCalculator:As you can see when the return value of the
RiskFactorCalculator.canCalculateRiskFactor()
is false code won't set the value of the_carapacePremiumRate
and it would have 0 value and after the IF cod would set the_minCarapaceRiskPremiumPercent
as the_carapacePremiumRate
and the returned premium would be lowest possible. this iscanCalculateRiskFactor()
code:As you can see there are two states that causes risk factor to be incalculable:
leverageRatio < Pool.leverageRatioFloor
leverageRatio > Pool.leverageRatioCeiling
in both this states code returns the minimum risk factor but whenleverageRatio < Pool.leverageRatioFloor
code should return the maximum risk factor because according to the docs: " The lower the leverage ratio is, the higher the risk factor and the premium are because the market believes that underlying loans are unsafe."Impact
wrong premium calculations when
leverageRatio < Pool.leverageRatioFloor
which can cause other logics that use this function to work incorrectly and some users would lose funds because of the lower calculated premiumes.Code Snippet
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/libraries/RiskFactorCalculator.sol#L33-L56
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/PremiumCalculator.sol#L63-L102
Tool used
Manual Review
Recommendation
when
leverageRatio < Pool.leverageRatioFloor
then set value of the_carapacePremiumRateToUse
to highest.