calculateRiskFactor() computes the risk factor differently than what is documented.
Vulnerability Detail
The comment says the denominator should be (currentLeverageRatio - leverageRatioFloor - BUFFER), while in the code it actually is (currentLeverageRatio - (leverageRatioFloor - BUFFER)) = (currentLeverageRatio - leverageRatioFloor + BUFFER)
The risk factor computed as per the comments is higher than what it is in reality, which can be confusing and lead to unexpected results for end-users.
joestakey
medium
Mismatch for Risk Factor formula
Summary
calculateRiskFactor()
computes the risk factor differently than what is documented.Vulnerability Detail
The comment says the denominator should be
(currentLeverageRatio - leverageRatioFloor - BUFFER)
, while in the code it actually is(currentLeverageRatio - (leverageRatioFloor - BUFFER)) = (currentLeverageRatio - leverageRatioFloor + BUFFER)
Impact
The risk factor computed as per the comments is higher than what it is in reality, which can be confusing and lead to unexpected results for end-users.
Code Snippet
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/libraries/RiskFactorCalculator.sol#L27
Tool used
Manual Review
Recommendation
Amend the comment to match the code.