instantUnstake fee can be avoided
The instantUnstake fee calculation rounds down, allowing users to avoid the fee by unstaking small amounts in a loop. An attacker could unstake tokens without paying the liquidity provider fee, though only in small increments per call.
Submitted by skoorch
Users can utilize the instantUnstake function without paying the liquidity provider fee using rounding errors in the fee calculation. This attack only allows for a relatively small amount of tokens to be unstaked in each call, so is likely not feasible on mainnet. However, on low-cost L2s and for tokens with a small decimal precision it is likely a feasible workaround.
Proof of Concept
The instantUnstake fee is handled by sending the user back amount - fee. We can work around the fee by unstaking small amounts (amount < BASIS_POINTS / fee) in a loop until reaching the desired amount.
Recommended Mitigation Steps
Avoid using subtraction to calculate the fee as this causes the fee to be rounded down rather than the amount. I’d propose calculating amount less fee using a muldiv operation over (1 - fee). In this case, the fee is effectively rounded up instead of down, so it can never be 0 unless fee is 0. Uniswapv2 uses a similar solution for their LP fee: https://github.com/Uniswap/v2-core/blob/8b82b04a0b9e696c0e83f8b2f00e5d7be6888c79/contracts/UniswapV2Pair.sol#L180-L182
It might look like the following:
uint256 amountMinusFee = amount * (BASIS_POINTS - fee) / BASIS_POINTS
toshiSat (Yieldy) confirmed and resolved
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the fee is calculated by subtracting a rounded-down fee from the amount, so for small amounts the fee rounds to zero.
Impact
The fee can be avoided, but only for small amounts per call, so it is likely not feasible on mainnet; however, on low-cost L2s and tokens with small decimal precision it is likely feasible.
What the attacker needed
Ability to call instantUnstake repeatedly; low transaction costs (e.g., L2); token with small decimal precision
The fix
The fee should be calculated using a muldiv operation over (1 - fee) so that the fee is rounded up instead of down.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you unstake tokens instantly, a small fee is taken. The code calculates the fee by subtracting a rounded-down number, so for very small unstakes the fee becomes zero. By repeating many tiny unstakes, you can avoid paying the fee altogether.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.