Setting stable price in oracle can result in arbitrate opportunities and significant bad debt if the stable depegs
The oracle allows governance to manually set a stablecoin's price, which can become inaccurate if the stablecoin depegs. An attacker could buy the depegged stablecoin cheaply, deposit it as collateral at the inflated manual price, and open positions that create bad debt for the protocol.
Bauchibred Follow with dirk_y, kutugu and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/69
Found by
Bauchibred, dirk_y, kutugu, lil.eth, minhtrng, n1punp, oakcobalt, p12473, rogue-lion-0619
Summary
In Oracle.sol there is the ability for governance to manually specify the price of an underlying asset (designed for stable coins). However, when the given stable coin depegs there is now the opportunity for arbitrage and even the possibility that Hubble becomes insolvent.
Vulnerability Detail
Firstly, it is worth noting that stable coins depeg relatively frequently. For the sake of argument let's say that a stable coin is pegged to the US Dollar and the price is set by governance to 1000000 (to 6 decimal places) in the oracle.
Probably the most important place in the protocol where the price of an asset is used is in MarginAccount in the weightedAndSpotCollateral method. This method is used under the hood to check whether a user can withdraw from the margin account and whether the user is able to be liquidated. It is also used in the AMM logic but I'll focus on the margin account case as I think that is the easiest to exploit.
Let's now say that the stable coin depegs from its $1 price. Now, a user that has already used this stable coin as collateral in the margin account should have a lower value of collateral and therefore could be at risk of being liquidated. However, because the price of the stable coin is manually pegged to $1, the unhealthy trader's position will still appear healthy. If the stable coin failed to return to it's previous $1 value then even if the price of the stable coin was changed by governance to reflect the new lower value, the amount of bad debt accrued by Hubble would be huge at the time of liquidation/settlement.
The other scenario that will be used more actively by malicious users is that they will acquire the depegged stable coin from another source at its depegged value (e.g. $0.9). The malicious user can then deposit this stable coin into the Hubble margin account at the hard coded value of $1, and open positions with a value that should ordinarily put the trader into a bad debt position.
Impact
A short term stable coin depeg event will result in accounts not being liquidated when they should be, and it will allow users to gain from arbitrage trades where they purchase a stable coin at its depegged price and are offered a higher price in Hubble.
A permanent depeg will result in a huge amount of bad debt in Hubble and would likely cause the protocol to become insolvent due to the inability to perform liquidations during the downward price movement.
Code Snippet
https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/Oracle.sol#L30-L32 https://github.com/sherlock-audit/2023-04-hubble-exchange/blob/main/hubble-protocol/contracts/Oracle.sol#L172
Tool used
Manual Review
Recommendation
I would recommend not having the option to manually set and read the price of a stable coin. Yes, you protect accounts from being liquidated from a short term depeg event, however it is precisely in these volatile market periods that accounts should be able to be liquidated to prevent Hubble from accruing too much bad debt, particularly if the depeg is permanent, in which case it will likely cause Hubble to become insolvent.
Discussion
asquare08
We are using stable price mechanism just for our testnet. We will use actual USDC price for the mainnet.
asquare08
As mentioned in the above comment, there is no change required for this in contracts. We'll set stable price for usdc to 0 to use oracle price feeds for usdc.
IAm0x52
No fix needed in the current contract. Mainnet deployment will use oracle feed for USDC
MLON33
No fix will be made so Sherlock considers this issue to be acknowledged by the protocol team.
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
Likely the oracle contract allows governance to manually set a stablecoin's price, which does not update automatically when the stablecoin depegs.
Impact
A short-term depeg could prevent liquidations and allow arbitrage profits, while a permanent depeg could cause significant bad debt and potentially insolvency.
What the attacker needed
Stablecoin depegs; attacker can acquire depegged stablecoin; manual price set by governance
The fix
The protocol team stated that the stable price mechanism is only for testnet and that mainnet will use oracle price feeds for USDC, so no contract change was made.
How it was found
- Acquire the depegged stablecoin from another source at its depegged value.
- Deposit the stablecoin into the Hubble margin account, where it is valued at the manually set price of $1.
- Open positions using the inflated collateral value, potentially creating bad debt for the protocol.
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 stablecoin is a cryptocurrency designed to stay at a fixed price, like $1. The oracle is a service that tells the protocol what an asset is worth. Here, the protocol let administrators set the stablecoin's price manually to $1, even if the market price dropped. An attacker could buy the stablecoin for less than $1 elsewhere, deposit it as if it were worth $1, and borrow against that inflated value, leaving the protocol with losses.