Skip to content
Business logic Audit finding Intermediate

Can not update target price

The sanity checks in the rampTargetPrice function are broken because the multiplication and division order causes the comparison to always fail when the future target price is smaller than the initial one. As a result, the admin cannot ramp the target price down by even 1 wei, preventing an important feature from working.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005, also found by WatchPug

Impact

The sanity checks in rampTargetPrice are broken SwapUtils.sol#L1571-L1581

        if (futureTargetPricePrecise < initialTargetPricePrecise) {
            require(
                futureTargetPricePrecise.mul(MAX_RELATIVE_PRICE_CHANGE).div(WEI_UNIT) >= initialTargetPricePrecise,
                "futureTargetPrice_ is too small"
            );
        } else {
            require(
                futureTargetPricePrecise <= initialTargetPricePrecise.mul(MAX_RELATIVE_PRICE_CHANGE).div(WEI_UNIT),
                "futureTargetPrice_ is too large"
            );
        }

If futureTargetPricePrecise is smaller than initialTargetPricePrecise 0.01 of futureTargetPricePrecise would never larger than initialTargetPricePrecise.

Admin would not be able to ramp the target price. As it’s one of the most important features of the customswap, I consider this is a high-risk issue

Proof of Concept

Here’s a web3.py script to demo that it’s not possible to change the target price even by 1 wei.

    p1, p2, _, _ =swap.functions.targetPriceStorage().call()
    future = w3.eth.getBlock(w3.eth.block_number)['timestamp'] + 200 * 24 * 3600

    # futureTargetPrice_ is too small
    swap.functions.rampTargetPrice(p1 -1, future).transact()
    # futureTargetPrice_ is too large
    swap.functions.rampTargetPrice(p1 + 1, future).transact()

Tools Used

None

Recommended Mitigation Steps

Would it be something like:

        if (futureTargetPricePrecise < initialTargetPricePrecise) {
            require(
                futureTargetPricePrecise.mul(MAX_RELATIVE_PRICE_CHANGE + WEI_UNIT).div(WEI_UNIT) >= initialTargetPricePrecise,
                "futureTargetPrice_ is too small"
            );
        } else {
            require(
                futureTargetPricePrecise <= initialTargetPricePrecise.mul(MAX_RELATIVE_PRICE_CHANGE + WEI_UNIT).div(WEI_UNIT),
                "futureTargetPrice_ is too large"
            );
        }

I believe the dev would spot this mistake if there’s a more relaxed timeline.

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 multiplication and division order in the require statements causes the comparison to always fail when futureTargetPricePrecise is less than initialTargetPricePrecise.

Impact

The admin cannot ramp the target price, which is a core feature of the customswap, potentially disrupting price adjustments.

What the attacker needed

Admin privileges

The fix

The require statements should be modified to multiply by (MAX_RELATIVE_PRICE_CHANGE + WEI_UNIT) before dividing by WEI_UNIT, as suggested in the report.

How it was found

  1. Call targetPriceStorage to get the current target price.
  2. Attempt to ramp the target price to a value 1 wei lower than the current price.
  3. Observe the transaction fails with 'futureTargetPrice_ is too small'.
  4. Attempt to ramp the target price to a value 1 wei higher than the current price.
  5. Observe the transaction fails with 'futureTargetPrice_ is too large'.

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.

This is a smart contract bug where a function that should let an admin gradually change a price has a mistake in its safety checks. The checks are written in a way that makes them always reject any attempt to lower the price, even by the smallest amount. So the admin is stuck and cannot use that feature.

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.