Skip to content
Business logic Audit finding Intermediate

Lack of message ordering may lead to failed transactions

Cross-chain messages sent from an external chain are not guaranteed to be finalised in the order they were sent, because observers vote independently and at different times. A dApp that relies on two messages being processed in sequence, such as a stake followed by an unstake, could see the second message executed first and the transaction revert on the destination chain.

berndartmueller Follow

Originally disclosed on Code4rena

Submitted by berndartmueller

Cross-chain messages might be processed out-of-order, leading to failed transactions and dApps that are not working as expected.

Proof of Concept

Cross-chain messages can be sent between external chains by using the ZetaConnectorEth.send function. This function emits the ZetaSent event that is subsequently picked up by the ZetaChain observers and voted upon.

31: function send(ZetaInterfaces.SendInput calldata input) external override whenNotPaused {
32:     bool success = IERC20(zetaToken).transferFrom(msg.sender, address(this), input.zetaValueAndGas);
33:     if (!success) revert ZetaTransferError();
34:
35:     emit ZetaSent(
36:         tx.origin,
37:         msg.sender,
38:         input.destinationChainId,
39:         input.destinationAddress,
40:         input.zetaValueAndGas,
41:         input.destinationGasLimit,
42:         input.message,
43:         input.zetaParams
44:     );
45: }

Such a cross-chain transaction is considered valid (finalized), once a quorum of observers has voted on the transaction and verified the legitimacy of the transaction. This process naturally takes a certain amount of time, as the observers wait for the including block (on the external chain) to be confirmed by a reasonable amount of subsequent blocks. Additionally, observers are not 100% synchronized, meaning that some observers might have seen the including block earlier than others.

As a result, cross-chain transactions, or inbound cctxs in general, are not guaranteed to be finalized in the order they were sent from the external chain.

This can lead to a situation where a contract on an external chain that sends two consecutive cross-chain messages and expects the second message to be processed after the first message, is not guaranteed to be processed in the correct order.

For example, consider the simplified example of a staking dApp which sends multiple consecutive cross-chain messages in the same block or transaction (please ignore the reasoning why a user would stake and immediately unstakes, this should just demonstrate the dependency on the order of the messages):

  1. stake
  2. unstake

Those two messages have to be in order. If message 2 (unstake) is executed before message 1 (stake), the transaction reverts on the destination chain as there is no stake to unstake.

Even if the dApp would incorporate a nonce in the cross-chain message, the receiving contract on the destination chain would reject the out-of-order message as the nonce is not the next expected nonce and revert the transaction.

Recommended mitigation steps

Consider adding the option to enforce message ordering per sender and source chain, similar to LayerZero’s message ordering feature.

lumtis (ZetaChain) confirmed


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

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 protocol finalises inbound cross-chain transactions based on independent observer votes without any per-sender ordering guarantee, so arrival order at the destination is not preserved.

Impact

Cross-chain messages may be processed out of order, causing dependent transactions to revert and dApps to behave incorrectly; the text does not describe theft or loss of funds.

What the attacker needed

A dApp sending dependent cross-chain messages; no ordering guarantee on the protocol

The fix

The protocol should offer an option to enforce message ordering per sender and source chain, similar to LayerZero's message ordering feature.

How it was found

  1. A contract on an external chain sends two consecutive cross-chain messages, for example stake then unstake.
  2. Observers pick up the emitted events and vote on them at different times.
  3. The second message is finalised before the first.
  4. The destination chain executes the out-of-order message and the transaction reverts.

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 cross-chain system lets one blockchain send a message to another. Here, a group of watchers on the outside chain each vote on whether a message really happened, and they do not all see it at the same moment. So two messages sent one after the other can be accepted in the wrong order, and a contract that expects the first one to land first will fail.

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 berndartmueller

View all

97 more disclosed reports, best first.

More from ZetaChain

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.