Skip to content
Business logic Audit finding Intermediate

TON transactions risk being lost due to flawed transaction handling

The TON observer fetched transactions in newest-to-oldest order and, when the last scanned transaction was found, returned early without reversing the list. If more than 100 transactions were returned, only the 100 most recent were processed, and older unprocessed transactions were skipped in subsequent runs, causing a loss of funds.

0x73696d616f Follow with BrothersInCode

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-04-zetachain-cross-chain-judging/issues/73

Found by

0x73696d616f, BrothersInCode

Description

Inside the ton::inbound.go::ObserveInbound function, transactions are fetched using the following code:

Go
txs, err := ob.client.GetTransactionsSince(ctx, ob.gateway.AccountID(), lt, hashBits)
if err != nil {
	return errors.Wrap(err, "unable to get transactions")
}

The GetTransactionsSince method retrieves transactions, populating the txsarray, beginning with most recent to oldest, which aligns with how the TON Lite API operates:

Go
// Note: TON Lite API returns transactions from latest to oldest.
// We retrieve up to `pageSize` transactions per call.
txs, err := c.GetTransactions(ctx, pageSize, acc, lt, hashBits)
if err != nil {
	return nil, errors.Wrapf(err, "unable to get transactions [lt %d, hash %s]", lt, hashBits.Hex())
}

Here, pageSize is set to 200.

JSX
	pageSize       = 200

If the last scanned transaction is found in the retrieved txs, the function exits early without reversing the list. As a result, the transactions are processed starting from the most recent to oldest.

JSX
	for i := range txs {
			found := txs[i].Lt == oldestLT && txs[i].Hash() == tlb.Bits256(oldestHash)
			if !found {
				continue
			}

			// early exit
			result = append(result, txs[:i]...)

			return result, nil
		}

When exiting early and processing without reversing, ObserveInbound continues with this logic:

Go
case len(txs) > maxTransactionsPerTick:
	ob.Logger().Inbound.Info().
		Msgf("observeGateway: got %d transactions. Taking first %d", len(txs), maxTransactionsPerTick)

	txs = txs[:maxTransactionsPerTick]

JSX
	maxTransactionsPerTick = 100

If more than maxTransactionsPerTick transactions are returned—which is possible given the pageSize is set to 200—only the first 100 transactions are processed. Because of the way the transactions are ordered, only the 100 most recent ones will be processed.

Impact

As a result, The next time ObserveInbound runs, it will skip over the older transactions that were previously unprocessed due to the maxTransactionsPerTick limit because setLastScannedTx points to a newer transaction, causing the previously skipped older ones to be bypassed entirely and never be processed causing loss of funds.

POC

  • LastScannedTx is set to tx=0
  • GetTransactionsSince retrieves 200 transactions, ordered from newest to oldest.
  • During processing, the last scanned transaction (tx=0) is found at the 130th position, so the function returns early without reversing the list.
  • Since 130 > maxTransactionPerTick, only the first 100 transactions (i.e., the most recent ones) are processed.
    • In this example, it will be transaction 30..130
  • At the end of ObserveInbound, the pointer will be set to 130
  • This means that, in the next round of ObserveInbound, transactions will be fetched from 130.. and thus, the transactions 0..29 will never be executed.
  • This is a total loss of funds for the users that submitted those transactions.

Recommendation

Ensure that users do not risk losing their funds when interacting with the TON implemenation.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/zeta-chain/node/pull/3958

gjaldon

The early exit case in GetTransactionsSince() now reverses the order of the results and fixes the issue.

The original report as published on Sherlock, by 0x73696d616f. 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 code did not reverse the transaction list when exiting early, so transactions were processed newest-first, and the limit of 100 per tick caused older transactions to be skipped and then permanently bypassed.

Impact

Older unprocessed transactions are permanently skipped, causing a total loss of funds for the affected users.

What the attacker needed

More than 100 transactions returned in one call; Last scanned transaction found within the fetched batch

How it was found

  1. LastScannedTx is set to tx=0.
  2. GetTransactionsSince retrieves 200 transactions, ordered from newest to oldest.
  3. The last scanned transaction (tx=0) is found at the 130th position, so the function returns early without reversing the list.
  4. Since 130 > maxTransactionPerTick, only the first 100 transactions (the most recent ones) are processed.
  5. At the end of ObserveInbound, the pointer is set to 130.
  6. In the next round, transactions are fetched from 130 onwards, so transactions 0..29 are never executed.

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 program that watches for incoming transactions on a blockchain was reading them in the wrong order. When there were too many to handle at once, it only looked at the newest ones and ignored the older ones. Later, it thought it had already seen those older ones, so they were never processed and users lost 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 0x73696d616f

View all

172 more disclosed reports, best first.

More from ZetaChain Cross-Chain

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.