Omniscia Euler Finance Audit

RedstoneCoreOracle Code Style Findings

RedstoneCoreOracle Code Style Findings

RCO-01C: Ineffectual Usage of Safe Arithmetics

Description:

The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

src/adapter/redstone/RedstoneCoreOracle.sol
57/// @notice Ingest a signed update message and cache it on the contract.
58/// @dev Validation logic inherited from PrimaryProdDataServiceConsumerBase.
59function updatePrice() external {
60 // Use the cache if the previous price is still fresh.
61 if (block.timestamp < lastUpdatedAt + RedstoneDefaultsLib.DEFAULT_MAX_DATA_TIMESTAMP_DELAY_SECONDS) return;
62
63 uint256 price = getOracleNumericValueFromTxMsg(feedId);
64 if (price > type(uint208).max) revert Errors.PriceOracle_Overflow();
65 lastPrice = uint208(price);
66 lastUpdatedAt = uint48(block.timestamp);
67}
68
69/// @notice Get the quote from the Redstone feed.
70/// @param inAmount The amount of `base` to convert.
71/// @param _base The token that is being priced.
72/// @param _quote The token that is the unit of account.
73/// @return The converted amount using the Redstone feed.
74function _getQuote(uint256 inAmount, address _base, address _quote) internal view override returns (uint256) {
75 bool inverse = ScaleUtils.getDirectionOrRevert(_base, base, _quote, quote);
76
77 uint256 staleness = block.timestamp - lastUpdatedAt;

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statement to be wrapped in an unchecked code block thereby optimizing its execution cost.

Alleviation:

The Euler Finance team considered the optimization outlined by the exhibit and opted to retain the current implementation in place.