Skip to content

Commit

Permalink
refactor: safe cast badDebt
Browse files Browse the repository at this point in the history
Signed-off-by: MathisGD <[email protected]>
  • Loading branch information
MathisGD authored Nov 8, 2023
1 parent a937fb0 commit 0e8174f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Morpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,14 @@ contract Morpho is IMorpho {
uint256 badDebtShares;
if (position[id][borrower].collateral == 0) {
badDebtShares = position[id][borrower].borrowShares;
// Safe "unchecked" cast since the value is smaller than totalBorrowAssets.
uint128 badDebt = uint128(
UtilsLib.min(
market[id].totalBorrowAssets,
badDebtShares.toAssetsUp(market[id].totalBorrowAssets, market[id].totalBorrowShares)
)
uint256 badDebt = UtilsLib.min(
market[id].totalBorrowAssets,
badDebtShares.toAssetsUp(market[id].totalBorrowAssets, market[id].totalBorrowShares)
);
market[id].totalBorrowAssets -= badDebt;
market[id].totalSupplyAssets -= badDebt;
market[id].totalBorrowShares -= uint128(badDebtShares); // Safe "unchecked" cast.

market[id].totalBorrowAssets -= badDebt.toUint128();
market[id].totalSupplyAssets -= badDebt.toUint128();
market[id].totalBorrowShares -= badDebtShares.toUint128();
position[id][borrower].borrowShares = 0;
}

Expand Down

0 comments on commit 0e8174f

Please sign in to comment.