Omniscia Tangible Audit

GoldOracleTangibleV2 Code Style Findings

GoldOracleTangibleV2 Code Style Findings

GOT-01C: Generic Typographic Mistake

Description:

The referenced line contains a typographical mistake (i.e. private variable without an underscore prefix) or generic documentational error (i.e. copy-paste) that should be corrected.

Example:

contracts/priceOracles/GoldOracleTangibleV2.sol
85* @return Returns USD price per gram, premium fee, and tokization cost.

Recommendation:

We advise this to be done so to enhance the legibility of the codebase.

Alleviation (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):

The typographic mistake of the documentation has been corrected.

GOT-02C: Inefficient mapping Lookups

Description:

The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.

Example:

contracts/priceOracles/GoldOracleTangibleV2.sol
154function decrementSellStock(uint256 _fingerprint) external override onlyFactory {
155 require(goldBars[_fingerprint].weSellAtStock != 0, "Already zero sell");
156 unchecked {
157 goldBars[_fingerprint].weSellAtStock--;
158 }
159}

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 (1f394a00cc2ed1dc2020a9c07f982cff9029077d):

All referenced inefficient mapping lookups have been optimized to the greatest extent possible, significantly reducing the gas cost of the functions the statements were located in.

GOT-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/priceOracles/GoldOracleTangibleV2.sol
331for (uint256 i; i < length; 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 (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):

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.

GOT-04C: Redundant Parenthesis Statements

Description:

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

Example:

contracts/priceOracles/GoldOracleTangibleV2.sol
97return (priceForGrams);

Recommendation:

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

Alleviation (1f394a00cc2ed1dc2020a9c07f982cff9029077d):

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

GOT-05C: Redundant Ternary Operator

Description:

The evaluation of the referenced ternary operator is redundant as it will yield false in case its conditional is true and true if its conditional is false.

Example:

contracts/priceOracles/GoldOracleTangibleV2.sol
219bool useFingerprint = _fingerprints.length == 0 ? false : true;

Recommendation:

We advise the ternary operator to be replaced by the conditional it evaluates in its negated form, optimizing its gas cost.

Alleviation (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):

The redundant ternary operator was replaced by a direct conversion of the conditional it used to evaluate. To note, the negation (!) can be assimilated in the comparison (==) to increase the legibility of the codebase (i.e. a != b is better than !(a == b)).

Despite of this, we consider the original recommendation applied and thus this exhibit as addressed.