When a borrower calls refinance(), the loan will be brought to the new pool of borrower's choice. While the poolBalance of the old pool is correctly updated, the poolBalance of the new pool is wrongly calculated, which lead to permanent fund losing of the new lender.
The poolBalance of the new pool is deducted twice, which should be only once.
First it occurs here: https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L636
But then in the end when updating loans[loanID] states, the poolBalance is mistakenly deducted once again: https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L698
Copy this test case into test/Lender.t.sol
Use forge test --mt test_refinancePoc to run this test case.
The lender of the new pool will permanently lose the fund equals to the loan debt amount. Or the borrower's refinance action will revert without a specific reason as the poolBalance of the new pool is underflow when poolBalance < loan.debt * 2 since it will be deducted twice. Which also leads to the fact that the new lender loses his/her possibility of earning interest yield although his/her poolBalance is enough for the loan to be refinanced to.
Manual
Remove the second deduction of the new pool's poolBalance.
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L698
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.