Skip to content
Smart contracts Audit finding Advanced

Malicious actors can manipulate the cross_chain_callback callback

The signature check on the cross-chain callback did not cover the from_chain field, so an attacker could front-run the legitimate callback with a wrong from_chain value that still passed signature verification. The handler then rejected the call and the transaction status was set to Failed, blocking the real callback from ever succeeding.

shaflow2 Follow with Abdessamed, gajiknownnothing and 11 others

Originally disclosed on Code4rena

Submitted by shaflow2, also found by Abdessamed, gajiknownnothing, Drynooo, 0x37, 0xAsen, Audinarey, Draiakoo, b0g0, agent3bood, MrPotatoMagic, fyamf, gesha17, and SBSecurity

Impact

Because the validator’s signature message does not include the from_chain field, a malicious actor can preemptively execute the validator’s transaction with an incorrect from_chain field. This can cause the status of create_cross_txs[txid] to become a Failed state, preventing it from being executed again.

Proof of Concept

This is the receive_cross_chain_callback function

    function receive_cross_chain_callback(
        uint256 txid,
        string memory from_chain,
        uint256 from_handler,
        address to_handler,
        CrossChainMsgStatus status,
        uint8 sign_type,
        bytes calldata signatures
    ) external {
        verifySignature(
            txid,
            from_handler,
            to_handler,
            status,
            sign_type,
            signatures
        );
        processCrossChainCallback(
            txid,
            from_chain,
            from_handler,
            to_handler,
            status,
            sign_type,
            signatures
        );
        emitCrossChainResult(txid);
    }

In the signature verification process, we found that the signature message does not include the from_chain field.

    function verifySignature(
        uint256 txid,
        uint256 from_handler,
        address to_handler,
        CrossChainMsgStatus status,
        uint8 sign_type,
        bytes calldata signatures
    ) internal view {
        bytes32 message_hash = keccak256(
            abi.encodePacked(txid, from_handler, to_handler, status)
        );

        require(
            signature_verifier.verify(message_hash, signatures, sign_type),
            "Invalid signature"
        );
    }

In this scenario, a malicious actor could execute the following attack steps:

  1. Front-run the caller’s transaction, providing correct signatures and other parameters, but with an incorrect from_chain field, causing the verifySignature validation to pass.
  2. In the processCrossChainCallback function, call handler::receive_cross_chain_callback.
  3. Due to the incorrect from_chain, the is_valid_handler function returns false, which causes handler::receive_cross_chain_callback to return false.
        if (is_valid_handler(from_chain, from_handler) == false) {
            return false;
        }
  1. If handler::receive_cross_chain_callback returns false, it will cause create_cross_txs[txid].status to be set to Failed.
        if (
            ISettlementHandler(to_handler).receive_cross_chain_callback(
                txid,
                from_chain,
                from_handler,
                status,
                sign_type,
                signatures
            )
        ) {
            create_cross_txs[txid].status = status;
        } else {
            create_cross_txs[txid].status = CrossChainMsgStatus.Failed;
        }

Recommended Mitigation Steps

    function receive_cross_chain_callback(
        uint256 txid,
        string memory from_chain,
        uint256 from_handler,
        address to_handler,
        CrossChainMsgStatus status,
        uint8 sign_type,
        bytes calldata signatures
    ) external {
        verifySignature(
            txid,
+           from_chain
            from_handler,
            to_handler,
            status,
            sign_type,
            signatures
        );
        ...
    }
    function verifySignature(
        uint256 txid,
+       string memory from_chain,
        uint256 from_handler,
        address to_handler,
        CrossChainMsgStatus status,
        uint8 sign_type,
        bytes calldata signatures
    ) internal view {
        bytes32 message_hash = keccak256(
-            abi.encodePacked(txid, from_handler, to_handler, status)
+            abi.encodePacked(txid, from_chain, to_handler, status)
        );

        require(
            signature_verifier.verify(message_hash, signatures, sign_type),
            "Invalid signature"
        );
    }

pidb (Chakra) disputed and commented:

This from_chain parameter is not important, as long as you ensure that the txid unique signature cannot be constructed repeatedly, currently txid satisfies this.

I think it should be downgraded to Medium risk, because txid can prevent it.

0xsomeone (judge) commented:

The Warden has identified a mechanism via which the third leg of a transaction can be blocked via a front-running attack, causing the transaction to indicate a failure status even though it would have normally been executed otherwise.

I consider this to be a valid high-severity issue as the status of all transactions can be trivially sabotaged to a failure state during their final callback leg.


The original report as published on Code4rena, by shaflow2. 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 signed message hash omitted the from_chain parameter, so a valid signature could be replayed with a different from_chain value.

Impact

An attacker could block the final callback of any cross-chain transaction and force its status to Failed, even though it would otherwise have succeeded.

What the attacker needed

Attacker can front-run the callback tx; valid validator signatures observed

The fix

The from_chain value should be included in the signed message hash so a signature cannot be reused with a different chain.

How it was found

  1. Front-run the legitimate callback transaction, reusing the valid signatures but supplying an incorrect from_chain value so signature verification still passes.
  2. The callback proceeds into processCrossChainCallback and calls the settlement handler's receive_cross_chain_callback.
  3. The handler's is_valid_handler check fails because from_chain is wrong, so the handler returns false.
  4. The contract sets create_cross_txs[txid].status to Failed, and the genuine callback can no longer be executed.

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 bridge lets one blockchain tell another that something happened, and a signed message proves the message is genuine. Here the signature covered most details but not which chain the message came from, so an attacker could copy a valid signed message, change that one detail, and send it first. The receiving contract then marked the transfer as failed, and the genuine message could no longer be processed.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by shaflow2

View all

12 more disclosed reports, best first.

More from Chakra

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.