You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The _calculateMinRepayUnits function calculates the repayment amount needed to reduce leverage on a debt position, taking into account the acceptable slippage when repaying the debt. However, the implementation of slippage in the calculation is incorrect.
function _calculateMinRepayUnits(uint256 _collateralRebalanceUnits, uint256 _slippageTolerance, ActionInfo memory _actionInfo) internal virtual pure returns (uint256) {
return _collateralRebalanceUnits
.mul(_actionInfo.collateralPrice).div(MORPHO_ORACLE_PRICE_SCALE)
.preciseMul(PreciseUnitMath.preciseUnit().sub(_slippageTolerance));
}
the function subtracts the slippage tolerance. This is incorrect because, when accounting for acceptable slippage, the calculation should add the acceptable percentage instead of subtracting it. As a result, the function will calculate the minimum repayment amount incorrectly, attempting to repay less than intended due to the misapplication of the slippage tolerance.
this will cause unnecessary revert when trying to repay/deleverage even when the slippage is within acceptable range which can temporarily dos the protocol
PoC
No response
Mitigation
To correct this, the calculation should add the slippage tolerance.
The text was updated successfully, but these errors were encountered:
sherlock-admin2
changed the title
Breezy Basil Toad - incorrect slippage in _calculateMinRepayUnits
nikhilx0111 - incorrect slippage in _calculateMinRepayUnits
Oct 28, 2024
nikhilx0111
High
incorrect slippage in _calculateMinRepayUnits
Summary
The _calculateMinRepayUnits function calculates the repayment amount needed to reduce leverage on a debt position, taking into account the acceptable slippage when repaying the debt. However, the implementation of slippage in the calculation is incorrect.
the function subtracts the slippage tolerance. This is incorrect because, when accounting for acceptable slippage, the calculation should add the acceptable percentage instead of subtracting it. As a result, the function will calculate the minimum repayment amount incorrectly, attempting to repay less than intended due to the misapplication of the slippage tolerance.
Root Cause
https://github.com/sherlock-audit/2024-10-morpho-x-index/blob/2f125406e0dd3b1fc029b9a47fe97bfbf906fce2/index-coop-smart-contracts/contracts/adapters/MorphoLeverageStrategyExtension.sol#L1165-L1169
No response
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
No response
Impact
this will cause unnecessary revert when trying to repay/deleverage even when the slippage is within acceptable range which can temporarily dos the protocol
PoC
No response
Mitigation
To correct this, the calculation should add the slippage tolerance.
The text was updated successfully, but these errors were encountered: