Omniscia Evergon Labs Audit
CampaignCreationSkeletonNID Code Style Findings
CampaignCreationSkeletonNID Code Style Findings
CCI-01C: Generic Typographic Mistake
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | CampaignCreationSkeletonNID.sol:L234 |
Description:
The referenced line contains a typographical mistake (i.e. private variable without an underscore prefix) or generic documentational error (i.e. copy-paste) that should be corrected.
Example:
234address hanlderAddress = address(new CampaignAssetManager());Recommendation:
We advise this to be done so to enhance the legibility of the codebase.
Alleviation (b64b659786cf3c84bea52feb3a69f546ba3601f0):
The typographic mistake has been corrected addressing this exhibit.
CCI-02C: Inefficient mapping Lookups
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | CampaignCreationSkeletonNID.sol:L218, L219, L235, L236, L267 |
Description:
The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.
Example:
217// On creation218generalStorage.campaignsInfo[campaignId].state++;219generalStorage.campaignsInfo[campaignId].creator = msg.sender;220
221CampaignCreationStorage.Layout storage campaignCreationStorage = CampaignCreationStorage.layout();222
223bytes4[] memory requiredSelectors = campaignCreationStorage.requiredSelectors;224
225uint256 totalLength = dataToExecute.length;226uint256 requiredLength = requiredSelectors.length;227
228if (requiredLength + optionalSelectorsToExecute.length != totalLength || totalLength == 0) {229 revert InvalidCampaignCreationInput(requiredLength, optionalSelectorsToExecute.length, totalLength);230}231
232// Deploy InputAssetKeeper for the campaign233address keeperAddress = address(new CampaignAssetManager());234address hanlderAddress = address(new CampaignAssetManager());235generalStorage.campaignsInfo[campaignId].inputAssetKeeper = keeperAddress;236generalStorage.campaignsInfo[campaignId].rewardAssetHandler = hanlderAddress;237
238emit CampaignAssetManagersDeployed(campaignId, keeperAddress, hanlderAddress);239
240// Execute setters241uint256 i;242
243for (i; i < requiredLength; i++) {244 bytes memory input = abi.encodeWithSelector(requiredSelectors[i], campaignId, dataToExecute[i]);245 (bool success, bytes memory returnData) = address(this).call(input);246 if (!success) {247 revert RequiredSetterExecutionFailed(campaignId, requiredSelectors[i], dataToExecute[i], returnData);248 }249}250
251for (i; i < totalLength; i++) {252 bytes4 selectorToExecute = optionalSelectorsToExecute[i - requiredLength];253
254 if (!campaignCreationStorage.isOptionalSelectorSupported[selectorToExecute]) {255 revert UnsupportedOptionalSelector(selectorToExecute);256 }257
258 bytes memory input = abi.encodeWithSelector(selectorToExecute, campaignId, dataToExecute[i]);259 (bool success, bytes memory returnData) = address(this).call(input);260
261 if (!success) {262 revert OptionalSetterExecutionFailed(campaignId, selectorToExecute, dataToExecute[i], returnData);263 }264}265
266// Created267generalStorage.campaignsInfo[campaignId].state++;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 (b64b659786cf3c84bea52feb3a69f546ba3601f0):
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.
