Lender can borrow from his own pool. When he does that, he can give loan to other pool. Giving away the loan adds debt amount - fee to his pool balance. After withdrawing he has his initial pool balance + debt - fee. This can be profitable when tokens gained have higher value then collateral lost.
There is no check that lender can't borrow from his pool. If there was, he could create second address. If conditions are satisfied, this malicious lender can give the loan to other pool, withdraw and end up with more loan tokens than he started with.
Lender starts with 100,000.
Wallet balance: 100,000
Pool is deployed.
Pool balance: 100,000
Wallet balance: 0
Debt: 0
Lender borrows 100.
Pool balance: 99,900
Wallet balance: 100
Debt: 100
Lender gives away the loan.
Pool balance: 99,999.5
Wallet balance: 100
Debt: 0
Lender withdraws.
Wallet balance: 100,099.5
Lender profited 99.5 tokens. When those tokens are more valuable than collateral lost in the process, he gained value.
Simplified POC was created to demonstrate the flow. It can be run by code below in Lender.t.sol.
Malicious lender can profit from other lenders by giving them his loans from his pool. Other lenders can't defend themselves against such practices.
Manual review
Add two-step transfer to giveLoan feature. First, lender sends transaction to give loan away. The receiving lender would have to send his transaction to accept this loan.
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.