Omniscia Ultra Yield Audit

UltraVaultRateProvider Code Style Findings

UltraVaultRateProvider Code Style Findings

UVR-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificUltraVaultRateProvider.sol:
I-1: L179
I-2: L181

Description:

The linked mathematical operation is guaranteed to be performed safely by logical inference, such as surrounding conditionals evaluated in require checks or if-else constructs.

Example:

src/oracles/UltraVaultRateProvider.sol
178} else if (fromDecimals < toDecimals) {
179 return amount * 10 ** (toDecimals - fromDecimals);
180} else {
181 return amount / 10 ** (fromDecimals - toDecimals);
182}

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

Both decimal difference calculations have been wrapped in an unchecked code block, optimizing the code's gas cost.

UVR-02C: Inexecutable Code

Description:

The first case of the referenced if-else-if conditional chain will never be executed as the UltraVaultRateProvider::_convertDecimals function is solely invoked whenever the decimals differ between them.

Example:

src/oracles/UltraVaultRateProvider.sol
170/// @dev Helps with decimals accounting
171function _convertDecimals(
172 uint256 amount,
173 uint8 fromDecimals,
174 uint8 toDecimals
175) internal pure returns (uint256) {
176 if (fromDecimals == toDecimals) {
177 return amount;
178 } else if (fromDecimals < toDecimals) {
179 return amount * 10 ** (toDecimals - fromDecimals);
180 } else {
181 return amount / 10 ** (fromDecimals - toDecimals);
182 }
183}

Recommendation:

We advise the code to be optimized based on this premise, reducing its gas cost.

Alleviation (28f27853965de07fb79f4f2b5fed696d35120032):

The code was updated to instead invoke the UltraVaultRateProvider::_convertDecimals function in the decimal equality case as well, addressing this exhibit indirectly.

UVR-03C: Optimization of Yielded Statement

Description:

The UltraVaultRateProvider::isSupported function will evaluate whether data.isPegged is true, yield true in such a case, and yield data.rateProvider != address(0) in any other.

Example:

src/oracles/UltraVaultRateProvider.sol
82if (data.isPegged) {
83 return true;
84}
85return data.rateProvider != address(0);

Recommendation:

We advise the code to directly yield data.isPegged || data.rateProvider != address(0), optimizing the code's gas cost.

Alleviation (28f27853965de07fb79f4f2b5fed696d35120032):

The code was updated to yield an optimized conditional statement, addressing this exhibit.

UVR-04C: Repetitive Invocations of Storage Offset

TypeSeverityLocation
Gas OptimizationUltraVaultRateProvider.sol:
I-1: L91, L100
I-2: L115, L116
I-3: L122, L123, L126
I-4: L132, L133
I-5: L150, L151

Description:

The referenced statement pairs will end up invoking the UltraVaultRateProvider::_getStorage function multiple times within the same code block redundantly.

Example:

src/oracles/UltraVaultRateProvider.sol
121function updateRateProvider(address asset, address rateProvider) external onlyOwner {
122 require(asset != baseAsset(), CannotUpdateBaseAsset());
123 require(!supportedAssets(asset).isPegged, AssetNotSupported());
124 require(rateProvider != address(0), InvalidRateProvider());
125
126 _getStorage().supportedAssets[asset].rateProvider = rateProvider;
127 emit RateProviderUpdated(address(asset), rateProvider);
128}

Recommendation:

We advise the UltraVaultRateProvider::_getStorage function to be invoked once, cached to a local variable, and then re-used to optimize the code's gas cost.

Alleviation (28f2785396):

The optimization was solely applied to the example instance, rendering instances 1, 3, 4, and 5 to remain unaddressed.

Alleviation (2d9651dbd7):

All remaining instances have been optimized per our recommendation, addressing this exhibit in full.