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

Zero interest rate and fees while repaying the loan

Summary

Borrowers can loan tokens and repay them at nearly zero interest and 0 percent fees in certain scenarios.
block.timestamp manipulation can aid in this.

Vulnerability Details

When a user wants to pay a loan, the contract calls the _calculateInterest function to calculate the interest accrued and fees that the user has to pay.

Unfortunately, it uses block.timestamp at its core for calculation which can be manipulated by a clever borrower who's also a miner.

He can manipulate it in such a way that the interest and fee approaches zero.

This will lead the person to pay zero interest and zero fee loans which are not intended.

Fuzzing

Code

function testFuzz_InterestRate(
uint interestRate,uint startTimestamp,uint debt,uint timestamp
) external {
interestRate = bound(interestRate,0, 5000);
// timestamp 64078774826 = year 4000
timestamp = bound(timestamp,0, 64078774826);
startTimestamp = bound(startTimestamp,0, 64078774826);
debt = bound(debt,0, 10000000);
unchecked {
uint256 lenderFee = 1000;
uint256 timeElapsed = timestamp - startTimestamp;
uint interest = (interestRate * debt * timeElapsed) / 10000 / 365 days;
uint fees = (lenderFee * interest) / 10000;
interest -= fees;
assert(interest>0 && fees>0);
}
}
}

Fuzz results

Here are some failure cases based on different values of the variables:

No. Loan.InterestRate Loan.startTimeStamp Loan.debt block.timestamp
1 2419 972 5332 6290
2 1698 4788 4 12906
3 597 13453 105151829 14137

Impact

-> Loss of funds for protocol

-> Disturbing inner accounting of the protocol to disturb the normal functioning

Tools Used

Foundry , Manual Review and some brain

Recommendations

There should be some invariant checks on interest and fee being greater than zero otherwise the transaction should revert.

Support

FAQs

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

Give us feedback!