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

1 stars 1 forks source link

Gas Optimizations #191

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas Report

[G-01] for loop gas optimisation

https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L238-L240

for(uint256 i = 0; i < modules.length; i++) {
            try IDebtIssuanceModule(modules[i]).registerToIssuanceModule(_setToken) {} catch {}
        }

Gas could be saved by:

Example:

length = modules.length;
for(uint256 i; i < length;) {
    try IDebtIssuanceModule(modules[i]).registerToIssuanceModule(_setToken) {} catch {}
        unchecked { ++i; }
}