PositionAction.sol#decreaseLever with EXACT_IN primary swaps would always brick if swapFee is non-zero. #8
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-27
🤖_primary
AI based primary recommendation
🤖_14_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
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-10-loopfi/blob/main/src/proxy/PositionAction.sol#L488
Vulnerability details
Impact
PositionAction.sol#decreaseLever with EXACT_IN primary swaps would always brick if swapFee is non-zero.
Bug Description
Note: This is a new issue that was introduced by the latest code diff (Doesn't exist in the 2024-07 Loopfi contest).
When performing decreaseLever, in the flashloan fallback
onCreditFlashLoan()
, we need to payoff the flashloan along with the fees.For EXACT_IN primary swaps, if extra underlying tokens are swapped out, they are sent back to the vault as payed off debt. However, the issue here is when calculating the residual amount, it does not take flashloan fees into account.
The buggy line is
uint256 residualAmount = swapAmountOut - subDebt;
, wheresubDebt
is the amount of token taken from flashloan, but fees also need to be subtracted here.Proof of Concept
N/A
Tools Used
Manual Review
Recommended Mitigation Steps
Change to
uint256 residualAmount = swapAmountOut - subDebt - fee;
Assessed type
DoS
The text was updated successfully, but these errors were encountered: