Skip to content
Business logic Audit finding Intermediate

User funds can be lost in favor of Zeta protocol during a CCTX due to contracts being paused

The onRevert function in ZetaConnector contracts is gated by whenNotPaused, so when contracts are paused during an emergency, a failed cross-chain transaction cannot be refunded and user funds remain stuck in the protocol.

dontonka Follow with lsaudit

Originally disclosed on Code4rena

Submitted by dontonka, also found by lsaudit

https://github.com/code-423n4/2023-11-zetachain/blob/main/repos/protocol-contracts/contracts/evm/ZetaConnector.eth.sol#L85

https://github.com/code-423n4/2023-11-zetachain/blob/main/repos/protocol-contracts/contracts/evm/ZetaConnector.non-eth.sol#L95

Observer take care of inbound/outbound CCTX in Zeta ecosystem. For EVM chains, it works with 3 smart contracts which are deployed on the external EVM chain:

  • ZetaConnectorEth.sol: entry point —> client calls send —> ZetaSent log
  • ZetaConnectorNonEth.sol: entry point —> client calls send —> ZetaSent log
  • ERC20Custody.sol: entry point —> client calls deposit —> Deposited log

In case of emergency, these contracts can be paused by calling their corresponding pause() function. The assumption would be that they are paused on both the inbound and outbound EVM chains, as otherwise there will be always inbounds CCTX coming in, and that will result more complex to manage. Since the 3 functions mention above are gated by whenNotPaused, whenever a contract is paused, it will prevent any inbounds cctx from coming in.

There is a key problem in the moment with this scenario: onRevert is gated with whenNotPaused while onReceive is not. This means whenever the contracts are paused (on both chains), the pending CCTX still need to be processed before any migration can happen (eg: migrating TSS). This is the specific reason why onReceive is not being gated with whenNotPaused, but since onRevert is gated, a revert in onReceive would kick-off the refund mecanism, which will call onRevert on the originating chain but that will always revert if the contract is also paused.

Impact

User funds can be lost in favor of Zeta protocol during a CCTX due to contracts being paused.

Proof of Concept

Let’s consider the CCTX flow described in the whitepaper as follow for Cross-Chain Message Passing.

Let’s consider a pending CCTX between BSC and ETH chains in a context of an emergency situation where contracts on both BSC and ETH are paused, but our CCTX had already generated his ZetaSent event, awaiting to be processed/voted/finalized by the Observers, so it’s pending, and now still need to be fully processed while the contracts are paused.

  • At step 5, this is where the onReceive is being called against ZetaConnector*.sol. But user has a bad luck and unfortunatelly, that revert (eg: caused by onZetaMessage).
  • At step 9, the refund mechanism will be triggered.
  • At step 11, this is when onRevert will be called. Since the BSC ZetaConnector*.sol is also paused, this will revert right away (caused by whenNotPaused), and at step 14 failure will be confirmed, hence funds will not be refunded to the user in the end and remain in Zeta protocol, which is effectivaly user funds lost.

Cross-Chain Message Passing flow

  1. An end user interacts with a Contract C1 on Chain A.
  2. The interaction leaves an event or transaction memo, with user specified [chainID,

contractAddress, message]. (the message is arbitrarily encoded application data in binary format. 3. ZetaChain observers (in zetaclient) pick up this event/memo and report to zetacore, which verifies the inbound transaction. 4. zetacore modifies the CCTX (cross-chain tx) state variable with OutboundTxParams which instructs the TSS signers (in zetaclient) to build, sign, and broadcast external transaction. 5. The zetaclient TSS signers observe the OutboundTxParams in the CCTX, and build outbound tx, enter into a TSS keysign ceremony to sign the transaction, and then broadcast the signed transaction to the external blockchains. For CCMP, the outbound transaction is mainly calling the user specified contract with specified addresses and parameters. 6. The CCTX structure also tracks the stages/status of the cross-chain transaction. 7. Once the broadcasted transaction is included in one of the blocks (said to be “mined” or “confirmed”), zetaclients will report such confirmation to zetacore, which will update the CCTX status. 8. If the “confirmed” outbound transaction was successful, the CCTX status becomes OutboundMined, and the CCTX is considered in its terminal state and will not be updated anymore. This CCTX processing is completed. 9. If the “confirmed” outbound transaction is failure (e.g. revert on Ethereum chains), then the CCTX will updates it status to PendingRevert if possible, or Aborted if revert is not possible. The CCTX processing is completed if it goes to Aborted status. 10. If the new status is “PendingRevert”, a second OutboundTxParams should be already in the CCTX, which instructs the zetaclients to create a “Revert” outbound tx to the incoming chain & contract, allowing the incoming contract to implement a application level revert function to cleanup contract state. 11. The zetaclients will build the revert transaction, enter into TSS keysign ceremony to sign the transaction, and broadcast to the incoming blockchain (Chain A in this case). 12. Once the revert transaction is “confirmed” on Chain A, the zetaclients will report the transaction status to zetacore. 13. If the revert transaction is successful, the CCTX status becomes Reverted, and the CCTX processing is completed. 14. If the revert transaction is failure, the CCTX status becomes Aborted, and the CCTX processing is completed.

Recommended Mitigation Steps

Whenever contracts are paused in case of emergency, in order to properly complete the pending CCTXs, the entire CCTX flow must be active, which include the refund mechanism.

By removing the whenNotPaused on onRevert function, that will resolve the problem, so I would recommend the following change in ZetaConnectorEth.sol and ZetaConnectorNonEth.sol

    function onRevert(
        address zetaTxSenderAddress,
        uint256 sourceChainId,
        bytes calldata destinationAddress,
        uint256 destinationChainId,
        uint256 remainingZetaValue,
        bytes calldata message,
        bytes32 internalSendHash
-    ) external override whenNotPaused onlyTssAddress {
+    ) external override onlyTssAddress {

lumtis (ZetaChain) commented:

This is a valid issue.

0xean (Judge) commented:

Since the pause state is meant to be utilized in the course of normal operations (updating the TSS address for example), I think H is actually warranted.

Note: See full discussion here.


The original report as published on Code4rena, by dontonka. 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 onRevert function includes the whenNotPaused modifier, preventing refunds while the contract is paused.

What the attacker needed

Contracts paused on both chains; pending cross-chain transaction; onReceive reverts

The fix

The whenNotPaused modifier should be removed from the onRevert function in both ZetaConnectorEth.sol and ZetaConnectorNonEth.sol.

How it was found

  1. A cross-chain transaction is pending between BSC and ETH while both chains' contracts are paused.
  2. The onReceive call on the destination chain reverts.
  3. The refund mechanism is triggered, which calls onRevert on the source chain.
  4. Because the source chain contract is also paused, onRevert reverts immediately.
  5. The transaction is marked as failed and funds are not refunded to the user.

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 a cross-chain transfer fails, the system tries to send the money back to the user. But if the contracts are paused for maintenance, that refund step is also blocked, so the money stays stuck in the protocol instead of returning to the user.

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 dontonka

View all

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