Borrowers lose funds if they call repayAndCloseLoan instead of closeLoan
The repayAndCloseLoan function does not check that a loan has been matched with a lender, so calling it on an unmatched loan causes the borrower to transfer a large interest amount and the minimum loan amount to the zero address. A borrower who has approved the contract could lose funds if they call this function instead of closeLoan.
Submitted by cmichel
The repayAndCloseLoan function does not revert if there has not been a lender for a loan (matched with lend). Users should use closeLoan in this case but the contract should disallow calling repayAndCloseLoan because users can lose funds.
It performs a ERC20(loan.loanAssetContractAddress).safeTransferFrom(msg.sender, lender, interest + loan.loanAmount) call where interest will be a high value accumulated from timestamp 0 and the loan.loanAmount is the initially desired min loan amount minLoanAmount set in createLoan. The user will lose these funds if they ever approved the contract (for example, for another loan).
Recommended Mitigation Steps
Add a check that there actually is something to repay.
require(loan.lastAccumulatedTimestamp > 0, "loan was never matched by a lender. use closeLoan instead");
wilsoncusack (Backed Protocol) commented:
ownerOf query here will fail if there is no lender, NFTLoanFacilitator.sol#L239.
wilsoncusack (Backed Protocol) confirmed and commented:
Actually this is wrong, we switched to solmate and this ownerOf will not fail. Is a legit issue.
Not an attack, but funds can be lost some. Medium probably makes sense?
wilsoncusack (Backed Protocol) commented:
Requires borrow to have approved the facilitator to move this erc20 and to call the wrong method.
wilsoncusack (Backed Protocol) resolved and commented:
Yooo just discovered solmate had not followed the ERC721 standard on this ownerOf and it should have reverted, updated here
Sponsor confirmed with fix.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the function lacks a check that the loan has been matched by a lender before attempting repayment.
Impact
Borrowers could lose funds if they have approved the contract and call repayAndCloseLoan on an unmatched loan; the sponsor notes this requires the borrower to have approved the facilitator and to call the wrong method.
What the attacker needed
Borrower has approved the contract; borrower calls repayAndCloseLoan on unmatched loan
The fix
The issue was fixed by updating the ownerOf implementation in solmate so that it reverts when there is no lender.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract has a function to repay a loan and close it. If no lender has taken the loan yet, that function should refuse to run, but it does not. Calling it anyway makes the borrower send money to an empty address, so they lose it.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.