File: src/PoolV3.sol
529:     function repayCreditAccount(
530:         uint256 repaidAmount,
531:         uint256 profit,
532:         uint256 loss
533:     )
...:
...: // ------- some code ------- //
...:
548:         if (profit > 0) {
549:             _mint(treasury, convertToShares(profit));
550:         } else if (loss > 0) {                         <@(1) //we're in this case when there's a loss
551:             address treasury_ = treasury;
552:             uint256 sharesInTreasury = balanceOf(treasury_);
553:             uint256 sharesToBurn = convertToShares(loss);
554:                if (sharesToBurn > sharesInTreasury) { <@(2) //sharesToBurn are capped to sharesInTreasury
555:                 unchecked {
556:                     emit IncurUncoveredLoss({
557:                         creditManager: msg.sender,
558:                         loss: convertToAssets(sharesToBurn - sharesInTreasury)
559:                     });
560:                 }
561:                     sharesToBurn = sharesInTreasury; <@(2) 
562:             }
563:                _burn(treasury_, sharesToBurn);
564:         }
Ran 1 test for src/test/unit/CDPVault.t.sol:CDPVaultTest
[PASS] testAudit_collateralDebt() (gas: 3980542)
Logs:
  ----------  initial state with borrowed assets ----------
  PoolV3 shares balance: 1e20
  PoolV3 ETH balance: 1e20
  virtualDebt before: 8e19
  virtualDebt after (accrued interest): 1.03138823529411764705e20

  ----------  state after bad debt liquidation ----------
  PoolV3 shares balance: 1e20
  PoolV3 ETH balance: 9e19
  ... Still 100 shares in PoolV3, but only 90 ETH left for Alice and Bob ...

  ----------  state after Alice withdraw ----------
  PoolV3 shares balance: 5e19
  PoolV3 ETH balance: 4e19
  ... Bob has 50 shares but can only withdraw 40 ETH ...

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 5.32ms (2.27ms CPU time)
    /// @dev Internal conversion function (from assets to shares) with support for rounding direction
    /// @dev Pool is not vulnerable to the inflation attack, so the simplified implementation w/o virtual shares is used
    function _convertToShares(uint256 assets, Math.Rounding rounding) internal returns (uint256 shares) {
        uint256 supply = totalSupply();
          if (supply < totalAssets()) {
               shares = (assets == 0 || supply == 0) ? assets : assets.mulDiv(supply, totalAssets(), rounding);
          }
          else {
               shares = assets;
          }
        return shares; 
    }

    /// @dev Internal conversion function (from shares to assets) with support for rounding direction
    /// @dev Pool is not vulnerable to the inflation attack, so the simplified implementation w/o virtual shares is used
    function _convertToAssets(uint256 shares, Math.Rounding rounding) internal returns (uint256 assets) {
        uint256 supply = totalSupply();
          if (supply < totalAssets()) {
               assets = (supply == 0) ? shares : shares.mulDiv(totalAssets(), supply, rounding);
          }
          else {
               assets = shares;
          }
        return assets; 
    }
