The _getData
function in the MultiHopOracle
contract combines multiple oracle price feeds to compute a price for tokens that do not have direct price feeds. However, the repeated division or multiplication during each step of the oracle path causes precision loss, which can significantly impact accuracy.
This issue is exacerbated when dealing with very large or very small intermediate oracle results (oracleRes
), especially when the invert
flag is true.
Calculating the numerator and denominator separately and performing the division only at the end is a safer approach to mitigate precision loss.
Precision Loss in Repeated Operations:
The repeated division by large numbers (oracleRes
) when invert
is true
causes the accumulated result to lose precision due to rounding errors inherent in integer division.
Conversely, repeated multiplication by small numbers (oracleRes
) amplifies rounding errors.
Accumulation of Errors:
The error grows with each additional oracle hop, leading to potentially inaccurate results, especially with longer oracle paths.
Improper Use of Fixed-Point Arithmetic:
Using division or multiplication directly in each loop iteration without maintaining precision compromises the accuracy of the final result.
Degraded Accuracy:
Results in inaccurate token prices, which can lead to incorrect decision-making by protocols or users relying on this data.
Potentially allows arbitrage opportunities or erroneous behavior in systems utilizing this oracle.
Increased Risk in Edge Cases:
High variance in oracleRes
values (very large or very small) may lead to drastic deviations in computed prices.
Separate Numerator and Denominator Calculation:
Maintain two variables for the numerator and denominator during the loop.
Compute the final result by dividing the total numerator by the total denominator at the end of the loop.
Proposed Implementation:
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.