# Handler's receive_cross_chain_callback() will always set the tx_status to SETTLED on source chain & burn the tokens (MintBurn Mode) even when the msg fails on destination

Chakra's Cairo Settlement callback ignores cross_chain_msg_status, always marking MintBurn bridge txs SETTLED and burning source tokens even when destination execution failed.

- Payout: Audit contest
- Severity: high
- Program: Chakra
- Found by: Shaheen
- Disclosed: 2025-02-20
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-08-chakra-findings/issues/84
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-chakra%3AH-12
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Settlement.cairo receive_cross_chain_callback bridge handler
**Root cause:** receive_cross_chain_callback ignores the cross_chain_msg_status argument and unconditionally writes tx_status=SETTLED and burns tokens in MintBurn mode, unlike the Solidity implementation which branches on Success/Failed.
**Steps:**
1. Validator calls `receive_cross_chain_callback(cross_chain_msg_id, from_chain, to_chain, from_handler, to_handler, cross_chain_msg_status)` on Settlement.cairo with status=Failed
2. Function asserts to_handler and caller==settlement and handler support
3. In MintBurn mode it calls `erc20.burn_from(get_contract_address(), created_tx.amount)` unconditionally
4. It writes created_tx with `tx_status: CrossChainTxStatus::SETTLED` and returns true, ignoring the Failed status
**How found:** Compared the Cairo handler against the Solidity reference implementation, noticing the Solidity code branches on CrossChainMsgStatus.Success/Failed while the Cairo version hardcodes SETTLED and burns unconditionally.
**Exploitation:** A destination-chain execution failure triggers the callback with a non-SUCCESS status; the source-chain handler still burns the locked/minted tokens and records SETTLED, so the user's funds are destroyed while the bridge reports success, with no refund path.
**Insight:** When a protocol is ported across languages (Solidity to Cairo), diff the ported handler against the reference: status/error branches are the most commonly dropped logic, turning failure paths into fund-loss paths.

## Proof of concept (copied exactly from the original report)

**Cairo receive_cross_chain_callback ignoring status and always SETTLED**

```
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);
            ///@audit-issue M cross_chain_msg_status not checked like in the solidity instance, this will always set tx_status as settled and return true and never Failed!
            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;
        }
```

**Solidity reference checking status before burn**

```
if (status == CrossChainMsgStatus.Success) {
            if (mode == SettlementMode.MintBurn) {
                _erc20_burn(address(this), create_cross_txs[txid].amount);
            }

            create_cross_txs[txid].status = CrossChainTxStatus.Settled;
        }

        if (status == CrossChainMsgStatus.Failed) {
            create_cross_txs[txid].status = CrossChainTxStatus.Failed;
        }
```

