20,000 USDC
View results
Submission Details
Severity: medium

Underflow possibility in repay function

Summary

The repay function in the smart contract enables users to repay one or multiple loans at once. However, there is a possibility of an underflow in this function due to the subtraction of loan.debt from pools[poolId].outstandingLoans without proper validation. This issue could lead to unintended behavior and potential loss of funds.

Vulnerability Details

The vulnerable line of code in the repay function is as follows:

pools[poolId].outstandingLoans -= loan.debt;

This line attempts to subtract the loan.debt from the outstandingLoans value in the pools[poolId] storage. However, if the loan.debt value is greater than the current value of outstandingLoans, an underflow can occur.

Impact

If an underflow happens in the repay function, the outstandingLoans value in the pools[poolId] storage will wrap around to a very large positive value, potentially leading to incorrect calculations and loss of funds in the pool. Additionally, it may affect subsequent loan processing and balance calculations.

Tools Used

manual

Recommendations

require(pools[poolId].outstandingLoans >= loan.debt, "Underflow: outstandingLoans");
pools[poolId].outstandingLoans -= loan.debt;

Support

FAQs

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