Skip to content
Business logic Audit finding Intermediate

Anyone can call AutoPxGmx.compound and perform sandwich attacks with control parameters

The compound function in AutoPxGmx allows any caller to supply swap parameters, including the fee tier and minimum output amount, which can direct the swap to an illiquid pool and accept large slippage. An attacker could use this to perform a sandwich attack and profit at the expense of the protocol.

cccz Follow with Englave, immeas and 5 others

Originally disclosed on Code4rena

Submitted by cccz, also found by Englave, immeas, hansfriese, rbserver, Jeiwan, xiaoming90, and aphak5010

AutoPxGmx.compound allows anyone to call to compound the reward and get the incentive.

However, AutoPxGmx.compound calls SWAP_ROUTER.exactInputSingle with some of the parameters provided by the caller, which allows the user to perform a sandwich attack for profit.

For example, a malicious user could provide the fee parameter to make the token swap occur in a small liquid pool, and could make the amountOutMinimum parameter 1 to make the token swap accept a large slippage, thus making it easier to perform a sandwich attack.

Proof of Concept

https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L242-L278

Recommended Mitigation Steps

Consider using poolFee as the fee and using an onchain price oracle to calculate the amountOutMinimum.

Picodes (judge) commented:

Flagging as best as the warden identifies that the main risk is not the possibility to increase fees but the fact that some of the pools will be highly illiquid.

drahrealm (Redacted Cartel) disagreed with severity and commented:

Please refer to: https://github.com/code-423n4/2022-11-redactedcartel-findings/issues/185#issuecomment-1341252133

Picodes (judge) commented:

It’s very likely that this attack is profitable as most of the time only 1 or 2 pools have decent liquidity, so Medium severity is appropriate.


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

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 compound function passes caller-controlled parameters (fee and amountOutMinimum) directly to the swap router without validating them against safe defaults or an oracle.

Impact

An attacker could perform a sandwich attack for profit, and the judge noted it is very likely profitable because only one or two pools have decent liquidity.

What the attacker needed

None

The fix

The recommended mitigation is to use a fixed pool fee and an on-chain price oracle to calculate the minimum output amount.

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.

A sandwich attack is when someone sees your trade and places their own trades before and after it to profit from the price change. Here, a smart contract lets anyone choose the settings for a token swap, so an attacker can pick a pool with very little money in it and allow a huge price difference, making it easy to profit from the swap.

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 cccz

View all

104 more disclosed reports, best first.

More from Redacted Cartel contest

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.