Omniscia Moby Audit

BaseToken Code Style Findings

BaseToken Code Style Findings

BTN-01C: Ineffectual Usage of Safe Arithmetics

Description:

The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

contracts/tokens/BaseToken.sol
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

Description:

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

Example:

contracts/tokens/BaseToken.sol
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

Description:

The linked for loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X).

Example:

contracts/tokens/BaseToken.sol
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.