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

Incorrect Loan Ratio Calculation

Summary

The smart contract function borrow allows users to borrow loans from a pool. However, there is a vulnerability in the calculation of the loanRatio, which is crucial for validating the loan-to-collateral ratio. Due to improper arithmetic operations, the calculated loanRatio may be rounded down to the nearest integer, resulting in potential inaccuracies and misrepresentations of the actual loan-to-collateral ratio.

Vulnerability Details

In the borrow function, the loan ratio (loanRatio) is calculated as follows:

uint256 loanRatio = (debt * 10 ** 18) / collateral;

The issue lies in the use of integer division in Solidity, where any fractional part of the result is truncated, leading to inaccurate loanRatio values. This calculation is crucial for ensuring that the loan-to-collateral ratio falls within acceptable limits and helps avoid excessive risk for both the borrower and the lender.

Impact

The incorrect calculation of the loan ratio can have several implications. For example, it may allow borrowers to take loans that exceed the permitted loan-to-collateral ratio, leading to higher risks for the lender. Conversely, it might prevent eligible borrowers from accessing loans within the intended limits, limiting the efficiency of the lending platform.

Tools Used

Manual

Recommendations

Use a reliable fixed-point arithmetic library, such as OpenZeppelin's SafeMath, which provides safe multiplication and division functions for uint256 variables.

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
// Inside the contract
using SafeMath for uint256;
// ...
function borrow(Borrow[] calldata borrows) public {
for (uint256 i = 0; i < borrows.length; i++) {
// ... (existing code)
// Correct calculation of loanRatio using SafeMath
uint256 loanRatio = debt.mul(10 ** 18).div(collateral);
// ... (existing code)
}
}

Support

FAQs

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