Omniscia Moby Audit
BaseToken Code Style Findings
BaseToken Code Style Findings
BTN-01C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | BaseToken.sol:L129, L156, L178 |
Description:
The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
128require(allowances[_sender][msg.sender] >= _amount, "BaseToken: transfer amount exceeds allowance");129uint256 nextAllowance = allowances[_sender][msg.sender] - _amount;
Recommendation:
Given that safe arithmetics are toggled on by default in pragma
versions of 0.8.X
, we advise the linked statements to be wrapped in unchecked
code blocks thereby optimizing their execution cost.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
All referenced arithmetic operations have been wrapped in an unchecked
code block safely, optimizing their gas cost whilst retaining their security guarantees via preceding conditionals.
BTN-02C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | BaseToken.sol:L128, L129 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
128require(allowances[_sender][msg.sender] >= _amount, "BaseToken: transfer amount exceeds allowance");129uint256 nextAllowance = allowances[_sender][msg.sender] - _amount;
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.
Alleviation (b02fae335f62cc1f5f4236fb4d982ad16a32bd26):
The referenced lookups have been optimized by reading the primitive value to a local variable and consequently re-using it.
BTN-03C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | BaseToken.sol:L81, L88, L201 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X
).
Example:
81for (uint256 i = 0; i < yieldTrackers.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 (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
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.