# In settlement.cairo::receive_cross_chain_msg - the payload_type can be passed by the user, confusing offchain systems

Chakra settlement's receive_cross_chain_msg omits payload_type from the signed message hash, letting a caller emit events with a forged payload_type and corrupt off-chain node state.

- 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/147
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-chakra%3AH-08
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:access-control vuln:signature-replay

**Target:** Cairo settlement contract cross-chain message receiver
**Root cause:** payload_type is passed as a user parameter but never included in the message_hash used for signature verification, and is only used to emit the CrossChainHandleResult event.
**Steps:**
1. Observe a pending cross-chain message with valid signatures and known cross_chain_msg_id, from_chain, to_chain, from_handler, to_handler, payload.
2. Call `receive_cross_chain_msg(cross_chain_msg_id, from_chain, to_chain, from_handler, to_handler, sign_type, signatures, payload, payload_type)` with all correct values but an arbitrary `payload_type`.
3. Signature check passes since payload_type is not hashed; event `CrossChainHandleResult` is emitted with the attacker-chosen payload_type.
4. Off-chain Chakra nodes/explorer consume the event and record incorrect payload_type.
**How found:** Code reading of receive_cross_chain_msg showed payload_type is only used in the emitted event and absent from the LegacyHash message_hash computation, so signature verification does not bind it.
**Exploitation:** A user or bot front-runs the off-chain system by submitting the receive call with correct signed fields but a manipulated payload_type, causing the emitted event to carry wrong type data that off-chain validators process.
**Insight:** When a signed message hash is built from a subset of function parameters, any parameter excluded from the hash but consumed by off-chain listeners is attacker-controllable; check every event field against the signed tuple.

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

**receive_cross_chain_msg signature with user-supplied payload_type**

```
fn receive_cross_chain_msg(
                ref self: ContractState,
                cross_chain_msg_id: u256,
                from_chain: felt252,
                to_chain: felt252,
                from_handler: u256,
                to_handler: ContractAddress,
                sign_type: u8,
                signatures: Array<(felt252, felt252, bool)>,
                payload: Array<u8>,
                payload_type: u8, <---
            ) -> bool {
```

**Event emission using unvalidated payload_type**

```
self.emit(CrossChainHandleResult{
                    cross_chain_settlement_id: cross_chain_msg_id,
                    from_chain: to_chain,
                    from_handler: to_handler,
                    to_chain: from_chain,
                    to_handler: from_handler,
                    cross_chain_msg_status: status,
                    payload_type: payload_type <---
                });
```

