# Does not check if to_chain and to_handler is whitelisted in cross_chain_erc20_settlement

Chakra's cross_chain_erc20_settlement omits whitelist checks on to_chain/to_handler, so funds sent to an invalid handler get stuck pending with no failure callback.

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

**Target:** Solidity cross-chain settlement Handler contract
**Root cause:** cross_chain_erc20_settlement validates to_handler != 0 but never checks is_valid_handler(to_chain, to_handler), so messages can be routed to unpaired chains/handlers.
**Steps:**
1. Call `Handler.cross_chain_erc20_settlement(to_chain, to_handler, to_token, to, amount)` with a to_handler that is not whitelisted (e.g. a non-contract address).
2. Tokens are locked/burned on the source chain and a cross-chain message is emitted.
3. On the destination chain, `Settlement.receive_cross_chain_msg` calls `ISettlementHandler(to_handler).receive_cross_chain_msg(...)`, which reverts for a non-contract address, so no `CrossChainHandleResult` event is emitted.
4. If the handler is a contract but not whitelisted, it returns false; the failure callback to the source chain is rejected by `receive_cross_chain_callback` because `is_valid_handler(from_chain, from_handler)` is false.
5. The source tx remains Pending forever and locked/burned funds are unrecoverable.
**How found:** Code review of cross_chain_erc20_settlement noticed only non-zero checks on to_handler, then traced the destination receive_cross_chain_msg and source receive_cross_chain_callback paths to confirm the failure cannot be reported back.
**Exploitation:** A user (or attacker inducing a user) submits a settlement with an unwhitelisted to_chain/to_handler; the source-side lock/burn succeeds but the destination handler call reverts or returns false, and the failure callback is filtered out by the whitelist check, leaving funds permanently stuck.
**Insight:** When a protocol has a whitelist enforced on inbound messages, check whether the outbound path enforces the same whitelist; asymmetric validation creates unrecoverable stuck states rather than clean reverts.

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

**cross_chain_erc20_settlement missing whitelist check**

```
function cross_chain_erc20_settlement(
    string memory to_chain,
    uint256 to_handler,
    uint256 to_token,
    uint256 to,
    uint256 amount
) external {
    require(amount > 0, "Amount must be greater than 0");
    require(to != 0, "Invalid to address");
@>  require(to_handler != 0, "Invalid to handler address");
    require(to_token != 0, "Invalid to token address");

    if (mode == SettlementMode.MintBurn) {
        _erc20_lock(msg.sender, address(this), amount);
    } else if (mode == SettlementMode.LockUnlock) {
        _erc20_lock(msg.sender, address(this), amount);
    } else if (mode == SettlementMode.LockMint) {
        _erc20_lock(msg.sender, address(this), amount);
    } else if (mode == SettlementMode.BurnUnlock) {
        _erc20_burn(msg.sender, amount);
    }
    ...
}
```

**receive_cross_chain_msg calls unvalidated to_handler**

```
bool result = ISettlementHandler(to_handler).receive_cross_chain_msg( // this will be reverted
        txid,
        from_chain,
        from_address,
        from_handler,
        payload_type,
        payload,
        sign_type,
        signatures
    );
  
    CrossChainMsgStatus status = CrossChainMsgStatus.Failed;
    if (result == true) {
        status = CrossChainMsgStatus.Success;
        receive_cross_txs[txid].status = CrossChainMsgStatus.Success;
    } else {
@>      receive_cross_txs[txid].status = CrossChainMsgStatus.Failed;
    }
```

