PositionAction.sol#onCreditFlashLoan
may have leftover tokens after conducting leverParams.auxSwap
.
#87
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
M-33
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_46_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/proxy/PositionAction.sol#L512
Vulnerability details
Impact
PositionAction.sol#onCreditFlashLoan
may have leftover tokens after conductingleverParams.auxSwap
.Bug Description
First, let's inspect how deposit decreaseLever with swap enabled works:
leverParams.primarySwap
and swap collateral to debt token.Now, step 4 is an EXACT_OUT swap, since it is forced to swap the exact amount of debt tokens used to repay the flashloan. However, after step 4, there may be some collateral tokens left, which is the
residualAmount
.If
leverParams.auxSwap
is not enabled, the collateral token is simply sent back to the recipient. However, ifleverParams.auxSwap
is enabled, a swap if performed.The issue here is, the
leverParams.auxSwap
swap is an EXACT_IN swap, and user would hardcode the amount of inTokens used for this swap. There is no way to know the exact amount of collateral tokens left after step 4, so there must still be some collateral tokens leftover after theleverParams.auxSwap
.These leftover tokens are not sent to anybody, and stuck in the contract.
Proof of Concept
N/A
Tools Used
Manual Review
Recommended Mitigation Steps
Send the amount of
IERC20(leverParams.primarySwap.assetIn).balance(address(this))
to residualRecipient to make sure there are no leftovers.Assessed type
Other
The text was updated successfully, but these errors were encountered: