When a borrower refinances a loan, tokens equivalent to the new debt are frozen in the protocol and permanently deducted from the pool balance.
In Lender.sol refinance(), the debt
amount is deducted twice from the balance of the new pool to which the loan is transferred.
This will result in:
Tokens being permanently frozen in the contract
The lender will lose debt
amount of tokens from the pool. So the loss depends on the new debt amount
Note: Assume interest=0
Pool A: 50,000 USDC
Pool B: 50,000 USDC
Borrower borrows 10,000 USDC from Pool A, so
Pool A balance = 40,000
Borrower calls refinance()
to move loan to Pool B with a new debt of 20,000 USDC
Pool A will receive 10,000 USDC back so balance = 50,000 USDC
Pool B will be deducted with 20,000 USDC twice (vulnerability), so new balance = 50000-20000-20000 = > 10,000 USDC
Borrower repays loan of 20,000 USDC to Pool B, so
Pool B balance = 10000+20000 => 30,000 USDC
The original balance of Pool B was 50,000 USDC, so
Pool B, thus the lender lost 20,000 USDC
These 20,000 USDC are frozen in the contract
The following POC can be tested in foundry. Copy the funtion in Lender.t.sol to run the POC
Financial loss of funds (ERC20 tokens) for the lender
Tokens are permanently frozen in the contract
Foundry
Update the balance of the new pool only once.
Remove the following line
https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/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.