Unutilized upFrontAmount
in PositionAction::increaseLever
swap potentially causes token locking
#161
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-87
🤖_46_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-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/proxy/PositionAction.sol#L319
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/proxy/PositionAction.sol#L397
Vulnerability details
Impact
In the
PositionAction::increaseLever
function, a user can transfer anupFrontAmount
ofupFrontToken
to the contract. However, if theauxSwap
specified inleverParams
does not use the entireupFrontAmount
, the remaining tokens are left in the contract. This discrepancy can lead to tokens being locked in the contract.This issue arises because the function does not validate that the entire
upFrontAmount
is utilized in theauxSwap
. As a result, any tokens not used in the swap remain in the contract, potentially leading to locked assets.Proof of Concept
In the section
PositionAction#L319-L325
, it can be seen that the transfer ofupFrontAmount
of theupFrontToken
is made. Additionally, when anauxSwap
is specified, it is validated that the sameupFrontToken
is used as theassetIn
token inPositionAction#L314
.Then, in the following section (PositionAction#L394-L400) where the swap is executed, it fails to validate that the entire amount transferred to the contract is used in the swap:
Consider a scenario where a user transfers 10 tokens (
upFrontAmount = 10
) but specifiesleverParams.auxSwap.amount = 9
. The contract will transfer 10 tokens to itself, but only 9 tokens are used in the swap, leaving 1 token locked in the contract.Tools used
Manual review
Recommended Mitigation Steps
To mitigate this issue, the contract should include a validation step to ensure that the entire
upFrontAmount
is utilized in theauxSwap
.function increaseLever( LeverParams calldata leverParams, address upFrontToken, uint256 upFrontAmount, address collateralizer, PermitParams calldata permitParams ) external onlyDelegatecall { ... ... // validate aux swap if it exists if ( leverParams.auxSwap.assetIn != address(0) && (leverParams.auxSwap.swapType != SwapType.EXACT_IN || leverParams.auxSwap.assetIn != upFrontToken || + leverParams.auxSwap.amount != upFrontAmount || leverParams.auxSwap.recipient != self) ) revert PositionAction__increaseLever_invalidAuxSwap(); ... ... }
Assessed type
Context
The text was updated successfully, but these errors were encountered: