# The user overpays the USDA amount for downside protection while withdrawing

Autonomint's withdraw() charges users the full borrowerDebt instead of deducting downsideProtected, so users overpay USDA and the protocol's downside protection is never honored.

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

**Target:** BorrowLib.withdraw() lending/withdrawal logic
**Root cause:** The transferFrom amount adds discountedCollateral and full borrowerDebt without subtracting downsideProtected, so burnValue + transfer amount equals borrowerDebt rather than borrowerDebt minus downsideProtected.
**Steps:**
1. User opens a borrow position with collateral and downside protection enabled.
2. User calls withdraw() passing depositDetail and params.
3. Observe burnValue = borrowedAmount - discountedCollateral is burned from user.
4. Observe transferFrom pulls (borrowerDebt - borrowedAmount) + discountedCollateral to treasury.
5. Sum equals borrowerDebt, so downsideProtected is never deducted; user overpays USDA.
**How found:** Code reading of withdraw() accounting: summing burnValue and the transferFrom amount algebraically reduces to borrowerDebt, revealing downsideProtected is omitted from the deduction.
**Insight:** When auditing withdrawal/repay flows, algebraically sum all token pulls and burns and compare against the intended net debt; a term that cancels out (like discountedCollateral) often hides a missing deduction such as downsideProtected.

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

**withdraw() burn and transfer of USDA**

```
uint256 burnValue = depositDetail.borrowedAmount - discountedCollateral;

        // Burn the USDa from the Borrower
        bool success = interfaces.usda.burnFromUser(msg.sender, burnValue);
        if (!success) revert IBorrowing.Borrow_BurnFailed();

        ...

        //Transfer the remaining USDa to the treasury
878     bool transfer = interfaces.usda.transferFrom(
            msg.sender,
            address(interfaces.treasury),
            (borrowerDebt - depositDetail.borrowedAmount) + discountedCollateral
        );
```

**Fix deducting downsideProtected from transfer**

```
(borrowerDebt - depositDetail.borrowedAmount) + discountedCollateral
+           (borrowerDebt - depositDetail.borrowedAmount - downsideProtected) + discountedCollateral
```

