Omniscia Moby Audit
YieldToken Code Style Findings
YieldToken Code Style Findings
YTN-01C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | YieldToken.sol:L126, L153, L175 |
Description:
The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
174require(balances[_sender] >= _amount, "YieldToken: transfer amount exceeds balance");175balances[_sender] = balances[_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.
YTN-02C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | YieldToken.sol:L125, L126 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
125require(allowances[_sender][msg.sender] >= _amount, "YieldToken: transfer amount exceeds allowance");126uint256 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 (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
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.
YTN-03C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | YieldToken.sol:L82, L89, L198 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X
).
Example:
82for (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.