Skip to content
Business logic Audit finding Intermediate

Emergency resolver targets wrong epoch

The emergency resolution function reads the market's current epoch and passes it to the resolver, but in time-based markets that value has already rolled forward to the new trading period. An authorised matcher calling it after a rollover therefore resolves the wrong epoch, leaving the earlier epoch without a merkle root so users cannot claim winnings and locking the new epoch to an incorrect root.

0xeix Follow with 0xnija, 8olidity and 13 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-10-index-fun-order-book-contest-judging/issues/47

Found by

0xeix, 0xnija, 8olidity, DemiGods, Edoscoba, Icarus, Idealz, KrisRenZo, RajeshKotaru, Sir_Shades, Ziusz, blockace, jo13, neeloy, ubl4nk, x15

emergencyResolveMarket grabs currentEpoch from the market and forwards it to the resolver .

Solidity
// src/Market/MarketController.sol:745-758
function emergencyResolveMarket(bytes32 questionId, uint256 numberOfOutcomes, bytes32 merkleRoot)
        external
        onlyAuthorizedMatcher
    {
        require(market.isMarketReadyForResolution(questionId), "Market not ready for resolution");

        // Validate numberOfOutcomes parameter matches the actual market
        uint256 actualOutcomes = market.getOutcomeCount(questionId);
        require(actualOutcomes > 0, "Market not found");
        require(numberOfOutcomes == actualOutcomes, "Outcome count mismatch");
        require(numberOfOutcomes <= 256, "Maximum 256 outcomes supported");

        uint256 currentEpoch = market.getCurrentEpoch(questionId);
        marketResolver.resolveMarketEpoch(questionId, currentEpoch, numberOfOutcomes, merkleRoot);

        emit EmergencyResolution(questionId, currentEpoch, merkleRoot);
    }

In time-based markets getCurrentEpoch returns 1 + elapsed/duration, so once the new window starts the current epoch already points at the active trading period.

Solidity
// src/Market/Market.sol:222-236
function getCurrentEpoch(bytes32 questionId) public view returns (uint256) {
        if (!marketExists[questionId]) {
            return 0;
        }

        uint256 duration = epochDuration[questionId];
        
        // Manual epoch mode (legacy behavior)
        if (duration == 0) {
            return currentEpoch[questionId];
        }

        // Time-based epoch mode (automatic rolling)
        uint256 elapsed = block.timestamp - epochStartTime[questionId];
        return 1 + (elapsed / duration);
    }

Because daily/weekly markets configure resolutionTime = 0 (see controller comments), market.isMarketReadyForResolution is always true. An authorized matcher can legitimately call the emergency function hours after an epoch rolled. At that point currentEpoch has advanced, so the controller resolves the new epoch while the previous one remains unresolved.

The resolver then stores the merkle root under the wrong condition id and marks it resolved. Epoch 1’s condition id never gets a root, so users cannot claim winnings for that period, and epoch 2 is now locked to the incorrect root. There is no way for the matcher to repair this via the controller because the function lacks an epoch parameter.

Recommendation

Add an explicit epoch parameter to emergencyResolveMarket and require the caller to choose which epoch to resolve. Guard that value with require(epoch > 0 && epoch <= market.getCurrentEpoch(questionId)) and, for time-based markets, optionally ensure epoch < market.getCurrentEpoch(questionId) so only closed epochs can be resolved

https://github.com/sherlock-audit/2025-10-index-fun-order-book-contest/blob/main/orderbook-solidity/src/Market/MarketController.sol#L745

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/index-fun/orderbook-solidity/pull/54

The original report as published on Sherlock, by 0xeix. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 emergency function derives the epoch to resolve from the market's live current-epoch value instead of accepting an explicit epoch, so a rollover between the intended and actual call shifts the target.

Impact

Users cannot claim winnings for the skipped epoch and the following epoch is locked to an incorrect root, with no way to repair it through the controller; the text does not claim any loss of funds beyond that.

What the attacker needed

Caller is an authorised matcher; time-based market with rolling epochs; call made after an epoch rollover

The fix

The protocol team fixed this issue by adding an explicit epoch parameter to the emergency function and validating it against the market's current epoch.

How it was found

  1. An authorised matcher intends to resolve a finished epoch of a time-based market.
  2. The epoch window rolls over before the emergency call is made.
  3. The function reads the now-advanced current epoch and forwards it to the resolver.
  4. The resolver stores the merkle root under the new epoch's condition id and marks it resolved.
  5. The earlier epoch's condition id never receives a root, so claims for that period fail.

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.

Markets here run in repeating periods called epochs, and each period needs a published list (a merkle root) so winners can prove and claim their payouts. The emergency function was meant to publish that list for a finished period, but it looked up the period that is currently running instead of the one that just ended. So the finished period never got its list and payouts for it were stuck, while the running period got the wrong list.

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.

More by 0xeix

View all

10 more disclosed reports, best first.

More from Index Fun Order Book

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.