Skip to content
Business logic Audit finding Intermediate

No slippage protection during adding liquidity to uniswap

The contract calls Uniswap's addLiquidity with zero minimum amounts for both tokens, so the transaction reverts if the pool price moves even slightly before execution. An attacker could manipulate the pool price just before the transaction to cause it to fail, denying the liquidity addition.

EPSec Follow with BestBugBusters, chupinexx and 7 others

Originally disclosed on Code4rena

Submitted by EPSec, also found by BestBugBusters, chupinexx, felconsec, gmh5225, Olugbenga, PotEater, pro_king, unique, and wahedtalash77

https://github.com/code-423n4/2025-04-virtuals-protocol/blob/28e93273daec5a9c73c438e216dde04c084be452/contracts/virtualPersona/AgentFactoryV4.sol#L230-L239

Finding description and impact

In the _executeApplication in AgentFactoryV4, during the process of adding liquidity using Uniswap’s IUniswapV2Router02.addLiquidity method, slippage tolerance is set to 0 for both token and assetToken. Specifically, in the following line:

IUniswapV2Router02(_uniswapRouter).addLiquidity(
    token,
    assetToken,
    IERC20(token).balanceOf(address(this)),
    initialAmount,
    0, // slippage tolerance for token
    0, // slippage tolerance for assetToken
    address(this),
    block.timestamp
);

Here, the 0 values for slippage tolerance mean that the liquidity addition will fail if the price of either token or assetToken fluctuates even slightly between when the transaction is initiated and when it’s executed. This is because Uniswap requires that the amount of tokens being swapped remains within a certain tolerance range to prevent slippage.

Recommended mitigation steps

To mitigate this issue, the following steps are recommended:

Introduce slippage protection: Modify the addLiquidity call to include a non-zero slippage tolerance. This ensures that the liquidity addition will proceed within a reasonable range of price variation.

    uint256 slippageTolerance = 50; // 0.5% slippage tolerance (adjustable)
    uint256 tokenAmountMin = (IERC20(token).balanceOf(address(this)) * (100 - slippageTolerance)) / 100;
    uint256 assetAmountMin = (initialAmount * (100 - slippageTolerance)) / 100;

    IUniswapV2Router02(_uniswapRouter).addLiquidity(
        token,
        assetToken,
        IERC20(token).balanceOf(address(this)),
        initialAmount,
        tokenAmountMin,
        assetAmountMin,
        address(this),
        block.timestamp
    );
  • slippageTolerance: The percentage tolerance for slippage. This should be adjusted based on the application’s tolerance for price fluctuation (e.g., 0.5% or 1%).
  • tokenAmountMin and assetAmountMin: These variables calculate the minimum acceptable amounts of token and assetToken that will be added to the liquidity pool, accounting for slippage.

The original report as published on Code4rena, by EPSec. 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 addLiquidity call passes zero for both minimum-amount parameters, providing no slippage protection.

Impact

Liquidity additions could fail whenever the pool price moves, and an attacker could deliberately cause this failure by manipulating the price before the transaction.

What the attacker needed

Attacker can move pool price before tx; liquidity addition transaction is pending

The fix

The addLiquidity call should be changed to pass non-zero minimum amounts calculated from a chosen slippage tolerance.

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 you add money to a trading pool, you tell the exchange the least you will accept back. Here the code says the least is zero, so any small price change makes the whole transaction fail. Someone who can move the price at the right moment can make it fail on purpose.

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 EPSec

View all

5 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.