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

Chakra settlement.cairo ignores the callback's cross_chain_msg_status and marks failed cross-chain messages as SUCCESS on the source chain.

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

**Target:** Cairo settlement contract receive_cross_chain_callback
**Root cause:** The Cairo settlement contract derives the stored status solely from the handler call's boolean return (always true unless reverting), ignoring the cross_chain_msg_status parameter that carries the destination-chain outcome.
**Steps:**
1. Send a cross-chain message that fails on the destination chain, producing a callback with cross_chain_msg_status == FAILED.
2. Callback reaches settlement.cairo receive_cross_chain_callback, which calls handler.receive_cross_chain_callback.
3. Handler validates handlers and returns true without reverting.
4. Settlement sets state = SUCCESS because success is true, discarding cross_chain_msg_status.
5. created_tx is written with tx_status SUCCESS despite the failed destination execution.
**How found:** Compared the Cairo settlement implementation against the Solidity processCrossChainCallback, noticing Solidity assigns create_cross_txs[txid].status = status while Cairo hardcodes SUCCESS on handler success, and that the handler always returns true unless reverting.
**Exploitation:** A user bridges tokens; the destination-chain execution fails so no tokens are delivered, but the source-chain record is marked SUCCESS, misrepresenting the failed transfer as completed.
**Insight:** When a port exists between two language implementations (Cairo vs Solidity), diff the status/state assignment logic line by line; a handler's boolean return often reflects only call success, not the semantic outcome carried in a separate status parameter.

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

**Cairo callback status update ignoring cross_chain_msg_status**

```
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,
```

**Solidity correct processCrossChainCallback reference implementation**

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

