When liquidating positions with bad debt, reporting the bad debt to the FeeManagar can artificially inflate the totalBadDebtETH causing an incorrect accounting and making impossible to take down the totalBadDebtETH to 0
Audit: 2024-02-wise-lending-findings
Severity: HIGH

# Lines of code

https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/WiseSecurity/WiseSecurity.sol#L427-L429
https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/FeeManager/FeeManager.sol#L663-L675
https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/FeeManager/FeeManager.sol#L689-L699


# Vulnerability details

## Impact
All the fees collected from the FEE_MANAGER_NFT will be unclaimable on the FeeManager contract because the totalBadDebtETH will never be able to go back to 0.

## Proof of Concept
Liquidations in the WiseLending market are designed to allow the liquidators to liquidate debt from a specific pool and receive the liquidation payment on a different pool (if they want it, they can also receive the liquidation payment in the same type of poolToken if the position has collateralized deposits on such a pool).
- For example, if a position has collateralized deposits on PoolA and PoolB, and has loans on PoolA and PoolC.
  - The liquidator can liquidate the debt of the PoolA and receive tokens from the PoolB as the liquidation payment for liquidating the debt of the poolA.

When a liquidation is done, after all the lending and borrowing storage variables have been updated according to the amount of debt repaid by the liquidator, the liquidation logic checks if there is any bad debt in the position by calling the [`WISE_SECURITY.checkBadDebtLiquidation() function`](https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/WiseSecurity/WiseSecurity.sol#L405-L436), any bad debt (the difference between the `overallETHBorrowBare - overallETHCollateralsBare`) is reported to the FeeManager, to do this, two functions are called, the [`FEE_MANAGER.increaseTotalBadDebtLiquidation() function`](https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/FeeManager/FeeManager.sol#L494-L508) and the [`FEE_MANAGER.setBadDebtUserLiquidation() function`](https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/FeeManager/FeeManager.sol#L514-L531).
>
```
function checkBadDebtLiquidation(
    uint256 _nftId
)
    external
    onlyWiseLending
{

    uint256 bareCollateral = overallETHCollateralsBare(
        _nftId
    );

    uint256 totalBorrow = overallETHBorrowBare(
        _nftId
    );

    //@audit-info => If the total leftover debt is lower than the total leftover collateral, no bad debt, returns!
    if (totalBorrow < bareCollateral) {
        return;
    }

    //@audit-info => If the total leftover debt is greater than the total leftover collateral, bad debt has been generated!
    unchecked {
        uint256 diff = totalBorrow
            - bareCollateral;

        FEE_MANAGER.increaseTotalBadDebtLiquidation(
            diff
        );

        FEE_MANAGER.setBadDebtUserLiquidation(
            _nftId,
            diff
        );
    }
}
```

- The [`FEE_MANAGER.increaseTotalBadDebtLiquidation() function`](https://github.com/code-423n4/2024-02-wise-lendin