BlockchainLabsNZ / mothership-sen

GNU General Public License v3.0
0 stars 0 forks source link

Check if the distribution period is over before checking the balance to save on gas #2

Closed 0x00000002 closed 6 years ago

0x00000002 commented 6 years ago

MiniMeToken.sol, line 160:

    var previousBalanceFrom = balanceOfAt(_from, block.number);
    if (previousBalanceFrom < _amount) {
      return false;
    }

It check the balance before checking if the distribution is over, in the next few lines:

    if (isContract(controller)) {
      require(TokenController(controller).onTransfer(_from, _to, _amount));
    }

You can save a gas on reading the storage if change the order of these checks.

matt-lough commented 6 years ago

Require will refund all the gas spent if it fails so it doesn't matter what order it is called in.