<!-- canonical: https://0xsimao.com/findings/m-0-recomputation-storage-pointer-earning -->

# Unnecessary Recomputation of Storage Pointer in MToken._startEarning

Low/Info · Three Sigma · Stablecoin framework · 8th January, 2024

Finding 3S-M^0-N04 of the M^0 Minter Gateway security review.

- Protocol: https://www.m0.org/
- Report: /reports/m-0
- Codebase: https://github.com/0xsimao/ttg/tree/a8127901fa1f24a2e821cf4d9854a1aa6ac8088c
- Source: https://cdn.sanity.io/files/qoqld077/production/1cdafafad874aba76e062ad8c216c98338c096db.pdf

---

### Description

In [MToken._startEarning](https://github.com/MZero-Labs/protocol/blob/3499f50ff3382729f3e59565b19386ba61ef8e36/src/MToken.sol#L239) function, the _balances mapping is stored in the mBalance_
variable.
MBalance storage mBalance_ = _balances[account_];
But a few lines below, instead of using mBalance_ to retrieve rawBalance,
_balances[account].rawBalance is used again spending unnecessary gas.

```solidity
function _startEarning(address account_) internal {
    emit StartedEarning(account_);
    MBalance storage mBalance_ = _balances[account_];
    if (mBalance_.isEarning) return;
    mBalance_.isEarning = true;
    // Treat the raw balance as present amount for non earner. uint240 amount_ = _balances[account_].rawBalance;
```

### Recommendation

Change the amount_ variable to:
uint240 amount_ = mBalance_.rawBalance;

### Status

Addressed in [#fc9069a](https://github.com/MZero-Labs/protocol/commit/fc9069a2c3b4e2f3de43d4c1e51d3406cc7b21e5).
