Summary
The judgment in the LibChainlinkOracle::getTokenPrice()
function is wrong, resulting in the wrong function being called
Vulnerability Details
* @dev Returns the TOKEN/USD price with the option of using a TWA lookback.
* Use `lookback = 0` for the instantaneous price. `lookback > 0` for a TWAP.
* Return value has 6 decimal precision.
* Returns 0 if `priceAggregatorAddress` is broken or frozen.
**/
function getTokenPrice(
address priceAggregatorAddress,
uint256 maxTimeout,
uint256 lookback
) internal view returns (uint256 price) {
return
@> lookback > 0
@> ? getPrice(priceAggregatorAddress, maxTimeout)
@> : getTwap(priceAggregatorAddress, maxTimeout, lookback);
}
The binary judgment in the return part did not work as expected, resulting in an error in function execution.
Impact
The judgment in the LibChainlinkOracle::getTokenPrice()
function is wrong, resulting in the wrong function being called
Tools Used
Manual Review
Recommendations
We may consider the following modifications
function getTokenPrice(
address priceAggregatorAddress,
uint256 maxTimeout,
uint256 lookback
) internal view returns (uint256 price) {
return
- lookback > 0
+ lookback == 0
? getPrice(priceAggregatorAddress, maxTimeout)
: getTwap(priceAggregatorAddress, maxTimeout, lookback);
}