# Anyone can manipulate user nonce (nonce_manager) in settlement contract

ChakraSettlement.send_cross_chain_msg is external and increments nonce_manager[from_address] for any address, letting anyone desync a victim's settlement nonce from the handler nonce and corrupt txid generation.

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

**Target:** ChakraSettlement.sol send_cross_chain_msg / nonce_manager mapping
**Root cause:** send_cross_chain_msg is externally callable with an arbitrary from_address and increments nonce_manager[from_address] without access control or binding to the caller, so the settlement nonce is keyed only by user address rather than (handler, user).
**Steps:**
1. Deploy handler/settlement fixture; user calls `cross_chain_erc20_settlement(toChain, toHandler, toToken, receiverU256, amount)` after approving tokens.
2. Observe `nonce_manager[sender]` in settlement == 1 and handler nonce == 1.
3. Attacker calls `settlmentInstance.send_cross_chain_msg(toChain, senderAddress, toHandler, 5, "0x616263")` directly.
4. Settlement `nonce_manager[sender]` becomes 2 while handler nonce stays 1; assert nonceAfter != handlerNonce.
**How found:** Code reading: noticed send_cross_chain_msg is external with no access control and increments nonce_manager[from_address] where from_address is a caller-supplied argument, not msg.sender; hypothesized anyone could bump another user's nonce and confirmed with a Hardhat test.
**Exploitation:** Attacker directly invokes the external settlement function with the victim's address as from_address, incrementing the victim's settlement nonce and emitting a CrossChainMsg with a txid the victim never authorized, desynchronizing handler vs settlement nonces and confusing off-chain txid processing.
**Insight:** When a nonce/txid is keyed by a caller-supplied address argument rather than msg.sender, check whether the incrementing function is externally reachable; nonce mappings should be namespaced by (caller/handler, user) so third parties cannot advance someone else's counter.

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

**Attacker calls send_cross_chain_msg to bump victim nonce**

```
await(settlmentInstance.connect(attacker).send_cross_chain_msg(
                toChain,
                senderAddress, // sender address to target
                toHandler,
                payloadType,
                payload,
            ));
            const nonceAfter = await settlmentInstance.nonce_manager(senderAddress);
```

