Skip to content
Business logic Disclosed report Advanced

It's possible to put SDX orderbook into invalid state and execute trades at arbitrary price

Stellar-core mishandles a buy offer that crosses existing sell offers but is only partially filled due to a trustline limit, leaving a crossing offer in the orderbook. An attacker could exploit this to create invalid orderbook states and execute trades at arbitrary prices, manipulating trade history and charts.

nebolsin Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Triaged in 2 hours
  • Fixed in 6 months
  • Disclosed after 7 months

stellar-core improperly handles creation of a buy offer which crosses existing sell offers (immediate execution) but can only be filled partially due to a trustline limit on the source account. This makes it possible to create a valid offer to buy any custom asset at higher price than existing sell offers. If counter is not native, it's also possible to create a sell offer lower than existing bids.

Steps to reproduce

  1. Choose any asset ABC with non-empty orderbook ABC-XLM
  2. Create and fund account H, then set a trustline for ABC with limit 1
  3. Choose arbitrary price P higher than existing best ask price Pa
  4. Prepare the tx to sell P XLM for ABC at price P and then increase the trustline limit to 2, sign it with H secret key and send to the network.
Transaction(
  source = H, 
  operations = [
    manageOffer(selling=XLM, buying=ABC, amount=P, price=P, offerId=0),
    changeTrust(asset=ABC, limit=2)
  ]
)

Account H will receive 1 ABC balance and an offer to sell (P - Pa) XLM for ABC will be created at price P.

Order book is now in invalid state and contains crossing offers, so max(bidPrice) > min(askPrice). Next offer to sell ABC for XLM with price lower than P will claim our offer and result in a trade at price P.

Examples

F268790: Invalid bid created by exploiting this vulnerability. Account with a trustline for BUG asset (balance=500, limit=501) posted an offer to sell 100XLM to buy BUG at price 100 XLM per BUG. Result: account bought 1 BUG from the best ask at 9 XLM per BUG, and an offer to sell the remaining 91XLM at price 100 was saved into the orderbook.

F268791: Real case on a public network on MOBI-XLM traiding pair happened to some user (this is where I noticed the anomaly in trade history and started investigation). Relevant ledgers 16494494 - 16494512.

Impact

Attacker could exploit this behaviour to mess up the orderbook, trade history and chart for any trading pair on Stellar Distributed Exchange.

For example, it's possible (and very easy) to create a bot which will constantly create an bid at arbitrary high price P and immediately sell into this bid from another account, making last ticker price always equal P, despite that there're sell offers at a lower price.

This will make OHLC chart analysis useless because high price will be P on every tick. It could also confuse other market participants by creating the impression that P is the fair price for the asset.

Attachments

SDX_invalid_bid_.png
SDX_invalid_bid_.png From the original on HackerOne
MOBI-XLM_trade_history.png
MOBI-XLM_trade_history.png

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

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 code does not properly handle the case where a buy offer crosses existing sell offers but cannot be fully filled because the buyer's trustline limit is reached, leaving a partially filled crossing offer in the orderbook.

Impact

An attacker could mess up the orderbook, trade history and chart for any trading pair on the Stellar Distributed Exchange, potentially making OHLC chart analysis useless and confusing other market participants.

What the attacker needed

Access to Stellar network; ability to create accounts and trustlines; knowledge of orderbook state

How it was found

  1. Choose any asset ABC with a non-empty orderbook ABC-XLM.
  2. Create and fund account H, then set a trustline for ABC with limit 1.
  3. Choose an arbitrary price P higher than the existing best ask price Pa.
  4. Prepare a transaction to sell P XLM for ABC at price P and then increase the trustline limit to 2, sign it with H's secret key and send it to the network.

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.

The Stellar network lets people trade assets using an orderbook, which lists buy and sell offers. A bug in the software that runs the network allowed someone to create a buy offer that should have been fully matched but was only partly filled, leaving a buy price higher than the lowest sell price. This broken state could be used to make trades happen at fake prices and mess up price charts.

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 from Stellar.org

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.