DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: high
Valid

The judgment in the `LibChainlinkOracle::getTokenPrice()` function is wrong, resulting in the wrong function being called

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);
}
// if lookback > 0 -> getPrice(priceAggregatorAddress, maxTimeout)
// else -> 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);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

getTokenPrice never gives TWAP

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.