Skip to content
DoS Audit finding Advanced

Stateful precompiles panic on empty calldata, which can be exploited to prevent finalizing outbound CCTXs

ZetaChain's stateful precompiles read the first four bytes of calldata without checking the length, so empty calldata causes a panic that aborts the whole Cosmos SDK message. An attacker can make outbound cross-chain transactions fail to finalise, filling the pending queue and blocking zetaclients from processing new outbound transactions.

berndartmueller Follow with oade_hacks and sherlockxyz

Originally disclosed on Sherlock

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

This issue has been acknowledged by the team but won't be fixed at this time.

Found by

berndartmueller, oade_hacks, sherlockxyz

Summary

The precompile caller can pass invalid (empty) calldata, which results in a panic in the precompile. This immediately exits the EVM and propagates up to the Cosmos SDK baseapp. The Cosmos SDK message (e.g., MsgVoteOutbound) fails, and the outbound cctx cannot be finalized. The cctx remains pending in the queue.

Root Cause

In ZetaChain's precompiles, it is assumed that the provided input (calldata) by the caller is at least 4 bytes long (function selector).

This is observed in the following instances:

For example, the RequiredGas() function in the bank precompile,

Go
92: func (c *Contract) RequiredGas(input []byte) uint64 {
93: 	// get methodID (first 4 bytes)
94: 	var methodID [4]byte
95: 	copy(methodID[:], input[:4])

accesses the first 4 bytes of the input without checking if the length is at least 4 bytes. If the length is less than 4 bytes, this will panic with an index out of range error.

This panic is propagated up until the Cosmos SDK baseapp, where it is caught to prevent the node from crashing.

However, the Cosmos SDK message has failed and cannot be executed.

Internal Pre-conditions

None

External Pre-conditions

None

Attack Path

  1. Attacker sends 500 (MaxPendingCctxs = 500) outbound CCTXs from ZetaChain to an external EVM chain (e.g., Ethereum) where they will error when calling the attacker's contract
  2. Observers vote on the failed outbound CCTXs
  3. The "final" CCTX vote attempts to finalize the outbound CCTX on ZetaChain by processing the revert on ZEVM
  4. As part of the revert process, the attacker contract's onRevert() function is called
  5. In onRevert(), ZetaChain's precompile is called with invalid calldata (e.g., empty calldata)
  6. The precompile panics, and the entire transaction fails
  7. The outbound CCTX cannot be finalized and remains pending in the queue
  8. This is repeated for all 500 outbound CCTXs, which remain pending in the queue
  9. EVM zetaclients will be unable to process other outbound CCTXs due to their lookback criteria

Impact

  • A Solidity contract that explicitly uses try-catch to ensure an external contract call must never cause the overall transaction to revert is unable to do so if the called contract calls the precompile with invalid calldata so that it panics.
  • More severe, if the ZEVM call is initiated as part of the MsgVoteOutbound message in response to a failed outbound cctx (i.e., reverting the cctx on ZEVM), and it panics, the entire message fails. As a result, the outbound cctx cannot be finalized, it remains pending. An attacker can repeatedly cause multiple cctx's to remain in pending state so that the pending cctx queue fills up until the limit is reached and the zetaclients are unable to process any new outbound cctx's.

PoC

This simple PoC runs the e2e/e2etests/test_precompiles_staking_through_contract.go E2E test and demonstrates how the staking precompile is called with empty calldata so that it panics. The try-catch is just cosmetic as it is unable to catch the panic.

Update the stakeWithStateUpdate function in TestStaking.sol and add the new causePanic function:

Solidity
function stakeWithStateUpdate(
    address staker,
    string memory validator,
    uint256 amount
) external onlyOwner returns (bool) {
    counter = counter + 1;
    // transfer full balance
    (bool success, ) = payable(address(0xdead)).call{value: payable(this).balance }("");
    require(success, "transfer to dead address failed");

    success = staking.stake(staker, validator, amount);

    try this.causePanic() {} catch {
        // do nothing
    }

    counter = counter + 1;
    return success;
}

function causePanic() external {
    // call `staking` contract with low level call invalid calldata so that it panics
    address(staking).call(hex"");
}

Re-generate the ABI Go bindings:

Bash
go generate ./e2e/contracts/teststaking

Run the test:

Bash
zetae2e run precompile_contracts_staking_through_contract --config cmd/zetae2e/config/local.yml --verbose

The precompile will panic, and all state changes will be reverted. The Docker logs will show the panic:

Bash
panic recovered in runTx err="recovered: runtime error: slice bounds out of range [:4] with capacity 0

Mitigation

Consider checking that the input length is at least 4 bytes.

The original report as published on Sherlock, by berndartmueller. 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 precompile's gas and dispatch functions slice the first four bytes of the input without first checking that the input is at least four bytes long.

Impact

Pending cross-chain transactions cannot be finalised, and once the queue limit is reached zetaclients may be unable to process any new outbound transactions; a contract's try-catch also cannot contain the panic.

What the attacker needed

Attacker-controlled contract on an external chain; ability to send outbound cross-chain transactions

The fix

The precompile should check that the input is at least four bytes long before reading the selector; the team acknowledged the issue but will not fix it at this time.

How it was found

  1. Send many outbound cross-chain transactions to an external chain that will fail when calling the attacker's contract
  2. Observers vote on the failed outbound transactions
  3. The final vote tries to finalise the transaction by processing the revert on ZEVM
  4. During the revert the attacker contract's onRevert function is called
  5. In onRevert the precompile is called with empty calldata, it panics and the whole transaction fails
  6. The outbound transaction stays pending, and repeating this fills the queue

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 precompile is a built-in contract that lives inside the blockchain node itself. Its code assumed every call carries at least a four-byte function selector, so a call with no data made it crash, and that crash cancelled the whole transaction that triggered it. Because the crash happens while the system is trying to settle a failed cross-chain transfer, the transfer stays stuck in a queue.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by berndartmueller

View all

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

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.