Omniscia Moby Audit

SpotPriceFeed Code Style Findings

SpotPriceFeed Code Style Findings

SPF-01C: Ineffectual Usage of Safe Arithmetics

Description:

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

Example:

contracts/oracles/SpotPriceFeed.sol
73uint256 diffBasisPoints = _referencePrice > fastPrice ? _referencePrice - fastPrice : fastPrice - _referencePrice;

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 (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

The referenced operation is no longer present in the codebase, rendering this exhibit inapplicable.

SPF-02C: Loop Iterator Optimization

Description:

The linked for loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X).

Example:

contracts/oracles/SpotPriceFeed.sol
45for (uint256 i = 0; i < _tokens.length; i++) {

Recommendation:

We advise the increment / decrement operation to be performed in an unchecked code block as the last statement within the for loop to optimize its execution cost.

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

The referenced loop iterator's increment statement has been relocated at the end of the for loop's body and has been unwrapped in an unchecked code block, optimizing its gas cost.

SPF-03C: Redundant Parenthesis Statements

Description:

The referenced statements are redundantly wrapped in parenthesis' (()).

Example:

contracts/oracles/SpotPriceFeed.sol
66return _referencePrice * (BASIS_POINTS_DIVISOR + spreadBasisPoints) / (BASIS_POINTS_DIVISOR);

Recommendation:

We advise them to be safely omitted, increasing the legibility of the codebase.

Alleviation (b02fae335f62cc1f5f4236fb4d982ad16a32bd26):

The redundant parenthesis in the referenced statements have been safely omitted.

SPF-04C: Redundant Reservation of Memory

Description:

The SpotPriceFeed::getSpotPrice function will reserve a bool in memory that will be utilized in an if statement that immediately follows it.

Example:

contracts/oracles/SpotPriceFeed.sol
76// create a spread between the _refPrice and the fastPrice if the maxDeviationBasisPoints is exceeded
77// or if watchers have flagged an issue with the fast price
78bool hasSpread = !favorFastPrice() || diffBasisPoints > maxDeviationBasisPoints;
79
80if (hasSpread) {

Recommendation:

We advise the memory reservation to be omitted, and legibility to be introduced via comments as the compiler is not able to optimize these instances.

Alleviation (b02fae335f62cc1f5f4236fb4d982ad16a32bd26):

A local bool is no longer declared for the relevant code statement optimizing the function as advised.