Funds from reverted transaction may be lost/locked
When a cross-chain transaction is reverted on the destination chain, the revert transaction on the source chain can fail, causing the cross-chain transaction to be marked as Aborted. The user's funds are then lost because the tokens are burned on the source chain and cannot be minted back.
Submitted by deliriusz, also found by zhaojie and p0wd3r
Vulnerability details
When the cross chain transaction is reverted on destination chain, the revert transaction is processed on source chain, and the remaining amount of Zeta tokens, excluding fees is returned to the CCTX sender. According to the code comment in /x/crosschain/keeper/keeper_cross_chain_tx_vote_outbound_tx.go:
If the previous status was
PendingOutbound, a new revert transaction is created. To cover the revert transaction fee, the required amount of tokens submitted with the CCTX are swapped using a Uniswap V2 contract instance on ZetaChain for the ZRC20 of the gas token of the receiver chain. The ZRC20 tokens are then burned. The nonce is updated. If everything is successful, the CCTX status is changed toPendingRevert.If the previous status was
PendingRevert, the CCTX is aborted.
The flow is:
- A cross-chain transaction is generated on the source chain. It’s verified and its status is changed to
PendingOutbound. - The transaction execution is attempted on the destination chain and fails. It is observed by
zetaclient/evm_signer/TryProcessOutTx, and broadcased:
// [...]
} else if send.CctxStatus.Status == types.CctxStatus_PendingRevert {
logger.Info().Msgf("SignRevertTx: %d => %s, nonce %d, gasprice %d", send.InboundTxParams.SenderChainId, toChain, send.GetCurrentOutTxParam().OutboundTxTssNonce, gasprice)
tx, err = signer.SignRevertTx( // @audit executes ZetaConnector.onRevert()
ethcommon.HexToAddress(send.InboundTxParams.Sender),
big.NewInt(send.OutboundTxParams[0].ReceiverChainId),
to.Bytes(),
big.NewInt(send.GetCurrentOutTxParam().ReceiverChainId),
send.GetCurrentOutTxParam().Amount.BigInt(),
gasLimit,
message,
sendhash,
send.GetCurrentOutTxParam().OutboundTxTssNonce,
gasprice,
height,
)
// [...]
if tx != nil {
// [...]
err := signer.Broadcast(tx)
- In case that this is non-eth revert, ZetaConnector.non-eth is called:
function onRevert(
address zetaTxSenderAddress,
uint256 sourceChainId,
bytes calldata destinationAddress,
uint256 destinationChainId,
uint256 remainingZetaValue,
bytes calldata message,
bytes32 internalSendHash
) external override whenNotPaused onlyTssAddress {
if (remainingZetaValue + ZetaNonEthInterface(zetaToken).totalSupply() > maxSupply)
revert ExceedsMaxSupply(maxSupply);
ZetaNonEthInterface(zetaToken).mint(zetaTxSenderAddress, remainingZetaValue, internalSendHash);
if (message.length > 0) {
ZetaReceiver(zetaTxSenderAddress).onZetaRevert(
ZetaInterfaces.ZetaRevert(
zetaTxSenderAddress,
sourceChainId,
destinationAddress,
destinationChainId,
remainingZetaValue,
message
)
);
}
// [...]
There are 3 possibilities when it may fail:
- Amount to be minted together with
totalSupply()is bigger thanmaxSupply ZetaReceiver(zetaTxSenderAddress).onZetaRevert()call reverts- TSS provides too little gas on purpose, but we assume that it’s trused, so it’s not really an issue.
If if fails, the transaction state is set to Aborted in x/crosschain/keeper/keepercrosschaintxvoteoutboundtx.go, and it won’t be processed:
case types.CctxStatus_PendingRevert:
cctx.CctxStatus.ChangeStatus(types.CctxStatus_Aborted, "Outbound failed: revert failed; abort TX")
}
In won’t be processed again.
And because only Connector can mint the tokens, the funds are lost without anyone able to mint them for the user.
Concerning maxSupply, it’s set to uint256.max during contract creation, however it’s adjustable by TSS to any value:
function setMaxSupply(uint256 maxSupply_) external onlyTssAddress {
maxSupply = maxSupply_;
emit MaxSupplyUpdated(msg.sender, maxSupply_);
}
Impact
User funds lost in case that revert transaction reverts on source chain.
Proof of Concept
Let’s take following example:
- User creates a cross chain transaction, to sends 10_000$ worth of ZRC20 cross chain using ZetaChain. He posts a transaction to
ZetaConnectorNonEth.send(), which creates cross chain transaction. - The transaction is reverted on destination chain. Hence new state
PendingRevertis added to the transaction and awaits to be processed on the source chain. ZetaConnectorNonEth.onRevert()is called on source chain. It reverts and cross chain transaction state is set toAborted.- The funds are burned on source chain, and not minted back, meaning that the funds are lost.
Recommended Mitigation Steps
- Make sure that TSS cannot decrease
maxSupplyover constanceMIN_SUPPLY_CAPor currenttotalSupply()
function setMaxSupply(uint256 maxSupply_) external onlyTssAddress {
+ if(maxSupply < MIN_SUPPLY_CAP) {revert MaxSupplyTooSmall()};
maxSupply = maxSupply_;
emit MaxSupplyUpdated(msg.sender, maxSupply_);
}
- Handle this case gracefully - consider not aborting the transaction in case of revert transaction failure, or add some kind of “voucher” that the user can redeem manually.
lumtis (Zetachain) confirmed via duplicate Issue #245
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 system aborts the cross-chain transaction when the revert transaction fails, without providing a fallback mechanism to return the funds to the user.
What the attacker needed
Cross-chain transaction reverts on destination; revert transaction fails on source chain
The fix
The system should not abort the transaction on revert failure, or should provide a voucher for manual redemption, and should prevent TSS from setting maxSupply below a minimum cap.
How it was found
- User creates a cross-chain transaction sending ZRC20 tokens via ZetaConnectorNonEth.send().
- The transaction is reverted on the destination chain, setting status to PendingRevert.
- ZetaConnectorNonEth.onRevert() is called on the source chain and reverts.
- The cross-chain transaction state is set to Aborted.
- The funds are burned on the source chain and not minted back, so they are lost.
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 transaction moves tokens from one blockchain to another. If the destination chain rejects the transaction, the system tries to return the tokens to the sender on the original chain. This report shows that if that return step fails, the transaction is permanently marked as failed and the tokens are gone, with no way to recover them.
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.