This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
Aymen0909 - Incorrect amount given as input to _handleRebalanceIn
when flashRebalance
is called
#701
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Aymen0909
high
Incorrect amount given as input to
_handleRebalanceIn
whenflashRebalance
is calledSummary
When
flashRebalance
is called, the wrong deposit amount is given to the_handleRebalanceIn
function as the wholetokenInBalanceAfter
amount is given as input instead of the delta valuetokenInBalanceAfter - tokenInBalanceBefore
, this will result in an incorrect rebalance operation and can potentialy lead to a DOS due to the insufficient amount error.Vulnerability Detail
The issue occurs in the
flashRebalance
function below :As we can see from the code above, the function executes a flashloan in order to receive th tokenIn amount which should be the difference between
tokenInBalanceAfter
(balance of the contract after the flashloan) andtokenInBalanceBefore
(balance of the contract before the flashloan) :tokenInBalanceAfter - tokenInBalanceBefore
.But when calling the
_handleRebalanceIn
function the wrong deposit amount is given as input, as the total balancetokenInBalanceAfter
is used instead of the received amounttokenInBalanceAfter - tokenInBalanceBefore
.Because the
_handleRebalanceIn
function is supposed to deposit the input amount to the destination vault, this error can result in sending a larger amount of funds to DV then what was intended or this error can cause a DOS of theflashRebalance
function (due to the insufficient amount error when performing the transfer to DV), all of this will make the rebalance operation fail (or not done correctely) which can have a negative impact on the LMPVault.Impact
See summary
Code Snippet
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/libs/LMPDebt.sol#L185-L215
Tool used
Manual Review
Recommendation
Use the correct received tokenIn amount
tokenInBalanceAfter - tokenInBalanceBefore
as input to the_handleRebalanceIn
function :The text was updated successfully, but these errors were encountered: