Skip to content
Business logic Audit finding Intermediate

Integer division rounding down allows buyers to obtain free position tokens in JIT Minting

Integer division in the JIT minting path rounds a buyer's collateral contribution down to zero for very small fill amounts, while the buyer still receives position tokens. An attacker could repeat tiny orders to accumulate position tokens without locking collateral and then claim payouts from other participants' locked funds.

0x97 Follow with 0xCrypt0nite, 0xDaniel_eth and 16 others

Originally disclosed on Sherlock

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

Found by

0x97, 0xCrypt0nite, 0xDaniel_eth, 0xeix, 0xzen, 8olidity, AlexCzm, CasinoCompiler, OxSath404, SOPROBRO, anchabadze, dimulski, falde, heeze, ivanalexandur, jayjoshix, ke1caM, sach1r0, typicalHuman

Summary

Small trade amounts cause buyer collateral contribution to round down to zero in _executeJITMinting, allowing buyers to receive position tokens and accumulate position tokens without locking collateral through repeated small orders, then claim full payouts from other participants' locked funds.

Finding Description

The _executeJITMinting function calculates proportional collateral using integer division:

Solidity
        uint256 buyerPayment = (fillAmount * sellOrder.price) / 10000;
        uint256 sellerPayment = fillAmount - buyerPayment;

When fillAmount is small, buyerPayment rounds to zero while the buyer still receives tokens. Example:

  • fillAmount = 1 token
  • sellOrder.price = 4999 (49.99%)
  • buyerPayment = (1 × 4999) / 10000 = 0
  • sellerPayment = 1 - 0 = 1

The function then proceeds to:

Solidity
vault.lockCollateral(conditionId, buyOrder.user, 0);  // Alice locks nothing
vault.lockCollateral(conditionId, sellOrder.user, 1); // Bob locks 1

// Mint complete set - both get fillAmount regardless of contribution
for (uint256 i = 0; i < numberOfOutcomes; i++) {
    uint256 outcomeIndex = 1 << i;
    uint256 tokenId = positionTokens.getTokenId(conditionId, outcomeIndex);
    
    if (outcomeIndex == buyOrder.outcome) {
        buyerAmounts[0] = fillAmount;  // Alice gets 1 YES token
    } else {
        sellerAmounts[sellerIndex] = fillAmount; // Bob gets 1 NO token
    }
}

positionTokens.mintBatch(buyOrder.user, buyerTokenIds, buyerAmounts); // Alice receives tokens
positionTokens.mintBatch(sellOrder.user, sellerTokenIds, sellerAmounts); // Bob receives tokens

Token minting uses fillAmount for both parties, completely independent of their actual collateral contributions. Alice receives 1 YES token despite buyerPayment = 0.

Result:

  • Alice: Locks 0, receives 1 YES token
  • Bob: Locks 1, receives 1 NO token

Links to affected code

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

Impact Explanation

Attackers systematically accumulate position tokens with zero collateral contribution through repeated small trades, then claim full payouts

Recommendation

Implement minimum trade size.

Discussion

sherlock-admin2

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

The original report as published on Sherlock, by 0x97. 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

Likely the collateral split uses integer division without a minimum trade size or rounding guard, so a small fill amount makes the buyer's share truncate to zero while tokens are still minted for the full fill amount.

Impact

An attacker could accumulate position tokens with no collateral and then claim full payouts from other participants' locked funds.

What the attacker needed

Ability to place small orders on the order book

The fix

The protocol team fixed this issue by adding a minimum trade size, as stated in the linked pull request.

How it was found

  1. Choose a very small fill amount and a sell order price just under the full percentage.
  2. The buyer's payment is computed by integer division and truncates to zero.
  3. The contract locks zero collateral for the buyer and the full amount for the seller.
  4. Both parties are minted position tokens for the full fill amount regardless of contribution.
  5. Repeat with many small orders to accumulate tokens without locking collateral, then claim payouts.

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.

When two people trade, the contract works out how much each side must put up as a deposit using whole-number maths. With very small trades that calculation can round down to nothing, so one side pays nothing but still gets tokens that can later be cashed out. Repeating this many times lets someone collect tokens for free at the expense of other users' money.

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 0x97

View all

1 more disclosed report, 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.