Omniscia Tesseract Audit

ConfigManager Code Style Findings

ConfigManager Code Style Findings

CMR-01C: Inefficient Loop Iteration

Description:

The referenced for loops can be merged into a single one yet are presently separate.

Example:

contracts/ConfigManager.sol
221function whitelistSubstrates(uint256 marketId, bytes32[] calldata substrates) external onlyRole(DEFAULT_ADMIN_ROLE) {
222 if (substrates.length == 0) revert EmptyArray();
223 for (uint256 i; i < substrates.length; i++) {
224 _whitelistedSubstrates[marketId].add(substrates[i]);
225 }
226 _whitelistedMarketIds.add(marketId);
227 for (uint256 i; i < substrates.length; i++) {
228 emit SubstrateWhitelisted(marketId, substrates[i]);
229 }
230}

Recommendation:

We advise them to be merged, optimizing the code's gas cost significantly.

Alleviation (fdf0694b5c38834fa5a20cb2765766924d34f5d4):

The referenced for loops have been merged into a single one, addressing this exhibit.

CMR-02C: Inefficient mapping Lookups

TypeSeverityLocation
Gas OptimizationConfigManager.sol:
I-1: L192, L193
I-2: L213, L214
I-3: L224
I-4: L235, L238

Description:

The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.

Example:

contracts/ConfigManager.sol
192_whitelistedBalanceFuses[marketId].remove(fuse);
193if (_whitelistedBalanceFuses[marketId].length() == 0 && _whitelistedSubstrates[marketId].length() == 0) {

Recommendation:

As the lookups internally perform an expensive keccak256 operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping in case of primitive types or holds a storage pointer to the struct contained.

As the compiler's optimizations may take care of these caching operations automatically at-times, we advise the optimization to be selectively applied, tested, and then fully adopted to ensure that the proposed caching model indeed leads to a reduction in gas costs.

Alleviation (fdf0694b5c38834fa5a20cb2765766924d34f5d4):

All referenced inefficient mapping lookups have been optimized to the greatest extent possible, significantly reducing the gas cost of the functions the statements were located in.

CMR-03C: Suboptimal Struct Declaration Style

Description:

The linked declaration style of a struct is using index-based argument initialization.

Example:

contracts/ConfigManager.sol
152_callbackConfigs[key] = CallbackConfig(handler, sender, sig);

Recommendation:

We advise the key-value declaration format to be utilized instead, greatly increasing the legibility of the codebase.

Alleviation (fdf0694b5c38834fa5a20cb2765766924d34f5d4):

The key-value declaration style is now properly in use within the referenced struct declaration, addressing this exhibit in full.