# Multiple issues with retrySettlement() and retrieveDeposit() will cause loss of users' bridging deposits

retrySettlement() and retrieveDeposit() in Maia's BranchBridgeAgent omit native-token wrapping and a fallback handler, so failed settlements can't be retried and user bridging deposits are lost.

- Payout: Contest reward
- Severity: high
- Program: Maia DAO Ecosystem
- Credited: peakbolt
- Disclosed: 2023-09-18
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-05-maia-findings/issues/356
- Library page: https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-22
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:regression technique:source-review vuln:accounting-error vuln:business-logic

**Target:** BranchBridgeAgent settlement retry/retrieve functions (Ulysses omnichain)
**Root cause:** retrySettlement() and retrieveDeposit() never call wrappedNativeToken.deposit() to wrap the native gas paid by users, so the subsequent _depositGas() fails; retrySettlement() also redundantly increments depositNonce, and anyFallback() lacks handlers for flags 0x07/0x08.
**Steps:**
1. Deploy test in RootTest.t.sol; mint mock asset and hTokens to user.
2. Enable MockAnycall fallback mode and call `callOutSignedAndBridge{value: 1e11}(packedData, depositInput, remoteExecutionGas)` to create a failed settlement.
3. Disable fallback mode, call `testFallback()`; confirm settlement status == Failed.
4. Call `retrySettlement{value: 7.9e9}(settlementNonce, 1.6e9)`; observe failure because msg.value is not wrapped before `_depositGas()` at BranchBridgeAgent.sol#L929-L931.
5. Note depositNonce was incremented at L426, mismatching `_createGasDeposit` at L836, and anyFallback() has no case for 0x07/0x08.
**How found:** Code review comparing retrySettlement()/retrieveDeposit() against retryDeposit(), which correctly wraps native token for gas (L441-L447); noticed missing wrappedNativeToken.deposit(), a stray depositNonce increment, and absent fallback flags in anyFallback().
**Exploitation:** No attacker profit path; the flaw is a functional defect. Users who need to retry a failed settlement or retrieve a deposit cannot, and their bridging deposits plus unwrapped gas remain stuck in BranchBridgeAgent with no withdrawal function.
**Insight:** When auditing bridge retry/retrieve paths, diff each recovery function against its sibling success path (e.g. retryDeposit) for missing token-wrapping, nonce mutations, and fallback flag coverage; recovery functions are rarely exercised and drift from the main flow.
