code-423n4 / 2022-06-notional-coop-findings

1 stars 1 forks source link

Gas Optimizations #130

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
  1. Public function visibility can be made external a. Summary: Functions should have the strictest visibility possible. Public functions may lead to more gas usage by forcing the copy of their parameters to memory from calldata. b. Details: If a function is never called from the contract it should be marked as external. This will save gas. c. Github Permalinks: https://github.com/code-423n4/2022-06-notional-coop/tree/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L210-L212 d. Mitigation: Consider changing visibility from public to external.

  2. Gas optimization by not initialising loop indices a. Summary: Loop indices need not be initialised to 0. b. Details: Loop indices are 0 valued by default and there is no need to explicitly initialise them again to 0. This saves gas. c. Github Permalinks:https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L238 https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L254 https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L393 https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L605 https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L618

d. Mitigation: Remove explicit initialization to 0 for loop indices.

  1. Redundant variable initialization a. Summary: Initialization for some variables is not needed. b. Details: b1) The default value of address is address(0) thus the initialization to address(0) is not needed and will save gas. b2) The default value of uint is 0 thus the initialization to 0 is not needed and will save gas. c. Github Permalinks: https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L48 https://github.com/code-423n4/2022-06-notional-coop/blob/main/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L519 d. Mitigation: Remove the initialization.