Oracle.getUnderlyingPrice could have wrong decimals
The Oracle.getUnderlyingPrice function divides the Chainlink price by 100, assuming all price feeds have 8 decimals. If a feed with different decimals is used, the returned price would be incorrect, potentially leading to mispriced assets.
Submitted by cmichel
The Oracle.getUnderlyingPrice function divides the chainlink price by 100.
It probably assumes that the answer for the underlying is in 8 decimals but then wants to reduce it for 6 decimals to match USDC.
However, arbitrary underlying tokens are used and the chainlink oracles can have different decimals.
Recommended Mitigation Steps
While most USD price feeds use 8 decimals, it’s better to take the on-chain reported decimals into account by doing AggregatorV3Interface(chainLinkAggregatorMap[underlying]).decimals(), see Chainlink docs.
The price should then be scaled down to 6 decimals.
atvanguard (Hubble) confirmed, but disagreed with High severity and commented:
All chainlink USD pairings are expected to have 8 decimals hence disagreeing with severity; but yes agree that asserting this check when adding a new asset is a good idea.
moose-code (judge) decreased severity to Medium and commented:
Downgrading to medium. Dividing by magic numbers (100) should clearly comment assumptions.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code hardcodes a division by 100 instead of reading the actual decimals from the Chainlink aggregator.
Impact
If a Chainlink feed with decimals other than 8 is used, the price returned by the oracle would be wrong, potentially leading to incorrect valuations and financial loss.
What the attacker needed
A Chainlink feed with non-8 decimals
The fix
The code should read the decimals from the Chainlink aggregator and scale the price accordingly, rather than using a hardcoded divisor.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract gets prices from an external service called Chainlink. The code assumes every price has exactly 8 decimal places and divides by 100 to convert to 6 decimals. If a price with a different number of decimals is used, the contract will calculate the wrong price, which could cause financial losses.