Skip to content
Business logic Audit finding Intermediate

BondingTax has invalid slippage implementation

The slippage check in BondingTax's swapForAsset function is ineffective because the minimum output is calculated from the current spot price, which is itself dynamic. An attacker could cause the treasury to receive less than the intended minimum amount, or normal trading could lead to losses.

oakcobalt Follow with 0x1982us, adam-idarrha and 5 others

Originally disclosed on Code4rena

Submitted by oakcobalt, also found by 0x1982us, adam-idarrha, Damola0x, kodyvim, levi_104, Matin, and slowbugmayor

In BondingTax.sol, swapForAsset will swap taxTokens to assetToken through uniswap router.

The issue is that the slippage calculation (minOutput) is invalid. Currently, mintOutput is a percentage that is based on router.getAmountsOut(amount, path). Since router.getAmountsOut(amount, path) is also dynamic based on the actual uniswapV2pair spot price; this means minOutput will simply be a fraction of the actual swap result. The slippage check will always pass.

    function swapForAsset() public onlyBondingRouter returns (bool, uint256) {
...

|>      uint256[] memory amountsOut = router.getAmountsOut(amount, path);
        require(amountsOut.length > 1, "Failed to fetch token price");

        uint256 expectedOutput = amountsOut[1];
        uint256 minOutput = (expectedOutput * (10000 - _slippage)) / 10000;

 |>     try router.swapExactTokensForTokens(amount, minOutput, path, treasury, block.timestamp + 300) returns (
            uint256[] memory amounts
        ) {
            emit SwapExecuted(amount, amounts[1]);
            return (true, amounts[1]);
        } catch {
            emit SwapFailed(amount);
            return (false, 0);
        }

https://github.com/code-423n4/2025-04-virtuals-protocol/blob/28e93273daec5a9c73c438e216dde04c084be452/contracts/tax/BondingTax.sol#L143

Impact

Invalid slippage check allows any swap-out result, causing the treasury to lose the value of collected tax. Note that, even though the base chain has a low risk of front-running attack, the loss due to slippage happens naturally during normal trading activities.

Recommended mitigation steps

Slippage needs to be based on an expected price. Given swapForAsset is only intended to be invoked by BondingRouter, consider implementing a trusted on-chain oracle price reporting and basing the slippage calculation on the on-chain price.

Proof of Concept

Suppose 10000 virtual = 1 WBTC, due to a previous trading, price drops to 10000 virtual = 0.0833 WBTC. 1% slippage based on expected price: 0.099 WBTC.

In swapForAsset:

  1. BondingTax calculates minOutput with 1% slippage

    • minOutput = 0.0833 WBTC * (10000 - 100) / 10000 = 0.0825 WBTC
  2. BondingTax executes swap with these parameters:

    • router.swapExactTokensForTokens(

      1000 VIRTUAL,      // amountIn
      0.0825 WBTC,       // minOutput (1% less than minOutput)
      [VIRTUAL, WBTC],   // path
      treasury,          // recipient
      block.timestamp + 300  // deadline
      )
      
  3. The swap executes at the worse price:

    • Treasury receives approximately 0.0833 WBTC < 0.099 WBTC.

swapForAsset accepts unbounded slippage.


The original report as published on Code4rena, by oakcobalt. 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 minimum output is derived from the same dynamic spot price used for the swap, so it does not protect against price movements.

Impact

The treasury could lose the value of collected tax due to unbounded slippage, even during normal trading activities.

What the attacker needed

SwapForAsset is called by BondingRouter; price moves against the swap

The fix

Slippage should be based on a trusted on-chain oracle price rather than the current spot price.

How it was found

  1. BondingTax calculates minOutput with 1% slippage based on the current spot price.
  2. BondingTax executes the swap with that minOutput.
  3. The swap executes at a worse price, and the treasury receives less than the intended minimum.

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 swapping tokens, a slippage check ensures you get at least a minimum amount back. Here, the minimum is set based on the current price, so it always passes even if the price moves against you, meaning the treasury can lose value.

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 oakcobalt

View all

50 more disclosed reports, best first.

More from Virtuals Protocol

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.