Inadequate update of repayment amount post-swap #369
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-526
🤖_31_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/proxy/PositionAction.sol#L589
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/proxy/PositionAction.sol#L575
Vulnerability details
Inadequate update of repayment amount post-swap
Lines of code
Impact
In the
PositionAction
contract, specifically atPositionAction#L589
, the repayment amount used in the debt modification process does not account for potential changes resulting from swap operations. Instead, it uses the initialcreditParams.amount
, which may not reflect the correct amount after a swap. This discrepancy can lead to incorrect debt repayment calculations, causing financial inconsistencies and potential losses for users due partial repayments.In this code, the
amount
variable fromPositionAction#L575
is intended to capture the correct repayment amount after any swap operation. However, the subsequentforceApprove
andmodifyCollateralAndDebt
calls atPositionAction#L583
andPositionAction#L589
, respectively, usecreditParams.amount
instead of the updatedamount
. This oversight can lead to incorrect repayment amounts being processed.When the
swap
returns an amount ofunderlying
greater thancreditParams.amount
, it will result in a remaining amount left in the contract because the call tomodifyCollateralAndDebt
will usecreditParams.amount
. Conversely, when the amount returned from the swap is less thancreditParams.amount
, the repayment transaction will be reversed.Proof of Concept
The following test demonstrates how the contract retains the unused amount from the swap when the swap is executed and the underlying is greater than
creditParams.amount
.The following test shows how the repayment transaction is reversed when, after the swap, the amount of underlying is less than
creditParams.amount
.Tools used
Manual review
Recommended Mitigation Steps
To mitigate this issue and ensure accurate debt repayment calculations, the code should be updated to use the
amount
variable, which reflects the actual amount post-swap. This change will ensure that the repayment process correctly accounts for any adjustments resulting from swaps.Assessed type
Context
The text was updated successfully, but these errors were encountered: