# The `liquidationType1` function in the borrowLiquidation contract reverts unexpectedly when calculating the yields

liquidationType1 underflows and reverts when weETH/ETH exchange rate drops slightly, blocking liquidation of eligible positions.

- 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/519
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AM-12
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** borrowLiquidation contract yield calculation
**Root cause:** depositedAmountInETH is stored at deposit-time exchange rate; at liquidation the yield formula divides by the current (possibly lower) exchange rate, producing a value exceeding depositedAmount and underflowing the subtraction.
**Steps:**
1. Deposit 2e18 WeETH at exchangeRate 1029750180160445400; stored depositedAmount=2e18, depositedAmountInETH=2059500360320890800
2. Exchange rate drops 1 wei to 1029750180160445399
3. Liquidation computes `yields = depositedAmount - (depositedAmountInETH * 1 ether / exchangeRate)` = 2e18 - 2000000000000000001 = -1
4. Subtraction underflows, liquidationType1 reverts
**How found:** Noticed the yield formula divides a deposit-time ETH value by the current exchange rate, and reasoned that any downward tick in weETH/ETH (observed on Chainlink Dec 18 vs Dec 21) makes the quotient exceed the stored token amount.
**Insight:** When a contract stores a value converted at deposit-time oracle rate and later re-divides by the live rate, any rate decrease causes underflow; check every liquidation/withdrawal path for such asymmetric rate assumptions.

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

**Yield calculation underflow revert line**

```
uint256 yields = depositDetail.depositedAmount - ((depositDetail.depositedAmountInETH * 1 ether) / exchangeRate);
```

**Numeric PoC showing -1 underflow**

```
yields = 2e18 - ((2059500360320890800 * 1 ether) / 1029750180160445399)  -->   `-1`

Substitute values:

yields = 2e18 - 2000000000000000001 = -1 (revert the liquidation)
```

