sherlock-audit / 2023-10-mzero-judging

3 stars 2 forks source link

lemonmon - The functions `MinterGateway._rate()` and `MToken._rate()` may return a rate value of 0 which may cause issues #48

Closed sherlock-admin3 closed 7 months ago

sherlock-admin3 commented 7 months ago

lemonmon

medium

The functions MinterGateway._rate() and MToken._rate() may return a rate value of 0 which may cause issues

Summary

There are issues with MinterGateway._rate() and MToken._rate() where the returned rate may be 0, which may cause a number of further issues due to wrong calculations that are based on the rate.

Vulnerability Detail

The functions MinterGateway._rate() and MToken._rate() may return 0 (line 986 in MinterGateway.sol and line 455 MToken.sol), if the staticcall to the rate model fails which is supposed to fetch the rate.

As a result when ContinuousIndexing.updateIndex() is called (either for the MToken or for the MinterGateway contract, since both are inheriting from the ContinuousIndexing contract), the rate_ may be 0 (line 39 ContinuousIndexing.sol) since it fetches it's value from MinterGateway._rate(), which is then assigned to _latestRate state variable on line 45 in ContinuousIndexing.sol.

Both MToken.currentIndex() and MinterGateway.currentIndex() may then calculate a wrong current index value since both functions are relying on _latestRate which may be 0 as shown above. Also the state variable ContinuousIndexing.latestIndex will have a wrong value assigned (line 44 ContinuousIndexing.sol).

Impact

Wherever the protocol calls the currentIndex() method and wherever the state var ContinuousIndexing.latestIndex is used, there may be an issue:

In summary, a number of issues may arise if the rate fetched by MinterGateway._rate() or MToken._rate() would be 0 and not reverted.

Code Snippet

https://github.com/sherlock-audit/2023-10-mzero/blob/main/protocol/src/MinterGateway.sol#L981-L987

https://github.com/sherlock-audit/2023-10-mzero/blob/main/protocol/src/MToken.sol#L450-L456

https://github.com/sherlock-audit/2023-10-mzero/blob/main/protocol/src/MinterGateway.sol#L683-L698

https://github.com/sherlock-audit/2023-10-mzero/blob/main/protocol/src/MToken.sol#L158-L173

Tool used

Manual Review

Recommendation

Consider handling the case where MinterGateway._rate() or MToken._rate() return 0 as the rate value. For example by reverting or by using the latest rate that was fetched before, if the latest rate is not 0 as well.