Omniscia Bluejay Finance Audit
PriceFeedOracle Code Style Findings
PriceFeedOracle Code Style Findings
PFO-01C: Inefficient Loop Limit Evaluation
Type | Severity | Location |
---|---|---|
Gas Optimization | PriceFeedOracle.sol:L28 |
Description:
The linked for
loop reads the value of length
from storage on each iteration that it validates the limit condition on.
Example:
packages/contracts/contracts/PriceFeedOracle.sol
25function getPrice() public view override returns (uint256 price) {26 uint256 numerator = WAD;27 uint256 denominator = 1;28 for (uint256 i = 0; i < path.length; i++) {29 Feed memory feed = path[i];30 (, int256 feedPrice, , , ) = feed.aggregator.latestRoundData();31 uint256 scaledPrice = uint256(32 scalePrice(feedPrice, feed.decimals, decimals)33 );34 if (feed.invert) {35 numerator *= WAD;36 denominator *= scaledPrice;37 } else {38 numerator *= scaledPrice;39 denominator *= WAD;40 }41 }42 price = numerator / denominator;43}
Recommendation:
We advise the path.length
value to be cached to a local variable instead that is consequently utilized for the loop limit to significantly reduce the function's gas cost.
Alleviation:
The loop limit is now cached to a local variable that is consequently utilized optimizing the codebase.
PFO-02C: Inexistent Visibility Specifiers
Type | Severity | Location |
---|---|---|
Code Style | PriceFeedOracle.sol:L7-L8 |
Description:
The linked variables have no visibility specifiers explicitly set.
Example:
packages/contracts/contracts/PriceFeedOracle.sol
7uint8 constant decimals = 18;8uint256 constant WAD = 10**decimals;
Recommendation:
We advise them to be set to avoid potential compilation discrepancies in the future as the current behaviour is for the compiler to assign one automatically which may deviate between pragma
versions.
Alleviation:
Both variables have been set as private
thereby alleviating this exhibit.