Omniscia Teahouse Finance Audit
AssetOracle Code Style Findings
AssetOracle Code Style Findings
AOE-01C: Inefficient mapping Lookups
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | AssetOracle.sol:L32, L34 |
Description:
The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.
Example:
30constructor(address _baseAsset) {31 baseAsset = _baseAsset;32 poolInfoChain[_baseAsset] = new PoolInfo[](1);33 34 poolInfoChain[_baseAsset][0] = PoolInfo({35 pool: IUniswapV3Pool(address(1)),36 twapInterval: 0,37 decimals0: ERC20(_baseAsset).decimals(),38 decimals1: 0,39 assetIsToken0: true40 });41}Recommendation:
As the lookups internally perform an expensive keccak256 operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping in case of primitive types or holds a storage pointer to the struct contained.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
This finding was indirectly alleviated via the efforts for AOE-03C as a single mapping lookup is now performed.
AOE-02C: Loop Iterator Optimizations
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | AssetOracle.sol:L67, L99, L119, L133, L167 |
Description:
The linked for loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X).
Example:
67for (uint256 i; i < _pools.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.
AOE-03C: Redundant Initialization of Pool Information
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | AssetOracle.sol:L32 |
Description:
By default, all poolInfoChain lookups point to an "initialized" zero-entry PoolInfo array. As such, it is possible to perform a poolInfoChain[_baseAsset]::push operation without initializing an array first.
Example:
30constructor(address _baseAsset) {31 baseAsset = _baseAsset;32 poolInfoChain[_baseAsset] = new PoolInfo[](1);33 34 poolInfoChain[_baseAsset][0] = PoolInfo({35 pool: IUniswapV3Pool(address(1)),36 twapInterval: 0,37 decimals0: ERC20(_baseAsset).decimals(),38 decimals1: 0,39 assetIsToken0: true40 });41}Recommendation:
We advise this to be done so, optimizing the overall cost of the AssetOracle::constructor.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
A direct push operation is now performed, optimizing the gas cost of the statement whilst minimizing mapping lookups and thus alleviating AOE-01C as well.
AOE-04C: Redundant Parenthesis Statements
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | AssetOracle.sol:L55, L77, L79, L155 |
Description:
The referenced statements are redundantly wrapped in parenthesis' (()).
Example:
55return (poolInfoChain[_asset].length) != 0;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.
AOE-05C: Repetitive Value Literal
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | AssetOracle.sol:L177, L179, L180, L184 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
177relativePrice = sqrtPriceX96.mulDiv(sqrtPriceX96, 1 << 96);Recommendation:
We advise it to be set to a constant variable instead optimizing the legibility of the codebase.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
The referenced value literal 1 << 96 has been properly relocated to a contract-level constant declaration labelled POW_2_96, optimizing the code's legibility.
