Omniscia Moby Audit
SettlePriceFeed Code Style Findings
SettlePriceFeed Code Style Findings
SPD-01C: Loop Iterator Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | SettlePriceFeed.sol:L25 |
Description:
The linked for
loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X
).
Example:
25for (uint256 i = 0; i < _tokens.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 (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
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.
SPD-02C: Potentially Inefficient Storage Relation
Type | Severity | Location |
---|---|---|
Gas Optimization | SettlePriceFeed.sol:L11, L29 |
Description:
The settlePrices
mapping is used as a token to timestamp to settle price relation, however, the SettlePriceFeed::feedSettlePrices
function will utilize it as a one-to-many relation of a timestamp-to-tokens.
Example:
24function feedSettlePrices(address[] memory _tokens, uint256[] memory _settlePrices, uint256 _expiry) external override onlyKeeper {25 for (uint256 i = 0; i < _tokens.length; i++) {26 // @TODO: get rid of expiry requirement for test27 // require(_expiry < block.timestamp, "SettlePriceFeed: EXPIRY_NOT_PASSED");28 require(_settlePrices[i] > 0, "SettlePriceFeed: INVALID_PRICE");29 settlePrices[_tokens[i]][_expiry] = _settlePrices[i];30
31 emit FeedSettlePrice(_tokens[i], _settlePrices[i], _expiry, msg.sender);32 }33}
Recommendation:
We advise the mapping relation to be adjusted to a timestamp to token to settle price relation, permitting the SettlePriceFeed::feedSettlePrices
function to cache the settlePrices[_expiry]
lookup and utilize it for each token in a significantly efficient manner.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
The Moby team stated that it is difficult to restructure the data type, however, our recommendation is to swap the key order which should not affect how the code currently operates on the mapping
.