Skip to content
Request an audit

‹ All findings

Unnecessary Recomputation of Storage Pointer in MToken._startEarning

Low/InfoM^0 Minter Gateway·Three Sigma · Stablecoin framework · 8th January, 2024Codebase3S-M^0-N04

Description

In MToken._startEarning 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.