Skip to content
Business logic Audit finding Intermediate

Stop ramp target price would create huge arbitrage space.

The stopRampTargetPrice function changes the token precision multipliers, which alters the AMM pool price. An attacker can sandwich this change to profit from the price difference.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005

Stop ramp target price would create huge arbitrage space.

Impact

stopRampTargetPrice would set the tokenPrecisionMultipliers to originalPrecisionMultipliers[0].mul(currentTargetPrice).div(WEI_UNIT); Once the tokenPrecisionMultipliers is changed, the price in the AMM pool would change. Arbitrager can sandwich stopRampTargetPrice to gain profit.

Assume the decision is made in the DAO, an attacker can set up the bot once the proposal to stopRampTargetPrice has passed. I consider this is a medium-risk issue.

Proof of Concept

The precisionMultiplier is set here: Swap.sol#L661-L666

We can set up a mockSwap with extra setPrecisionMultiplier to check the issue.

function setPrecisionMultiplier(uint256 multipliers) external {
    swapStorage.tokenPrecisionMultipliers[0] = multipliers;
}
print(swap.functions.getVirtualPrice().call())
swap.functions.setPrecisionMultiplier(2).transact()
print(swap.functions.getVirtualPrice().call())

# output log:
#     1000000000000000000
#     1499889859738721606

Tools Used

None

Recommended Mitigation Steps

Dealing with the target price with multiplier precision seems clever as we can reuse most of the existing code. However, the precision multiplier should be an immutable parameter. Changing it after the pool is setup would create multiple issues. This function could be implemented in a safer way IMHO.

A quick fix I would come up with is to ramp the tokenPrecisionMultipliers as the aPrecise is ramped. As the tokenPrecision is slowly increased/decreased, the arbitrage space would be slower and the profit would (probably) distribute evenly to lpers.

Please refer to _getAPreceise’s implementation SwapUtils.sol#L227-L250

chickenpie347 (Boot Finance) confirmed

The original report as published on Code4rena, by jonah1005. 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 precision multiplier used in price calculation is not immutable and can be changed by a privileged function, causing an abrupt price shift.

Impact

An attacker could sandwich the stopRampTargetPrice transaction to profit from the price change, which the author considers a medium-risk issue.

What the attacker needed

DAO proposal to call stopRampTargetPrice passes; Attacker can sandwich the transaction

How it was found

  1. Set up a mockSwap with an extra setPrecisionMultiplier function.
  2. Call getVirtualPrice to record the initial price.
  3. Call setPrecisionMultiplier with a new value.
  4. Call getVirtualPrice again to see the changed price.

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.

In a decentralised exchange, prices are set by a formula. If someone can change a number that affects the formula, the price jumps. An attacker can buy before the change and sell after to make a profit, which is called sandwiching.

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 jonah1005

View all

39 more disclosed reports, best first.

More from Boot Finance 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.