Omniscia Ultra Yield Audit

UltraVaultOracle Code Style Findings

UltraVaultOracle Code Style Findings

UVO-01C: Calculation Simplification

Description:

The referenced calculation can be simplified by merging exponentials into a single multiplication or division depending on the outcome.

Example:

src/oracles/UltraVaultOracle.sol
233return inAmount * price * (10 ** quoteDecimals) / (10 ** (baseDecimals + 18));

Recommendation:

We advise the powers to be summed and to perform a single multiplication or division with the relevant power of 10.

Alleviation (28f27853965de07fb79f4f2b5fed696d35120032):

The code was updated per our recommendation albeit ensuring that the denominatorDecimals are always greater than the nominatorDecimals, simplifying the calculation further.

UVO-02C: Ineffective Boolean Flag Management

Description:

The increase boolean is meant to indicate whether price.price <= price.targetPrice is true.

Example:

src/oracles/UltraVaultOracle.sol
195bool increase;
196uint256 diff;
197
198if (price.price <= price.targetPrice) {
199 increase = true;
200 diff = price.targetPrice - price.price;
201} else {
202 diff = price.price - price.targetPrice;
203}

Recommendation:

We advise the increase flag to be assigned to the price.price <= price.targetPrice evaluation on its declaration and the if conditional to utilize the increase flag directly, optimizing the code's gas cost.

Alleviation (28f27853965de07fb79f4f2b5fed696d35120032):

The increase flag's assignment has been revised as advised, optimizing the code's gas cost.

UVO-03C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificUltraVaultOracle.sol:
I-1: L200
I-2: L202

Description:

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

Example:

src/oracles/UltraVaultOracle.sol
198if (price.price <= price.targetPrice) {
199 increase = true;
200 diff = price.targetPrice - price.price;
201} else {
202 diff = price.price - price.targetPrice;
203}

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 (28f27853965de07fb79f4f2b5fed696d35120032):

The referenced price delta calculations are now wrapped in an unchecked code block, optimizing the code's gas cost.

UVO-04C: Redundant Precision Concept

Description:

The DECIMAL_PRECISION concept employed by the UltraVaultOracle::_getCurrentPrice function is ineffective as the extrapolation of the timeLeft is immediately offset after use, thereby resulting in no increase of the calculation's accuracy.

Example:

src/oracles/UltraVaultOracle.sol
207uint256 change = diff - diff * timeLeft * DECIMAL_PRECISION / timeFull / DECIMAL_PRECISION;

Recommendation:

We advise the concept to be entirely omitted, optimizing the code's gas cost.

While precision errors exist, they are detailed in a separate exhibit.

Alleviation (28f27853965de07fb79f4f2b5fed696d35120032):

The ineffective precision concept has been omitted from the code, optimizing its legibility and gas cost.

UVO-05C: Repetitive Value Literal

Description:

The linked value literal is repeated across the codebase multiple times.

Example:

src/oracles/UltraVaultOracle.sol
233return inAmount * price * (10 ** quoteDecimals) / (10 ** (baseDecimals + 18));

Recommendation:

We advise it to be set to a constant variable instead, optimizing the legibility of the codebase.

In case the constant has already been declared, we advise it to be properly re-used across the code.

Alleviation (28f27853965de07fb79f4f2b5fed696d35120032):

The referenced value literal 18 has been properly relocated to a contract-level constant declaration labelled PRICE_FEED_DECIMALS, optimizing the code's legibility.