Skip to content
Business logic Audit finding Intermediate

AutoRange execution can be front-ran to avoid protocol fee, causing loss for protocol

The AutoRange contract allows users to change their fee-handling preference (onlyFees) after an operator has set the reward parameter, so a user can front-run the operator's transaction to switch to a lower fee mode. This causes the protocol to receive a much smaller fee than intended, leading to a loss.

0xjuan Follow

Originally disclosed on Code4rena

Submitted by 0xjuan

When users configure their NFT within the AutoRange contract, they have 2 options for fee-handling:

  1. Protocol takes 0.15% of the entire position size.
  2. Protocol takes a higher fee of 2%, but only from the position’s collected fees.

The user sets PositionConfig.onlyFees=false for the first option, and onlyFees=true for the second option. When an operator calls the AutoRange.execute() function, they set the reward parameter rewardX64 based on the user’s PositionConfig.

However, the execution can be front-ran by the user. They can change the onlyFees boolean, which changes the fee handling logic, while the rewardX64 parameter set by the operator is unchanged.

The user can exploit this to their advantage by initially setting onlyFees to false, so that the operator will call the function with only 0.15% reward percentage. But when the operator sends their transaction, the user front-runs it by changing onlyFees to true. Now, the protocol only gets 0.15% of the fees collected when they initially intended to collect 0.15% of the entire position.

Impact

The cost of executing the swap is likely to exceed the fees obtained (since expected fee is 0.15% of entire position, but only 0.15% of fees are obtained). This leads to loss of funds for the protocol.

Note: this has been submitted as only a medium severity issue since the protocol’s off-chain operator logic can simply blacklist such users once they have performed the exploit.

Proof of Concept

See the rewardX64 parameter and docs regarding fee source.

Recommended Mitigation Steps

Let the operator pass in 2 different values for rewardX64, where each one corresponds to a different value of onlyFees. This way, the rewardX64 parameter passed in will not be inconsistent with the executed logic.

Assessed type

MEV

kalinbas (Revert) acknowledged and commented:

As you mentioned we are solving this with the bot off-chain; it is a valid finding.


The original report as published on Code4rena, by 0xjuan. 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

The reward parameter is set by the operator based on the user's current configuration, but the user can change that configuration before the transaction is mined, so the reward no longer matches the actual fee logic.

Impact

The protocol could lose funds because the cost of executing the swap is likely to exceed the reduced fee obtained.

What the attacker needed

User has an NFT position in AutoRange; operator executes AutoRange; user can front-run the transaction

The fix

The operator should pass two different reward values, one for each onlyFees setting, so the reward always matches the executed logic.

How it was found

  1. User sets onlyFees to false, so the operator will use a 0.15% reward based on the entire position.
  2. Operator prepares and sends a transaction calling AutoRange.execute() with that reward.
  3. User front-runs the operator's transaction by changing onlyFees to true.
  4. The operator's transaction executes with the old reward but the new fee logic, so the protocol only gets 0.15% of collected fees instead of 0.15% of the entire position.

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 user can trick the system by quickly changing a setting just before the operator's transaction goes through. The operator thinks they are charging a fee based on the whole position, but because the setting changed, the fee is only taken from a smaller amount. This means the protocol gets less money than it expected.

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 0xjuan

View all

3 more disclosed reports, best first.

More from Revert Lend

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.