code-423n4 / 2022-03-rolla-findings

1 stars 1 forks source link

Gas Optimizations #7

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago
  1. It's possible to optimize some structs moving values, the following changes can save storage slots:
    struct QTokensDetails {
        address underlyingAsset;
        address strikeAsset;
        address oracle;
        uint256 shortStrikePrice;
        uint256 longStrikePrice;
        uint256 expiryTime;
        bool isCall; // <- move close to oracle
    }
    struct QTokenInfo {
        address underlyingAsset;
        address strikeAsset;
        address oracle;
        uint256 strikePrice;
        uint256 expiryTime;
        bool isCall; // <- move close to oracle
    }
  1. It's possible to save gas using external and calldata.

  2. There are require messages bigger than 32 bytes. More than 32 bytes for message will incur an extra gas costs.

  3. Change the incremental logic from i++ to ++i in order to save some opcodes:

  4. Store constant math result into a constant variable.

  5. It's possible to avoid storage access a save gas using immutable keyword for the following variables:

  6. Use uint8 in _getMonth instead of uint256.

  7. Remove onlyRole modifier because it's called inside the for loop.

alcueca commented 2 years ago

Score: 100