# excess funds will not always be refunded to borrower when they are withdrawing

Borrowing._withdraw only refunds excess ETH when downsideProtected is zero, so borrowers whose downside is covered locally lose their fee overpayment permanently.

- Payout: Audit contest
- Severity: medium
- Program: Autonomint
- Found by: 0x23r0
- Disclosed: 2024-11-26
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/890
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AM-28
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:fee-bypass

**Target:** borrowing.sol _withdraw / _getDownsideFromCDS
**Root cause:** _withdraw refunds msg.value - fee.nativeFee only in the else branch (downsideProtected == 0); when downsideProtected > 0 but CDS already holds enough funds, _getDownsideFromCDS takes the local branch and never forwards or refunds the fee ETH.
**Steps:**
1. Borrower calls _withdraw with msg.value covering fee.nativeFee plus excess.
2. Position has result.downsideProtected > 0, so the refund branch at line 691 is skipped.
3. _getDownsideFromCDS sees cds.getTotalCdsDepositedAmount() >= downsideProtected, takes the else branch (updateDownsideProtected) and makes no cross-chain call.
4. The fee ETH is neither forwarded nor refunded; it stays stuck in the borrowing contract with no sweep function.
**How found:** Code reading of the refund branch: noticed the developer assumed downsideProtected > 0 implies a cross-chain call, then checked _getDownsideFromCDS and saw the local-settlement else branch that consumes no ETH.
**Insight:** When a refund is gated on a state flag, verify every downstream branch that flag can take actually spends the funds; here 'needs downside protection' did not imply 'needs cross-chain fee'.

