MultiHopOracle - Precision Loss Due to Consecutive Integer Division When oracleConfig.invert
is True
The _getData
function in the MultiHopOracle
contract suffers from a critical precision loss issue when oracleConfig.invert
is set to true. The repeated integer division significantly reduces precision, especially in cases involving small values or multiple hops with inversions, leading to inaccurate oracle data and unreliable price feeds.
Here's the implementation of _getData
function of MultihHopOracle
contract:
As seen above, The _getData
function has the issue consecutive integer division operations involving oracleRes
, where fractions are truncated, leading to errors. Due to repeated inversions compound this precision loss, it would make the final calculation highly inaccurate, especially for small token values or low-liquidity assets.
Key Issues:
Inversion Logic: Division by small values leads to truncation and loss of meaningful data.
Chained Operations: Multi-hop paths amplify the precision loss through repeated inversions.
Unreliable Price Feeds: Results in inaccurate pricing for micro-tokens or inverted pairs, impacting downstream protocols.
This flaw renders the oracle unreliable for small-value tokens and multi-hop scenarios, introducing risks like incorrect pricing or economic losses across the ecosystem.
This flaw causes incorrect price calculations, especially for small tokens or multi-hop paths, where repeated operations lose precision. It can lead to unreliable price feeds, opening the door to potential financial losses, mispricing, and exploitation risks like arbitrage opportunities.
Manual Review
Consider Utilizing a 3rd party like FixedPoint
and restructure calculations to perform division only at the final step of multiplication. Preferably, consider doing the division as the last step.
Likelihood: Informational/Very Low, admin should use a price feed with 18 decimals and this feed should compare a assets with a very small value and an asset with a biggest amount to have the smallest price possible. Admin wouldn't do that intentionally, but one token could collapse, and with multiple hop, it increases a bit the probability. Impact: High, complete loss of precision. Probability near 0 but not 0: deserve a Low
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.