Invalid handling of risdual amount in PositionAction::onCreditFlashLoan
, forcing it to revert
#6
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
🤖_14_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-10-loopfi/blob/main/src/proxy/PositionAction.sol#L492-L499
Vulnerability details
Description
Users can call
PositionAction::decreaseLever
through a proxy, to "Decrease the leverage of a position by taking out a credit flash loan to withdraw and sell collateral", after it is called, the flash loan lender sends the credit and callsonCreditFlashLoan
, which handles all that logic. When doing so, users are supposed to swap their collateral withdrawn into debt tokens so that the flash loan can be repaid.The protocol tries to handle the residual amount from the swap (swapped - paid debt), by trying to repay extra debt for the designated position, using:
However, this is invalid for 2 main reasons:
primarySwap.amount
.decreaseLever
the TX will revert, as it'll try to repay some nonexistent debt.Proof of Concept
Add the following test in
src/test/integration/PositionAction20.lever.t.sol
:Logs:
Recommended Mitigation Steps
Rather than using the residual amount to repay excess debt (that might not even exist), transfer it to the designated residual recipient. Alternatively, check if the user still has any remaining debt. If they do, use the residual to repay it; otherwise, transfer the residual amount to the recipient.
Assessed type
DoS
The text was updated successfully, but these errors were encountered: