Omniscia Mitosis Audit
Cap Code Style Findings
Cap Code Style Findings
CPA-01C: Generic Typographic Mistakes
Type | Severity | Location |
---|---|---|
Code Style | Cap.sol:L18, L19, L20, L21, L22 |
Description:
The referenced lines contain typographical mistakes (i.e. private
variable without an underscore prefix) or generic documentational errors (i.e. copy-paste) that should be corrected.
Example:
18uint256 _load;
Recommendation:
We advise them to be corrected enhancing the legibility of the codebase.
Alleviation (58e8cc66dfa900c03c47df78f5170d9960005629):
All referenced variables have been renamed accordingly, omitting their underscore prefix for the sake of legibility as they do not constitute actual private
/ internal
variables.
CPA-02C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | Cap.sol:L161 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
157uint256 subbed = calcSubbed(amount);158
159StorageV1 storage $ = _getStorageV1();160
161$._load -= subbed;
Recommendation:
Given that safe arithmetics are toggled on by default in pragma
versions of 0.8.X
, we advise the linked statement to be wrapped in an unchecked
code block thereby optimizing its execution cost.
Alleviation (58e8cc66dfa900c03c47df78f5170d9960005629):
The subtraction is safely performed in an unchecked
code block, optimizing the code's gas cost.
CPA-03C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | Cap.sol:L91, L187, L230, L263 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X
).
Example:
91for (uint256 i = 0; i < domains.length; i++) {
Recommendation:
We advise the increment / decrement operations to be performed in an unchecked
code block as the last statement within each for
loop to optimize their execution cost.
Alleviation (58e8cc66dfa900c03c47df78f5170d9960005629):
The referenced loop iterator increment statements have been relocated at the end of each respective for
loop's body and have been unwrapped in an unchecked
code block, optimizing their gas cost.
CPA-04C: Redundant Initialization of Values
Type | Severity | Location |
---|---|---|
Gas Optimization | Cap.sol:L49-L52 |
Description:
Unless the Cap
contract acts as an upgrade, initializing values to 0
is redundant as all values contain that value by default.
Example:
46function initialize(address owner, address hook, address ism) public initializer {47 _MailboxClient_initialize(hook, ism, owner);48
49 StorageV1 storage $ = _getStorageV1();50 $._epoch[localDomain] = 0;51 $._load = 0;52 $._ready = false;53}
Recommendation:
We advise the referenced statements to be omitted if the contract is meant to be freshly deployed, optimizing its gas cost.
Alleviation (58e8cc66dfa900c03c47df78f5170d9960005629):
The redundant initializations of the _load
and _ready
variables have been safely omitted, optimizing the code's gas cost.
CPA-05C: Redundant Repetitive Invocation of Getter Function
Type | Severity | Location |
---|---|---|
Gas Optimization | Cap.sol:L92 |
Description:
The Cap::_getStorageV1
function will be invoked domains.length
times within the Cap::remoteEpochs
function redundantly.
Example:
91for (uint256 i = 0; i < domains.length; i++) {92 remoteEpochs_[i] = _getStorageV1()._epoch[domains[i]];93}
Recommendation:
We advise its value to be cached outside the for
loop, optimizing the function's gas cost.
Alleviation (58e8cc66dfa900c03c47df78f5170d9960005629):
The CapStorageV1::_getStorageV1
function result is now properly cached outside the for
loop thereby optimizing its gas cost.