# Inconsistent Handler Validation Behavior in Cairo ERC20Handler's Cross-Chain Callback

Cairo ERC20Handler's receive_cross_chain_callback asserts on invalid handler instead of returning false, reverting and leaving cross-chain transactions stuck Pending.

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

**Target:** Cairo ERC20Handler receive_cross_chain_callback / Settlement cross-chain callback
**Root cause:** Cairo implementation uses assert for handler whitelist validation, reverting on invalid handler, whereas Solidity returns false so Settlement can mark the tx Failed.
**Steps:**
1. Settlement calls receive_cross_chain_callback on Cairo ERC20Handler with a from_handler not in support_handler whitelist
2. `assert(self.support_handler.read((from_chain, from_handler)) && ...)` fails and reverts the whole call
3. Settlement's processCrossChainCallback cannot set status to Failed, leaving create_cross_txs[txid] Pending indefinitely
**How found:** Cross-implementation comparison: author diffed Cairo vs Solidity receive_cross_chain_callback and noticed Solidity returns false while Cairo asserts, tracing the divergence into Settlement's Failed-status handling.
**Exploitation:** Not a direct theft vector; an invalid/removed handler causes the callback to revert, blocking Settlement from transitioning the cross-chain tx out of Pending, causing stuck state and potential DoS of cross-chain operations.
**Insight:** When a protocol ships the same logic in two languages (Solidity + Cairo), diff the error-handling paths: a revert vs return-false divergence can strand state machines that rely on the boolean to mark Failed.

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

**Cairo receive_cross_chain_callback assert on handler**

```
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');
```

**Solidity receive_cross_chain_callback returns false**

```
function receive_cross_chain_callback(
    uint256 txid,
    string memory from_chain,
    uint256 from_handler,
    CrossChainMsgStatus status,
    uint8 /* sign_type */,
    bytes calldata /* signatures */
) external onlySettlement returns (bool) {
    if (is_valid_handler(from_chain, from_handler) == false) {
        return false;
    }
```

