An attacker can use the front-running attack method, when repayLoan is called, execute the mergeTranches function in advance, and make the id in _loans updated. In this case, the repayLoan execution will fail due to inconsistent _loanId.
If the attacker keeps using this attack, the borrower's debt will not be repaid, eventually causing the collateral to be liquidated.
In addition to the mergeTranches function, the attacker can also call addNewTranche, and the borrower can also call the refinance-related function, again causing _loanId to be updated.
An attacker can also use the same method to attack refinance related functions, making refinance unable to execute.
An attacker can also use the same method to attack the liquidateLoan function, making it impossible for debts to be cleared.
Judge has assessed an item in Issue #35 as 3 risk. The relevant finding follows:
Lines of code
https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/loans/MultiSourceLoan.sol#L405
Vulnerability details
Impact
The attackers make it impossible for borrowers to repay their debts, and the collateral is liquidated when the debts mature.
Proof of Concept
repayLoan
, need to check theloanId
, if the id is inconsistent will revert.The problem is that
_loans[_loanId]
can change, for example, whenmergeTranches
delete the oldloanId
and write the new one.An attacker can use the
front-running
attack method, whenrepayLoan
is called, execute themergeTranches
function in advance, and make the id in_loans
updated. In this case, therepayLoan
execution will fail due to inconsistent_loanId
.If the attacker keeps using this attack, the borrower's debt will not be repaid, eventually causing the collateral to be liquidated.
In addition to the
mergeTranches
function, the attacker can also calladdNewTranche
, and the borrower can also call the refinance-related function, again causing_loanId
to be updated.An attacker can also use the same method to attack
refinance
related functions, making refinance unable to execute.An attacker can also use the same method to attack the
liquidateLoan
function, making it impossible for debts to be cleared.Tools Used
vscode, manual
Recommended Mitigation Steps
Do not delete
_loanId
Assessed type
DoS