Omniscia Teahouse Finance Audit

TeaVaultV3PairOracle Code Style Findings

TeaVaultV3PairOracle Code Style Findings

TVP-01C: Inefficient Square Root Implementation

Description:

The referenced square root implementation is outdated and relies on Uniswap V2 code instead of the latest standards.

Example:

contracts/oracle/TeaVaultV3PairOracle.sol
185// source: v2-core/contracts/libraries/Math.sol
186// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
187function _sqrt(uint y) internal pure returns (uint z) {
188 if (y > 3) {
189 z = y;
190 uint x = y / 2 + 1;
191 while (x < z) {
192 z = x;
193 x = (y / x + x) / 2;
194 }
195 } else if (y != 0) {
196 z = 1;
197 }
198}

Recommendation:

We advise an implementation such as the one by OpenZeppelin to be utilized, significantly optimizing the gas cost involved in calculating a square root.

Alleviation (302b96f324a88038a0872015466cd43783c14543):

The inefficient implementation has been safely omitted from the codebase, making use of the OpenZeppelin Math::sqrt function instead and thus optimizing the codebase as advised.

TVP-02C: 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/oracle/TeaVaultV3PairOracle.sol
83for (uint256 i; i < _assets.length; i = i + 1) {

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 (302b96f324a88038a0872015466cd43783c14543):

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.

TVP-03C: Redundant Parenthesis Statements

Description:

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

Example:

contracts/oracle/TeaVaultV3PairOracle.sol
12610 ** (_teaVaultV3PairInfo.decimals)

Recommendation:

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

Alleviation (302b96f324a88038a0872015466cd43783c14543):

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

TVP-04C: Redundant Type Cast Operations

Description:

The referenced type casts are redundant as the value being cast is already of the desired type.

Example:

contracts/oracle/TeaVaultV3PairOracle.sol
141if (address(_teaVaultV3PairInfo.token0) == address(0)) revert AssetNotEnabled();

Recommendation:

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

Alleviation (302b96f324a88038a0872015466cd43783c14543):

All referenced redundant casting operations have been safely omitted, optimizing the code style of the codebase.