Submitted by nonseodion
When a user enters or exits a PowerFarm, he specifies an allowed spread. The spread specifies the minimum value of the position allowed at the end of the transaction.
E.g. a spread of 105% on a position with a value of $1000 ensures the value does not fall below $950.
1000 * (200-105) / 100 = 950
When a user opens a position on Arbitrum, the ENTRY_ASSET is converted to WETH on UniswapV3. The second argument in line 434 specifies the minimum value for the swap. The spread is applied to this argument. Hence, the _depositAmount in line 432 cannot go less than what the spread allows.
PendlePowerFarmLeverageLogic.sol#L423-L440
The value at the end of the transaction is checked in line 508 below to ensure it does not go below the allowed spread. The ethValueBefore is calculated from _depositAmount in line 489. Note that if the swap on Uniswap occurred the _depositAmount may already be the minimum value. The ethValueAfter is scaled with the allowed spread in line 501.
PendlePowerFarmLeverageLogic.sol#L485-L505
Thus the comparison in line 508 may compare ethValueAfter with the minimum value of the spread instead of the value of the initial deposit. With this implementation, if the spread for a $1000 transaction is 105%, the minimum value after the transaction becomes $902.5.
(1000 * 95 / 100) * (95/100) = 902.5. The user can lose $47.5 (950-902.5).
Note: In the implementation, the value at the end is scaled up instead of the value at the beginning being scaled down like the examples show. Hence, the actual minimum value is lesser i.e. ~$904.76 (950/1.05). This is a different bug.
Consider storing the actual deposit and using it to calculate ethValueBefore.
PendlePowerFarmLeverageLogic.sol#L423-L488
Uniswap
Wise Lending commented:
