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.
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
- Report ID: #46886
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/flare-foundation/fassets/blob/main/contracts/assetManager/implementation/CollateralPool.sol
- Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
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:
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:
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:
- Agent announces destruction via
announceDestroyAgent; status changes to DESTROYING and a waiting period begins. - After some time the agent calls the
destroyAgent()to finalize the process - Attacker frontruns this process by calling
enter()with a minimal deposit into thecollateralPOOL. - When the agent later attempts to finalize destruction via
destroy(), the call fails due to totalSupply > 0. - Attacker backruns and calls
exit()to withdraw their deposit.
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
- Agent announces destruction via announceDestroyAgent; status changes to DESTROYING and a waiting period begins.
- After some time the agent calls the destroyAgent() to finalize the process
- Attacker frontruns this process by calling enter() with a minimal deposit into the collateralPOOL.
- When the agent later attempts to finalize destruction via destroy(), the call fails due to totalSupply > 0.
- 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.