code-423n4 / 2023-01-ondo-findings

0 stars 0 forks source link

`borrowRatePerBlock()` and `supplyRatePerBlock()` may not return correct values. #343

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-01-ondo/blob/main/contracts/lending/tokens/cToken/CTokenModified.sol#L254 https://github.com/code-423n4/2023-01-ondo/blob/main/contracts/lending/tokens/cToken/CTokenModified.sol#L267

Vulnerability details

Impact

borrowRatePerBlock() may return an incorrect value, as totalBorrows may not be up to date : that is, if accrueInterest() was called N >= 1 blocks before the call to borrowRatePerBlock().

Rated as medium as external dApps may call borrowRatePerBlock() and have built-in logic to borrow depending on the value of the returned interest rate.

Proof of Concept

This would not have happened if the interest had been updated in borrowRatePerBlock.

Tools Used

Manual review

Recommended Mitigation Steps

Add a accrueInterest() call at the start of borrowRatePerBlock() and supplyRatePerBlock()

trust1995 commented 1 year ago

We can see that Compound doesn't do it either: https://github.com/compound-finance/compound-protocol/blob/a3214f67b73310d547e00fc578e8355911c9d376/contracts/CToken.sol Will treat as more of a suggestion.

c4-judge commented 1 year ago

Duplicate of https://github.com/code-423n4/2023-01-ondo-findings/issues/341

c4-judge commented 1 year ago

trust1995 marked the issue as grade-b

c4-judge commented 1 year ago

trust1995 marked the issue as grade-a