code-423n4 / 2022-04-mimo-findings

0 stars 0 forks source link

Gas Optimizations #140

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Issue: Should use != 0 instead of > 0 in a require statement if the variable is an unsigned integer (uint) Explanation: != 0 should be used where possible since > 0 costs more gas.

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/inception/InceptionVaultsCore.sol#L121-L126

  function deposit(uint256 _amount) public override {
    require(_amount > 0, "IV100");
    _inceptionCollateral.safeTransferFrom(msg.sender, address(this), _amount);

    _addCollateralToVault(_amount);
  }

Change _amount > 0 to _amount != 0

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/oracles/GUniLPOracle.sol#L112

    require(rA > 0 || rB > 0, "C100");

Change rA > 0 || rB > 0 to rA != 0 || rB != 0

Issue: Use of '&&' within a require function Explanation: Dividing the require into separate require messages instead of using '&&' will save gas

The two lines below contain identical code: https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L58

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/liquidityMining/v2/PARMinerV2.sol#L52

    require(boostConfig.a >= 1 && boostConfig.d > 0 && boostConfig.maxBoost >= 1, "LM004");

Change to:

    require(boostConfig.a >= 1, "LM004");
    require(boostConfig.d > 0, "LM004");
    require(boostConfig.maxBoost >= 1, "LM004");

The two lines below contain identical code: https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L70

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/liquidityMining/v2/PARMinerV2.sol#L71

    require(newBoostConfig.a >= 1 && newBoostConfig.d > 0 && newBoostConfig.maxBoost >= 1, "LM004");

Change to:

    require(newBoostConfig.a >= 1, "LM004");
    require(newBoostConfig.d > 0, "LM004");
    require(newBoostConfig.maxBoost >= 1, "LM004");

The two lines below contain identical code: https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/liquidityMining/v2/GenericMinerV2.sol#L331

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/liquidityMining/v2/PARMinerV2.sol#L426

    require(multiplier >= 1e18 && multiplier <= _boostConfig.maxBoost, "LM103");

Change to:

    require(multiplier >= 1e18, "LM103");
    require(multiplier <= _boostConfig.maxBoost, "LM103");

Issue: Variables should not be initialized to their default values Explanation: Initializing uint256 variables to their default value of zero is unnecessary and costs gas.

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/contracts/inception/InceptionVaultsCore.sol#L218

    uint256 insuranceAmount = 0;

Change uint256 insuranceAmount = 0; to uint256 insuranceAmount;