Borrowers cannot withdraw collateral due to missing poolId validation in buyLoan().
There is no check if msg.sender owns the pool at poolId in buyLoan(). This allows a lender to transfer the loan to another Pool that matches the tokens used for the loan. The loan cannot be repaid as the outstanding debt has transferred to another poolId.
Scenario
Pool A is created by a Lender using Token A and Token B.
A malicious user can call buyLoan() transferring the debt to another matching pool. If there is no matching pool they can create one themselves.
A loan is taken against Pool A and is put up for auction soon after. The malicious user calls buyLoan() transferring the loan to another Pool. This is possible due to buyLoan() not verifying the poolId against the msg.sender.
Now that the loan has transfered to another Pool when the borrower attempts to repay the loan the transaction will revert with an Arithmetic over/underflow due to the check at line 314.
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L314
Borrowers are unable to repay the loan resulting in a loss of collateral.
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L355-L385
Manual review and Foundry for the POC
When buying a loan verify that the lender owns the pool at poolId
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.