You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Incorrect Decimal Handling in MixOracle Price Calculation
Summary
The incorrect decimal handling in MixOracle.sol will cause significant price discrepancies as the contract fails to properly scale token decimals when calculating prices from Tarot Oracle TWAP and Pyth oracle feeds, which leads to severely undervalued or overvalued asset prices.
Root Cause
In MixOracle.sol#L40-L95, the getThePrice function incorrectly handles decimals in multiple places:
When calculating amountOfAttached:
int amountOfAttached =int(
(((2**112)) * (10** decimalsToken1)) / twapPrice112x112
);
The different decimal places between token0 and token1
The additional scaling applied by Tarot Oracle (10^12)
Internal pre-conditions
No response
External pre-conditions
Tarot Oracle needs to return a TWAP price for a token pair with different decimals (e.g., WETH/USDT with 18/6 decimals)
The price ratio between tokens needs to be significant enough to make the decimal scaling error apparent
The Pyth oracle price feed for the attached token needs to be active and returning prices
Attack Path
No response
Impact
Medium. The incorrect decimal handling leads to wrong price calculations that could significantly impact protocol operations relying on these price feeds.
Doesn't properly handle the decimal difference between token0 and token1
Results in a significantly wrong price due to improper scaling
Mitigation
Modify the price calculation in getThePrice to properly handle decimals
The text was updated successfully, but these errors were encountered:
sherlock-admin3
changed the title
Little Spruce Seagull - Incorrect Decimal Handling in MixOracle Price Calculation
endless-c - Incorrect Decimal Handling in MixOracle Price Calculation
Dec 12, 2024
endless-c
Medium
Incorrect Decimal Handling in MixOracle Price Calculation
Summary
The incorrect decimal handling in
MixOracle.sol
will cause significant price discrepancies as the contract fails to properly scale token decimals when calculating prices from Tarot Oracle TWAP and Pyth oracle feeds, which leads to severely undervalued or overvalued asset prices.Root Cause
In MixOracle.sol#L40-L95, the
getThePrice
function incorrectly handles decimals in multiple places:amountOfAttached
:The calculation fails to properly account for:
Internal pre-conditions
No response
External pre-conditions
Attack Path
No response
Impact
Medium. The incorrect decimal handling leads to wrong price calculations that could significantly impact protocol operations relying on these price feeds.
PoC
Consider a WETH/USDT pair where:
As demonstrated in the Python POC:
This shows that the current implementation:
Mitigation
Modify the price calculation in
getThePrice
to properly handle decimalsThe text was updated successfully, but these errors were encountered: