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.
Submitted by WatchPug, also found by 0x1f8b, Chom, and gzeon
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
getBorrowRatereturns 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.
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.