Omniscia Moby Audit

VaultPriceFeed Code Style Findings

VaultPriceFeed Code Style Findings

VPF-01C: Deprecated Revert Pattern

Description:

The referenced revert statement will yield a textual description of the error which is an abandoned practice.

Example:

contracts/VaultPriceFeed.sol
215revert("Chainlink feeds are not being updated");

Recommendation:

We advise a custom error declaration to be introduced to the VaultPriceFeed and consequently utilized in place of the referenced message, optimizing the code's gas cost as well as legibility.

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

A ChainlinkFeedsNotUpdated error declaration has been introduced that is correspondingly emitted in the referenced revert statement, addressing this exhibit.

VPF-02C: 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/VaultPriceFeed.sol
175uint256 delta = price > ONE_USD ? (price - ONE_USD) : (ONE_USD - price);

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

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.

VPF-03C: 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/VaultPriceFeed.sol
224for (uint80 i = 0; i < priceSampleSpace; 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.

VPF-04C: Redundant Parenthesis Statements

Description:

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

Example:

contracts/VaultPriceFeed.sol
196return price * (BASIS_POINTS_DIVISOR + _spreadBasisPoints) / (BASIS_POINTS_DIVISOR);

Recommendation:

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

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

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