Skip to content

Commit

Permalink
🪲 [M-3] fix potential overflow in maxTotalUnlock()
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIryna committed May 12, 2024
1 parent 6483713 commit 423ed33
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/strategies/CLeverCVXStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,18 @@ contract CleverCvxStrategy is ICleverCvxStrategy, TrackedAllowances, Ownable, UU
uint256 repayAmount = clevCvxAvailable.mulDiv(CLEVER_FEE_PRECISION, CLEVER_FEE_PRECISION + repayRate);

(uint256 totalDeposited,,, uint256 totalBorrowed,) = CLEVER_CVX_LOCKER.getUserInfo(address(this));
// decrease borrowed amount
totalBorrowed -= repayAmount;
maxUnlock = totalDeposited - totalBorrowed.mulDiv(CLEVER_FEE_PRECISION, reserveRate);

if (totalBorrowed > repayAmount) {
// Decrease borrowed amount
unchecked {
totalBorrowed = totalBorrowed - repayAmount;
}
maxUnlock = totalDeposited - totalBorrowed.mulDiv(CLEVER_FEE_PRECISION, reserveRate);
} else {
// Amount of clevCVX in Furnace can be greater than the borrowed amount only if
// CVX is swapped for clevCVX and deposited to Furnace, rather than locked in CleverLocker.
maxUnlock = totalDeposited;
}

if (maxUnlock > unlockObligations) {
unchecked {
Expand Down

0 comments on commit 423ed33

Please sign in to comment.