MixOracle is broken due to hardcoded position
tjonair Follow with xiaoming90
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/540
Found by
tjonair, xiaoming90
Summary
No response
Root Cause
No response
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
Following is the information about MixOracle extracted from the Debita's documentation for context:
To integrate a token without a direct oracle, a mix oracle is utilized. This oracle uses a TWAP oracle to compute the conversion rate between Token A and Token B. Token B must be supported on PYTH oracle, and the pricing pool should have substantial liquidity to ensure security.
This approach enables us to obtain the USD valuation of tokens that would otherwise would be impossible.
The following attempts to walk through how the MixOracle is used for reader understanding before jumping into the issue.
WFTM token is supported on Pyth Oracle via the WFTM/USD price feed, but there is no oracle in Fantom Chain that supports EQUAL token. Thus, the MixOracle can be leveraged to provide the price of the EQUAL token even though no EQUAL price oracle exists. A pricing pool with substantial liquidity that consists of EQUAL token can be used here.
Let's use the WFTM/EQUAL pool (EQUALPAIR = 0x3d6c56f6855b7Cc746fb80848755B0a9c3770122) from Equalizer within the test script for illustration.
File: OracleTarotUSDCEQUAL.t.sol
136: function testUSDCPrincipleAndEqualCollateral() public {
137: createOffers(USDC, EQUAL);
138: DebitaMixOracle.setAttachedTarotPriceOracle(EQUALPAIR);
139: vm.warp(block.timestamp + 1201);
140: int priceEqual = DebitaMixOracle.getThePrice(EQUAL);
The token0 and token1 of the WFTM/EQUAL pool are as follows as retrieved from the FTMscan:
-
token0 = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83 = WFTM
-
token1 = 0x3Fd3A0c85B70754eFc07aC9Ac0cbBDCe664865A6 = EQUAL
In this case, the price returned from the pool will be computed by EQUAL divided by WFTM. So, the price of EQUAL per WFTM is provided by the pool.
Equalizer Pool's getPriceCumulativeCurrent = reserve1/reserve0 = token1/token0 = EQUAL/WFTM
When configuring the MixOracle to support EQUAL token, the setAttachedTarotPriceOracle will be executed, and the pool address (0x3d6c56f6855b7Cc746fb80848755B0a9c3770122) will be passing in via the uniswapV2Pair parameter. In this case, the MixOracle will return the price of the EQUAL (token1) token when the MixOracle.getThePrice(EQUAL) function is executed within another part of the protocol.
AttachedPricedToken[token1] = token0;
AttachedPricedToken[EQUAL] = WFTM;
File: MixOracle.sol
72: function setAttachedTarotPriceOracle(address uniswapV2Pair) public {
73: require(multisig == msg.sender, "Only multisig can set price feeds");
74:
75: require(
76: AttachedUniswapPair[uniswapV2Pair] == address(0),
77: "Uniswap pair already set"
78: );
79:
80: address token0 = IUniswapV2Pair(uniswapV2Pair).token0();
81: address token1 = IUniswapV2Pair(uniswapV2Pair).token1();
82: require(
83: AttachedTarotOracle[token1] == address(0),
84: "Price feed already set"
85: );
86: DebitaProxyContract tarotOracle = new DebitaProxyContract(
87: tarotOracleImplementation
88: );
89: ITarotOracle oracle = ITarotOracle(address(tarotOracle));
90: oracle.initialize(uniswapV2Pair);
91: AttachedUniswapPair[token1] = uniswapV2Pair;
92: AttachedTarotOracle[token1] = address(tarotOracle);
93: AttachedPricedToken[token1] = token0;
94: isFeedAvailable[uniswapV2Pair] = true;
95: }
The issue is that the MixOracle relies on the position of token0 and token1 in the pool that cannot be controlled. Within the pool (Equalizer or Uniswap Pool), the position of token0 and token1 is pre-determined and sorted by the token's address (smaller address will always be token0)
However, the position of the token in the setAttachedTarotPriceOracle function is hardcoded. For instance, the keys of the AttachedUniswapPair, AttachedTarotOracle, AttachedPricedToken mapping are all hardcoded to token1.
Assume that the protocol wants to create another MixOracle to support another token called $Token_X$ that does not have any oracle on Fantom. However, this token to be supported is located in the position of token0 instead of token1 in the pool. Thus, because the MixOracle is hardcoded to always use only token1, there is no way to support this $Token_X$ even though a high liquidity pool that consists of $Token_X$ exists on Fantom.
The MixOracle is supposed to work in this scenario, but due to hardcoded position, it cannot supported. Thus, the MixOracle is broken in this scenario.
Impact
Medium. Breaks core contract functionality. Oracle is a core feature in a protocol.
PoC
No response
Mitigation
Consider not hardcoding the position (token1) as the key of the mapping used within MixOracle. Instead, allow the deployer to specify which token (token0 or token1) the MixOracle is supposed to support.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/83b5cf41c6100a4b31be2779bb66e7c41ea957a6
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Debita Finance V3. Sherlock made it public on 13 December 2024. Found in the 627 audit contest (finding M-15), also found by 1 other warden.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.