There is a counting error in the Lender.sol::refinance() function causing losses to the new pool who takes the loan.
The Lender.sol::refinance() helps to the borrower to refinance his loan to a new offer (pool).
The problem is that the new pool, whoever takes the loan, his balance is substracted twice. First the balance is substracted here:
and here is subtracted one more time:
I created a test where the new pool (initial pool balance of 1000 tokens) who takes the loan will end up with 800 token balance, which is incorrect because the loan debt is 100 tokens. Test steps:
Create a borrow in the first pool with 1000 balance. Borrower borrows 100 debt and put 100 collateral.
Lender2 creates a second pool with 1000 pool balance.
Borrower execute the refinance to the second pool with the same debt amount.
Assert first pool balance gets the 100 loaned amount, so the first pool balance is now 1000.
Assert second pool balance is substracted two times and the loan debt is still 100 tokens.
The second pool should have a balance of 900 tokens not 800.
The new pool, whoever takes the loan, will lost balance. In the example above the borrower will pay 100 debt tokens but there are another 100 tokens that are lost and nobody will pay.
Manual review
Remove the next lines:
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.