Skip to content
Business logic Audit finding Advanced

Inbound Tx Confirmation Bypass via Malicious Observer

The inbound transaction tracker in ZetaChain did not check block confirmations before acting on cross-chain transactions, unlike the normal event handler. A malicious or compromised observer could add a transaction from a fork to the tracker and later profit from a block reorganisation, potentially causing a double spend.

ChristiansWhoHack Follow with ChristiansWhoHack

Originally disclosed on Code4rena

Submitted by ChristiansWhoHack, also found by ChristiansWhoHack

https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/zetaclient/inbound_tracker.go#L144

https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/zetaclient/inbound_tracker.go#L179

https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/zetaclient/inbound_tracker.go#L213

https://github.com/code-423n4/2023-11-zetachain/blob/b237708ed5e86f12c4bddabddfd42f001e81941a/repos/node/zetaclient/inbound_tracker.go#L71

When utilizing state from multiple blockchains, it is important that this information is finalized. If not, a block reorganization can occur. This is possible since some subset of nodes may have one chain but the other set will have another. When this happens, a double spend can occur. For instance, if node set A includes the transaction and is processed as the event occurring but then a block reorganization occurs going to node set B that does NOT include a transaction, then the funds were processed prematurely. Now, the user has funds in both locations. For more on this, read the post by Halborn. This finding is similar to the Outbound Block confirmation check missing but is different because there are in separate sections of code and one is outbound while the other is inbound (this one).

Zetachain has set amount of blocks that it must observe to be completed before it will be confirmed that a block occurred or not. After this threshold of new blocks has been met, it is presumed that no block reorganization will occur. In previous audits, the Bitcoin confirmation count was too low, leading to potential of double spend issues. When processing incoming transaction through the normal event handling, Zetachain verifies that enough blocks have passed.

It is possible to bypass the confirmation protection by using the InTxTracker functionality. The confirmation checks are completely missing for both Ethereum and Bitcoin clients when performing these event checks. Directly after seeing the event in the TxTracker queue, the events will be queried from the blockchain without verifying the amount of blocks that have passed. The regular event handling and TxTracker processing are implemented completely separately, even though they are very similar in nature.

To exploit this, the attacker must be an observer. This is because untrusted relayers must add in a proof, which requires the header to be at a certain point. In particular, the confirmation check is respected on the block header voting. However, an observer does not have to provide a proof; they can simply provide by TxHash and it will be added to the functionality. The observers are somewhat trusted entities but this is still a decentralized system. A malicious or compromised observer should not be able to forgo the confirmation checks entirely to lead the environment vulnerable to a double spend attack.

The result of this is that a malicious observer/compromised node could see a fork happening, add this to the Tracker, then profit from the reorganization that happens later. This would duplicate the funds; once on the specified destination from the CCTX and one in the owners wallet. Practically exploiting this is difficult though.

Proof of Concept

Actually implementing an exploit that causes a double spend by a block reorganization is extremely difficult to do in a test environment. As a result, we deemed that a sufficient way to write a proof of concept for this is to demonstrate that the CCTXs are being operated on even though not enough blocks have been passed. From this, it is easy to deduce that a block reorganization would result in stolen funds.

To prepare for the exploit, do the following:

  • Setup the Zetachain test environment. Instructions can be found at https://github.com/code-423n4/2023-11-zetachain/blob/main/repos/node/contrib/localnet/README.md.

  • Attach to the administrative function of the ETH node. This can be done with the following commands: sudo docker exec -it geth /bin/sh geth attach ipc://tmp/geth.ipc

  • Ensure that cast from Foundry and Zetacore are installed on the same machine. Otherwise, it’s not feasible to do this fast enough. This may require porting keys from the observer to the main machine or installing cast on the zetacore0 observer.

  • Follow along in the PoC video

  • Find the ETH TSS address. This can be found by grepping the orchestrator logs for ETH Address.

  • Send Ether to the TSS address. We will do this with Cast using the following command.

      cast send --value 1000007 <TSS ADDRESS> --private-key d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263
    
  • Quickly after sending this, add the transaction to the tx queue. This can be done with the following command: zetacored tx crosschain add-to-in-tx-tracker 1337 1 —from zetacored keys list --output json | jq '.[0].address' -r —yes —fees 10000azeta —chain-id athens_101-1

  • Go to the terminal with the geth admin connection setup. Run miner.stop() as fast as possible. If this is done fast enough, a single mined block is enough. Notice that this has paused the chain. To check this, you can run cast block-number and notice that the block number does not change.

  • Keep track of the amount of CCTXs being voted on. This can be done by calling the following command: zetacored query crosschain list-cctx -o json | jq ‘.CrossChainTx | length’

  • Notice that the length increases by 1 over time, which is the CCTX we just sent. This should NOT happen because the block confirmation has not been met. If a reorganization occurred at this point then a double spend could occur later.

Short Term Remediation

Respect the block confirmation limits on both Ethereum and Bitcoin for inbound transactions. Simply ensure that enough blocks have passed prior to acting on them.

This is done properly within the ObserveTxIn code but not in the InboundTracker code.

Long Term Remediation

The code between the InboundTracker and ObserveTxIn does almost the exact same parsing. The only difference is that the InboundTracker is told which transactions to look at while the latter looks at all transactions. The original was safe but the newer code is not.

To prevent these sorts of issues in the future, try to share the code between the two locations. This way, security issues are not repeated over and over again.

lumtis (ZetaChain) confirmed, but disagreed with severity and commented:

I would actually decrease the severity since it concerns malicious observer and doesn’t seem trivial to execute.

0xean (Judge) decreased severity to Medium


The original report as published on Code4rena, by ChristiansWhoHack. 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

The inbound tracker code path did not enforce the same block confirmation threshold as the normal inbound transaction handler.

Impact

A malicious or compromised observer could bypass confirmation checks and potentially cause a double spend after a block reorganisation, though the report notes that practically exploiting this is difficult.

What the attacker needed

Attacker is an observer node; ability to trigger a block reorganisation; test environment for proof of concept

The fix

The inbound tracker should enforce the same block confirmation limits as the normal inbound transaction handler, ideally by sharing code between the two paths.

How it was found

  1. Set up the ZetaChain test environment and attach to the Ethereum node's administrative console.
  2. Find the TSS address from the orchestrator logs and send Ether to it.
  3. Quickly add the transaction to the inbound tracker queue using zetacored.
  4. Stop the miner to pause the chain before enough blocks are mined.
  5. Query the list of cross-chain transactions and observe that the count increases even though the confirmation threshold has not been met.

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 blockchain sometimes reorganises recent blocks, so a transaction that looked confirmed can disappear. ZetaChain normally waits for enough blocks before trusting a transaction, but a special shortcut called the inbound tracker skipped that wait. A malicious node operator could use the shortcut to get funds credited early and then keep them after the reorganisation.

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 ChristiansWhoHack

View all

6 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.