Prevent markets getting stuck when prices don’t move
The smart contract only advances its market update index when the asset price changes, so if the price stays constant, pending settlements never execute and the market becomes stuck. An attacker could not directly exploit this, but it poses an availability risk if the oracle returns a constant price.
Submitted by gpersoon, also found by cmichel
Suppose there is a synthetic token where the price stays constant, for example:
- synthetic DAI (with a payment token of DAI the price will not move)
- binary option token (for example tracking the USA elections; after the election results there will be no more price movements)
In that case assetPriceHasChanged will never be true (again) and marketUpdateIndex[marketIndex] will never increase. This means the _executeOutstandingNextPrice* functions will never be executed, which means the market effectively will be stuck.
function `_updateSystemStateInternal`(uint32 marketIndex) internal virtual requireMarketExists(marketIndex) {
...
int256 newAssetPrice = IOracleManager(oracleManagers[marketIndex]).updatePrice();
int256 oldAssetPrice = int256(assetPrice[marketIndex]);
bool assetPriceHasChanged = oldAssetPrice != newAssetPrice;
if (assetPriceHasChanged || msg.sender == staker) {
....
if (!assetPriceHasChanged) {
return;
}
....
marketUpdateIndex[marketIndex] += 1; // never reaches this point if the price doesn't change
function _executeOutstandingNextPriceSettlements(address user, uint32 marketIndex) internal virtual {
uint256 userCurrentUpdateIndex = userNextPrice_currentUpdateIndex[marketIndex][user];
if (userCurrentUpdateIndex != 0 && userCurrentUpdateIndex <= marketUpdateIndex[marketIndex]) { // needs marketUpdateIndex[marketIndex] to be increased
_executeOutstandingNextPriceMints(marketIndex, user, true);
_executeOutstandingNextPriceMints(marketIndex, user, false);
_executeOutstandingNextPriceRedeems(marketIndex, user, true);
_executeOutstandingNextPriceRedeems(marketIndex, user, false);
_executeOutstandingNextPriceTokenShifts(marketIndex, user, true);
_executeOutstandingNextPriceTokenShifts(marketIndex, user, false);
Recommend enhancing _updateSystemStateInternal so that after a certain period of time without price movements (for example 1 day), the entire function is executed (including the marketUpdateIndex[marketIndex] += 1;)
Good point, we thought the time since last update check wasn’t necessary.
I’ll chat with the team about what they think the risk is. But I don’t think it is 3 given that we don’t plan to launch any assets that don’t have regular change (so market would be stuck for a limited time - even if it is long).
In a lot of ways our ‘nextPriceExecution` model is designed for this case. Some more traditional markets close for the weekend and over night. Our mechanism means that users will be able to buy and trade these assets at any time and get the asset as soon as there is an update.
The more I think about this the more I think it is a safety feature. It is way more likely that if the oracle keeps returning the same value that something is broken (which means we can catch the issue before it negatively impacts the system by unfairly managing user funds or similar). If it really is stuck on the same value legitimately it can replace the OracleManager that is being used to help with that.
Since there is no current plan for a binary market, and the system would definitely need other accommodations to allow a binary market, since next price execution etc, this doesn’t make sense as an issue in this case. The system is built for markets where continuous price updates will occur.
Agree with Jason, if not price update is occurring, there is likely an issue with the oracle, and our system is not failing even in light of this issue. It is effectively paused until a new price update is given. As Jason mentions we can use the oracle manager to fix this
Due to the ability to update the oracle, funds would not be lost, but it would be an availability risk (even if temporary) for the system. Based on that I am downgrading to a 2.
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
The contract only increments the market update index when the asset price changes, so a constant price prevents any pending settlements from being executed.
Impact
The market could become stuck and unavailable for an indefinite period, though funds would not be lost because the oracle can be replaced.
What the attacker needed
A synthetic token with constant price; oracle returns same price repeatedly
The fix
The contract should be enhanced so that after a certain period without price movement, the entire update function executes, including incrementing the market update index.
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.
This is a smart contract bug where the system only processes certain actions when the price of an asset changes. If the price stays the same, those actions get stuck forever, like a queue that never moves because the trigger never fires.
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.