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

NoteInterest.getBorrowRate() derives interest rate from keccak256(msg.sender)%100, so borrowers get random rates gameable by choosing an address.

- Payout: Contest reward
- Severity: high
- Program: Canto
- Credited: WatchPug
- Disclosed: 2022-10-18
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2022-06-newblockchain-findings/issues/166
- Library page: https://bugbountylibrary.com/r/c4%3A2022-06-canto%3AH-04
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Solidity lending-market interest rate model (NoteInterest.sol)
**Root cause:** getBorrowRate() was left unimplemented and instead computes a pseudo-random value from keccak256(msg.sender) % 100, mixing it into the rate formula rather than using the intended TWAP/underlying price.
**Steps:**
1. Read `getBorrowRate(cash, borrows, reserves)` in NoteInterest.sol L92-101.
2. Observe `uint rand = uint(keccak256(abi.encodePacked(msg.sender))) % 100;`
3. Observe `ir = (100 - rand).mul(adjusterCoefficient).add(baseRatePerYear).mul(1e16)` and `newRatePerBlock = ir / blocksPerYear`.
4. Note the rate depends only on caller address and baseRatePerYear, ignoring cash/borrows/reserves.
5. Brute-force addresses until keccak256(address)%100 yields a low rand, then borrow from that address to pay a near-minimal rate.
**How found:** Code review of the interest rate model: the commented-out TWAP line and a keccak256(msg.sender) expression signaled an unimplemented placeholder left in production logic.
**Exploitation:** An attacker deploys/uses an address whose keccak256 hash mod 100 is small, obtaining a much lower borrow rate than honest users; conversely unlucky addresses overpay.
**Insight:** When auditing rate/oracle models, grep for keccak256/block.timestamp/msg.sender inside pricing math — pseudo-randomness seeded by caller-controlled values in a rate formula is a placeholder bug that lets borrowers self-select favorable rates.
