liquidate ()should handle the case if the repaid amount is greater than the loan amount
Summary
liquidate() should handle the case if the repaid amount is greater than the loan amount.
Vulnerability Detail
When liquidating loans in Surge, the liquidator can call liquidate() and pay the borrowers debt partially or fully in exchange for collateral. If liquidator intends to repay the debt in full, then he should set the amount to type(uint).max. If not, the borrower will set an arbitrary amount. However, the liquidator does not know the debt of the borrower until getDebtOf() is called. There may be cases when the amount he intends to pay back is greater than the loan amount. If that is the case, the borrower should also be able to repay in full.
peanuts
medium
liquidate ()should handle the case if the repaid amount is greater than the loan amount
Summary
liquidate() should handle the case if the repaid amount is greater than the loan amount.
Vulnerability Detail
When liquidating loans in Surge, the liquidator can call liquidate() and pay the borrowers debt partially or fully in exchange for collateral. If liquidator intends to repay the debt in full, then he should set the amount to type(uint).max. If not, the borrower will set an arbitrary amount. However, the liquidator does not know the debt of the borrower until getDebtOf() is called. There may be cases when the amount he intends to pay back is greater than the loan amount. If that is the case, the borrower should also be able to repay in full.
If amount > userDebt, then the else part will execute and the transaction will revert because of underflow.
A similar issue can be seen here: https://github.com/sherlock-audit/2023-01-cooler-judging/issues/327
Impact
liquidation will underflow if _amount is greater than userDebt.
Code Snippet
https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L504-L530
Tool used
Manual Review
Recommendation
Recommend updating the logic to take care of cases where _amount > userDebt