DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Hardcoded Chainlink Price Feed Decimals

Summary

The keeperProxy::_check function assumes that all Chainlink price feeds return values scaled to 8 decimals by hardcoding the adjustment with the expression price = price / 10 ** (decimals - 8). This assumption is not universally valid, as Chainlink aggregators can be configured to use a different number of decimals. Hardcoding this value can lead to inaccurate price comparisons if a price feed uses a different decimal format.

Vulnerability Details

function _check(address token, uint256 price) internal view {
(, int chainLinkPrice, , uint256 updatedAt, ) = AggregatorV2V3Interface(dataFeed[token]).latestRoundData();
require(updatedAt > block.timestamp - maxTimeWindow[token], "stale price feed");
uint256 decimals = 30 - IERC20Meta(token).decimals();
price = price / 10 ** (decimals - 8); // Chainlink price decimals is always 8.
require(
_absDiff(price, chainLinkPrice.toUint256()) * BPS / chainLinkPrice.toUint256() < priceDiffThreshold[token],
"price offset too big"
);
}
  • Issue:

  • The function incorrectly assumes that all Chainlink price feeds are scaled to 8 decimals by using the expression price / 10 ** (decimals - 8).

  • In practice, while many Chainlink aggregators do use 8 decimals, this is not guaranteed across all deployments. Different feeds might use different decimal scales.

  • This hardcoding could lead to incorrect price normalization, which in turn might cause valid price differences to exceed the threshold or vice versa, potentially leading to erroneous reverts in the _check function.

Impact

  • Inaccurate Price Validation:
    The reliance on a fixed 8-decimal format could cause the calculated price difference to be incorrect. This may lead to transactions being reverted due to "price offset too big" errors even when the price difference is within acceptable limits.

  • Limited Flexibility:
    The contract becomes less robust to changes in the underlying price feed configurations, reducing its adaptability to different Chainlink deployments.

Tools Used

manual review

Recommendations

  • Dynamic Decimal Adjustment:
    Instead of hardcoding the price feed decimals, retrieve the decimal value directly from the Chainlink aggregator using the decimals() function. For example:

+ uint8 chainlinkDecimals = AggregatorV2V3Interface(dataFeed[token]).decimals();
- price = price / 10 ** (decimals - 8); // Chainlink price decimals is always 8.
+ price = price / 10 ** (decimals - chainlinkDecimals);
Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Admin is trusted / Malicious keepers

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

Support

FAQs

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

Give us feedback!