Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nikhilx0111 - incorrect slippage in _calculateMinRepayUnits #39

Open
sherlock-admin2 opened this issue Oct 21, 2024 · 0 comments
Open

Comments

@sherlock-admin2
Copy link

sherlock-admin2 commented Oct 21, 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.

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.

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.

@sherlock-admin2 sherlock-admin2 changed the title Breezy Basil Toad - incorrect slippage in _calculateMinRepayUnits nikhilx0111 - incorrect slippage in _calculateMinRepayUnits Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant