20,000 USDC
View results
Submission Details
Severity: high
Valid

Lender loses money when a loan is refinanced

Summary

The updated debt of a loan is removed twice from the poolBalance when a loan is refined by the refinance function.

Vulnerability Details

In the refinance function the new debt is substracted twice from the pools[poolId].poolBalance. This leads to poolBalance being underestimated and so the lender can not withdraw their tokens anymore, funds are locked in the contract.

File: Lender.sol
L635: // now lets deduct our tokens from the new pool
_updatePoolBalance(poolId, pools[poolId].poolBalance - debt);
// [...]
L697: // update pool balance
pools[poolId].poolBalance -= debt; // @audit - [CRITICAL] Debt is removed for the second time

https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Lender.sol#L636

https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Lender.sol#L698

Impact

Funds can be locked in the contract after a refinancing. In addition, borrower is not able to refinance if they own more than the half of the pool because the second poolBalance update will underflow.

Tools Used

Manual review

Recommendations

Remove the second poolBalance update at line 698.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.