Submitted by ladboy233
Loss of precision is too high when accruing interest
When interest accrues, we are calling
Note that the loss of precision is too high:
We are dividing 365 days and then divde by IRM_SCALE (which is 1e9)
Combing the fact that the IRM_SCALE is hardcoded to 1e9
Also, the time passed between two accruing is small,
Also, the underlying tokens have low decimals (6 decimals, even two decimals).
The interest accrued will be always rounded to 0.
In tests/MockERC20.sol,
The decimal is hardcoded to 18
If we change the hardcode decimal to 6 and we add the POC below in TestOmniToken.t.sol
We are now accruing the interest every two minutes
Before running the POC we import the
In OmniToken.sol
and add the console.log to log the interest
We then run the POC:
The output is:
This mean within every two minutes time elapse, the interest is round down to 0 and the accrue function is called in every borrow / withdraw / transfer, so the interest will be rounded down heavily.
Alternatively, user can keep calling accrue for every two minutes (or x minutes) to avoid paying interest.
Modify the interest, do not do multiplication before division to avoid precision loss.
Do not hardcode  IRM_SCALE and consider token decimals when accruing interest
allenjlee (BetaFinance) confirmed and commented:
For this audit, 5 reports were submitted by wardens detailing low risk and non-critical issues. The report highlighted below by T1MOH received the top score from the judge.
The following wardens also submitted reports: 0xStalin, ladboy233, bin2chen, and dirk_y.
