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

Possible miss match of tokens during refinancing

Summary

The tokens of the loan are not matched with the pool buying it.

Vulnerability Details

During the refinance auction the buyLoan() function does not check if the loan token and collateral token match with the pool buying it.

File:Lender.sol
function buyLoan(uint256 loanId, bytes32 poolId) public {
// get the loan info
Loan memory loan = loans[loanId];
// validate the loan
if (loan.auctionStartTimestamp == type(uint256).max)
revert AuctionNotStarted();
if (block.timestamp > loan.auctionStartTimestamp + loan.auctionLength)
revert AuctionEnded();
// calculate the current interest rate
uint256 timeElapsed = block.timestamp - loan.auctionStartTimestamp;
uint256 currentAuctionRate = (MAX_INTEREST_RATE * timeElapsed) /
loan.auctionLength;
// validate the rate
if (pools[poolId].interestRate > currentAuctionRate) revert RateTooHigh();
// calculate the interest
(uint256 lenderInterest, uint256 protocolInterest) = _calculateInterest(
loan
);
// reject if the pool is not big enough
uint256 totalDebt = loan.debt + lenderInterest + protocolInterest;
if (pools[poolId].poolBalance < totalDebt) revert PoolTooSmall();
// if they do have a big enough pool then transfer from their pool
_updatePoolBalance(poolId, pools[poolId].poolBalance - totalDebt);
pools[poolId].outstandingLoans += totalDebt;
// now update the pool balance of the old lender
bytes32 oldPoolId = getPoolId(
// More code...

Impact

This will destroy the internal accounting of the protocol and may lead to funds being trapped.

Tools Used

Manual Review

Recommendations

Checks should be added to ensure that the tokens match before a sale is conducted.

Support

FAQs

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