Skip to content
Business logic Audit finding Intermediate

settlement.cairo doesn’t process callback correctly leading to CrossChainMsgStatus marked as SUCCESS even if it failed on destination chain

The settlement contract on the source chain marks a cross-chain message as SUCCESS whenever the handler callback returns true, ignoring the actual status passed in the callback. An attacker could cause a failed cross-chain message to be recorded as successful, misleading users and potentially enabling double-spending or incorrect state.

0xAsen Follow with Tigerfrake, pwnforce and 3 others

Originally disclosed on Code4rena

Submitted by 0xAsen, also found by Tigerfrake, pwnforce, b0g0, ABAIKUNANBAEV, and AllTooWell

When a cross-chain message is sent it can return a callback with status FAILED or SUCCESS. The problem is that even if the cross-chain message failed, the original message status on the source chain would be marked as SUCCESS.

Let’s take a look at the receive_cross_chain_callback function on the settlement.cairo contract, and more specifically the part that updates the status:

    fn receive_cross_chain_callback(
                ref self: ContractState,
                cross_chain_msg_id: felt252,
                from_chain: felt252,
                to_chain: felt252,
                from_handler: u256,
                to_handler: ContractAddress,
                cross_chain_msg_status: u8, <--
                sign_type: u8,
                signatures: Array<(felt252, felt252, bool)>,
            ) -> bool {
    //other functionality

    let success = handler.receive_cross_chain_callback(cross_chain_msg_id, from_chain, to_chain, from_handler, to_handler , cross_chain_msg_status);

                let mut state = CrossChainMsgStatus::PENDING;
                if success{
                    state = CrossChainMsgStatus::SUCCESS;
                }else{
                    state = CrossChainMsgStatus::FAILED;
                }

                self.created_tx.write(cross_chain_msg_id, CreatedTx{
                    tx_id:cross_chain_msg_id,
                    tx_status:state, <--- update the status
                    from_chain: to_chain,
                    to_chain: from_chain,
                    from_handler: to_handler,
                    to_handler: from_handler
                });

The problem is that as long as the call to handler.receive_cross_chain_callback function was successful, the message as a whole will be marked in a SUCCESS state even though that cross_chain_msg_status could be SUCCESS or FAILED depending on if the message failed on the destination chain.

This could lead to a situation where a message fails to get processed on the destination chain, a callback is returned with cross_chain_msg_status == FAILED but the message is marked as SUCCESS.

That situation could be a user trying to bridge his tokens, the bridging fails so he doesn’t receive his tokens on the destination chain, a callback is made and the message is marked as a SUCCESS even though it as not successfully executed.

And if we see the code of the handler.receive_cross_chain_callback function, we’ll see that it’d always return true as long as it doesn’t revert:

            fn receive_cross_chain_callback(
                ref self: ContractState,
                cross_chain_msg_id: felt252,
                from_chain: felt252,
                to_chain: felt252,
                from_handler: u256,
                to_handler: ContractAddress,
                cross_chain_msg_status: u8
            ) -> bool{

                assert(to_handler == get_contract_address(),'error to_handler');
                assert(self.settlement_address.read() == get_caller_address(), 'not settlement');
                assert(self.support_handler.read((from_chain, from_handler)) &&
                        self.support_handler.read((to_chain, contract_address_to_u256(to_handler))), 'not support handler');

                let erc20 = IERC20MintDispatcher{contract_address: self.token_address.read()};

                if self.mode.read() == SettlementMode::MintBurn{
                    erc20.burn_from(get_contract_address(), self.created_tx.read(cross_chain_msg_id).amount);
                }

                let created_tx = self.created_tx.read(cross_chain_msg_id);

                self.created_tx.write(cross_chain_msg_id, CreatedCrossChainTx{
                    tx_id: created_tx.tx_id,
                    from_chain: created_tx.from_chain,
                    to_chain: created_tx.to_chain,
                    from:created_tx.from,
                    to:created_tx.to,
                    from_token: created_tx.from_token,
                    to_token: created_tx.to_token,
                    amount: created_tx.amount,
                    tx_status: CrossChainTxStatus::SETTLED
                });

                return true;
            }

The function just performs validation of the handlers, if the settlement contract calls it and returns true. These validation could all be true but the initial message could still be with a FAILED status.

This is not taken into account and could lead to a failed message being marked as a successful one.

The implementation on the solidity contract is correct:

        function processCrossChainCallback(
            uint256 txid,
            string memory from_chain,
            uint256 from_handler,
            address to_handler,
            CrossChainMsgStatus status,
            uint8 sign_type,
            bytes calldata signatures
        ) internal {
            require(
                create_cross_txs[txid].status == CrossChainMsgStatus.Pending,
                "Invalid transaction status"
            );

            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;
            }
        }

As you can see, even if the call to the handler was successful, the status is updated with the CrossChainMsgStatus that was passed to the function and it is not automatically marked with SUCCESS.

This should be the case in the cairo function as well but right now the cross_chain_msg_status parameter is ignored.

Recommended Mitigation Steps

Change this line from this:

                if success{
                    state = CrossChainMsgStatus::SUCCESS;

to this:

                if success{
                    state = cross_chain_msg_status;

To be consistent with the solidity implementation.

zvlwwj (Chakra) confirmed

0xsomeone (judge) commented:

The Warden has identified that the status of a cross-chain message is not properly set when a callback is performed on the source chain.

I believe a severity of high is appropriate, as a failed cross-chain transaction would indicate it was processed successfully when this vulnerability manifests.


The original report as published on Code4rena, by 0xAsen. 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 code sets the message status to SUCCESS based solely on the handler callback returning true, instead of using the cross_chain_msg_status parameter that indicates the actual outcome on the destination chain.

Impact

A failed cross-chain message could be incorrectly marked as successful, leading to incorrect state and potential loss of funds or double-spending.

What the attacker needed

Cross-chain message sent; callback received on source chain

The fix

The status should be set to the cross_chain_msg_status parameter when the handler call succeeds, matching the Solidity implementation.

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 you send a message from one blockchain to another, the source chain needs to know if it worked. This code always says 'success' if the callback function runs without crashing, even if the destination chain said it failed. That means a failed transfer could look successful, which is dangerous.

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 0xAsen

View all

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

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.