Skip to content
Business logic Audit finding Intermediate

DestroyAgent() functionality can easily be bricked due to Frontrunning Attack

The CollateralPool's enter() function does not check whether the agent is in the DESTROYING state, so an attacker can frontrun the destroyAgent() transaction with a small deposit. This makes totalSupply non-zero, causing the destroy() call to fail, and the attacker can then withdraw their funds, repeatedly blocking the agent from exiting.

danvinci_20 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#46886 [SC-Low] `destroyAgent()` functionality can easily be bricked due to Frontrunning Attack

Submitted on Jun 5th 2025 at 21:15:46 UTC by @danvinci_20 for Audit Comp | Flare | FAssets

Description

Description

The agent destruction process is designed to safely decommission agents by enforcing a waiting period after which the agent can now call the destroyAgent() function to finalize the whole process. Now this function makes an external call to the CollateralPool to destroy it:

Solidity
 function destroy(address payable _recipient)
        external
        onlyAssetManager
        nonReentrant
    {
@>>        require(token.totalSupply() == 0, "cannot destroy a pool with issued tokens");
        token.destroy(_recipient);
        // transfer native balance, if any (used to be done by selfdestruct)
        Transfers.transferNAT(_recipient, address(this).balance);
        // transfer untracked f-assets and wNat, if any
     .............................
    }

There exist a condition that ensures no owned funds remain in the collateral pool (totalSupply == 0). This invariant is critical for maintaining the integrity and finality of the agent lifecycle.

However, a vulnerability exists in the CollateralPool contract due to the lack of a state check in the enter() function. Specifically, enter() does not verify whether the associated agent is currently in the DESTROYING state before allowing deposits.

This opens a griefing vector: an attacker can frontrun the destroyAgent() transaction by depositing a small amount of collateral via enter(). This breaks the destruction condition (since totalSupply > 0), causing the agent’s destroy() call to fail. After the failure, the attacker can simply withdraw their funds using exit().

Since this attack does not require significant capital and can be repeated indefinitely, it effectively allows malicious actors to prevent agents from ever exiting the system.

Impact Details

This attack makes it impossible for agents to safely exit the system, since the Agents are permanently or repeatedly blocked from exiting the system.

Recommendations

Add a check in the enter() function to ensure that no new deposits can be made if the agent is in the DESTROYING state:

Solidity
function enter(uint256 _fAssets, bool _enterWithFullFAssets)
    external payable
    nonReentrant
    returns (uint256, uint256)
{
    Agent.State storage agent = Agent.get(agentVault);
    require(agent.status != Agent.Status.DESTROYING, "agent is being destroyed");
    
    AssetData memory assetData = _getAssetData();
    // ... rest of the logic
}

A more efficient recommendation is to not bother about the remaining total supply when destorying agent vault since it's a timelock operation and agents have made announcement already legit users should have removed their funds safely before then, most likely the remaining share supply are dead shares.

Proof of Concept

Proof of Concept

This is the attack path:

  1. Agent announces destruction via announceDestroyAgent; status changes to DESTROYING and a waiting period begins.
  2. After some time the agent calls the destroyAgent() to finalize the process
  3. Attacker frontruns this process by calling enter() with a minimal deposit into the collateralPOOL.
  4. When the agent later attempts to finalize destruction via destroy(), the call fails due to totalSupply > 0.
  5. Attacker backruns and calls exit() to withdraw their deposit.

The original report as published on Immunefi, by danvinci_20. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 enter() function lacks a check that the agent's status is not DESTROYING, allowing deposits during the destruction process.

Impact

Agents could be permanently or repeatedly blocked from exiting the system, as the attack requires little capital and can be repeated indefinitely.

What the attacker needed

Agent in DESTROYING state; attacker can frontrun transaction; minimal deposit capital

The fix

Add a check in enter() to prevent deposits when the agent is in the DESTROYING state, or remove the totalSupply requirement from destroy().

How it was found

  1. Agent announces destruction via announceDestroyAgent; status changes to DESTROYING and a waiting period begins.
  2. After some time the agent calls the destroyAgent() to finalize the process
  3. Attacker frontruns this process by calling enter() with a minimal deposit into the collateralPOOL.
  4. When the agent later attempts to finalize destruction via destroy(), the call fails due to totalSupply > 0.
  5. Attacker backruns and calls exit() to withdraw their deposit.

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 an agent wants to shut down, it first announces this and waits, then calls a function to finalise. That final step only works if no one holds any of the pool's tokens. The bug is that the deposit function does not check if the agent is shutting down, so anyone can sneak in a tiny deposit just before the final step, making it fail. The attacker then takes their money back, and can do this again and again.

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 danvinci_20

View all

22 more disclosed reports, best first.

More from Flare | FAssets

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.