Skip to content
Business logic Audit finding Beginner

lending-market/NoteInterest.sol Wrong implementation of getBorrowRate()

The getBorrowRate function in NoteInterest.sol returns a random interest rate based on the caller's address instead of a proper calculation. An attacker could exploit this to obtain a much lower borrowing rate by using a favourable address.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by 0x1f8b, Chom, and gzeon

https://github.com/Plex-Engineer/lending-market/blob/b93e2867a64b420ce6ce317f01c7834a7b6b17ca/contracts/NoteInterest.sol#L92-L101

function getBorrowRate(uint cash, uint borrows, uint reserves) public view override returns (uint) {
    // Gets the Note/gUSDC TWAP in a given interval, as a mantissa (scaled by 1e18)
    // uint twapMantissa = getUnderlyingPrice(note);
    uint rand = uint(keccak256(abi.encodePacked(msg.sender))) % 100;
    uint ir = (100 - rand).mul(adjusterCoefficient).add(baseRatePerYear).mul(1e16);
    uint newRatePerYear = ir >= 0 ? ir : 0;
    // convert it to base rate per block
    uint newRatePerBlock = newRatePerYear.div(blocksPerYear);
    return newRatePerBlock;
}

The current implementation will return a random rate based on the caller’s address and baseRatePerYear.

This makes some lucky addresses pay much lower and some addresses pay much higher rates.

Alex the Entreprenerd (judge) commented:

The warden has shown how, due to most likely a developer oversight, the unimplemented getBorrowRate returns a random value which can easily be gamed (and is not recommended for production).

Because the contract is in scope, and the functionality is broken, I agree with High Severity.


The original report as published on Code4rena, by WatchPug. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

Some addresses pay much lower and some pay much higher interest rates, and the randomness can be gamed to obtain an unfairly low rate.

What the attacker needed

None

The fix

The function should be fixed to implement the intended interest rate calculation instead of using a random value.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This smart contract is supposed to set the interest rate for borrowing, but instead it picks a random number based on who is asking. That means some users get lucky and pay very little interest, while others pay too much. An attacker could keep trying different addresses until they get a low rate.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by WatchPug

View all

197 more disclosed reports, best first.

More from Canto

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.