Skip to content
Business logic Audit finding Intermediate

WithdrawPeriphery#_convertToToken slippage control is broken for any token other than USDC

The slippage calculation in WithdrawPeriphery always returns a value with 6 decimals, which is correct for USDC but ineffective for tokens with 18 decimals like WETH or WBTC. This means users withdrawing those tokens have virtually no slippage protection and could lose funds.

clems4ever Follow with 0x52

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-rage-trade-judging/issues/55

Found by

clems4ever, 0x52

Summary

WithdrawPeriphery allows the user to redeem junior share vaults to any token available on GMX, applying a fixed slippage threshold to all redeems. The slippage calculation always returns the number of tokens to 6 decimals. This works fine for USDC but for other tokens like WETH or WBTC that are 18 decimals the slippage protection is completely ineffective and can lead to loss of funds for users that are withdrawing.

Vulnerability Detail

function _convertToToken(address token, address receiver) internal returns (uint256 amountOut) {
    // this value should be whatever glp is received by calling withdraw/redeem to junior vault
    uint256 outputGlp = fsGlp.balanceOf(address(this));

    // using min price of glp because giving in glp
    uint256 glpPrice = _getGlpPrice(false);

    // using max price of token because taking token out of gmx
    uint256 tokenPrice = gmxVault.getMaxPrice(token);

    // apply slippage threshold on top of estimated output amount
    uint256 minTokenOut = outputGlp.mulDiv(glpPrice * (MAX_BPS - slippageThreshold), tokenPrice * MAX_BPS);

    // will revert if atleast minTokenOut is not received
    amountOut = rewardRouter.unstakeAndRedeemGlp(address(token), outputGlp, minTokenOut, receiver);
}

WithdrawPeriphery allows the user to redeem junior share vaults to any token available on GMX. To prevent users from losing large amounts of value to MEV the contract applies a fixed percentage slippage. minToken out is returned to 6 decimals regardless of the token being requested. This works for tokens with 6 decimals like USDC, but is completely ineffective for the majority of tokens that aren't.

Impact

Users withdrawing tokens other than USDC can suffer huge loss of funds due to virtually no slippage protection

Code Snippet

https://github.com/sherlock-audit/2022-10-rage-trade/blob/main/dn-gmx-vaults/contracts/periphery/WithdrawPeriphery.sol#L147-L161

Tool used

Manual Review

Recommendation

Adjust minTokenOut to match the decimals of the token:

    uint256 minTokenOut = outputGlp.mulDiv(glpPrice * (MAX_BPS - slippageThreshold), tokenPrice * MAX_BPS);
+   minTokenOut = minTokenOut * 10 ** (token.decimals() - 6);

Discussion

0xDosa

Agreed on the issue but the severity level should be medium since loss of funds is not possible. While swapping on GMX, there is min-max spread and fees but no slippage due to them using chainlink oracles for pricing the tokens, so a direct sandwich attack would not work.

Evert0x

Downgrading to medium

0xDosa

Fix PR: https://github.com/RageTrade/delta-neutral-gmx-vaults/pull/38

0x00052

Fix looks good. Slippage is now adjusted to match token decimals

The original report as published on Sherlock, by clems4ever. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

The minimum output amount is calculated without adjusting for the token's decimals, so it is only correct for 6-decimal tokens.

Impact

Users withdrawing tokens other than USDC could suffer large losses because slippage protection is virtually absent, though a direct sandwich attack may not work due to GMX's oracle pricing.

What the attacker needed

User withdraws to a non-6-decimal token

The fix

The fix adjusts the minimum output amount to match the token's decimals, and the text confirms it was applied.

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 swap tokens, a slippage setting protects you from getting much less than expected. This code calculates that minimum amount but always assumes the token has 6 decimal places, like USDC. For tokens with 18 decimal places, the minimum is far too low, so the protection does almost nothing.

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.

More by clems4ever

View all

8 more disclosed reports, best first.

More from Rage Trade

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.