Skip to content
Business logic Audit finding Intermediate

Incorrect gas allowance comparison in CoreVault transfer function leads to user fund loss

The CoreVault contract incorrectly compares a gas allowance (in gas units) with a transfer fee (in wei), causing users who overpay to lose the excess ETH because the refund logic fails. An attacker or normal user overpaying by a small amount permanently loses funds to the contract.

DSbeX Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#45533 [SC-Low] Incorrect gas allowance comparison in CoreVault transfer function leads to user fund loss

Submitted on May 16th 2025 at 09:31:08 UTC by @DSbeX for Audit Comp | Flare | FAssets

Description

Brief/Intro

The CoreVault contract miscalculates gas costs when refunding excess ETH paid by users for transfers, treating gas units as equivalent to wei. This error causes users to lose ETH when overpaying for transfer fees, as the contract retains funds that should be refunded. If exploited, attackers or users overpaying by even small amounts would permanently lose ETH to the contract.

Vulnerability Details

The vulnerability arises in the transferToCoreVault function of the CoreVault library, where the contract checks if msg.value exceeds the required transfer fee plus a gas allowance: https://github.com/flare-foundation/fassets/blob/fc727ee70a6d36a3d8dec81892d76d01bb22e7f1/contracts/assetManager/library/CoreVault.sol#L83

JavaScript
if (msg.value > transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE) {
            Transfers.transferNAT(state.nativeAddress, transferFeeWei);
            Transfers.transferNATAllowFailure(payable(msg.sender), msg.value - transferFeeWei);
        } else {
            Transfers.transferNAT(state.nativeAddress, msg.value);
        }

Transfers.TRANSFER_GAS_ALLOWANCE represents a gas limit (100_000 gas units), not wei. The code incorrectly adds it to transferFeeWei (in wei), leading to a mismatched comparison. This error systematically under-refunds users, as the gas cost in wei (gas units × tx.gasprice) is not calculated. The contract retains ETH that should be returned, resulting in direct fund loss.

Impact Details

Direct Theft of User Funds: Users overpaying beyond the miscalculated threshold lose ETH permanently to the contract. Exploitability: No attacker needed—users inadvertently lose funds due to normal contract interaction.

References

CoreVault::transferToCoreVault - https://github.com/flare-foundation/fassets/blob/fc727ee70a6d36a3d8dec81892d76d01bb22e7f1/contracts/assetManager/library/CoreVault.sol#L83

Transfers.sol - https://github.com/flare-foundation/fassets/blob/fc727ee70a6d36a3d8dec81892d76d01bb22e7f1/contracts/utils/lib/Transfers.sol#L8

Proof of Concept

Proof of Concept

1.User Initiates Transfer:

Calls transferToCoreVault(amountAMG) with msg.value = 0.1005 ETH. The required transfer fee is 0.1 ETH.

  1. Flawed Threshold Check:

Contract calculates:

msg.value (0.1005 ETH) > transferFeeWei (0.1 ETH) + TRANSFER_GAS_ALLOWANCE (100,000 wei = 0.0001 ETH). → 0.1005 ETH > 0.1001 ETH → true.

  1. Fee Payment:

Contract sends 0.1 ETH to the fee address (state.nativeAddress).

Remaining contract balance: 0.1005 ETH - 0.1 ETH = 0.0005 ETH.

  1. Refund Attempt:

Contract attempts to refund msg.value - transferFeeWei = 0.0005 ETH to the user.

Gas Cost Calculation:

Refund requires ~21,000 gas (standard ETH transfer).

Gas cost in wei: 21,000 gas * 20 gwei = 420,000,000,000 wei = 0.00042 ETH.

  1. Insufficient Contract Balance:

Total ETH needed for refund: 0.0005 ETH (refund) + 0.00042 ETH (gas) = 0.00092 ETH.

Contract only has 0.0005 ETH after paying the fee.

  1. Refund Failure:

The transferNATAllowFailure call fails due to insufficient ETH for gas.

Result:

0.0005 ETH remains trapped in the contract.

User loses their overpayment of 0.0005 ETH.

The original report as published on Immunefi, by DSbeX. 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 contract adds a gas allowance (in gas units) to a fee amount (in wei) without converting the gas allowance to wei using the gas price, leading to an incorrect threshold for refunding excess ETH.

Impact

Users who overpay for transfers could permanently lose the excess ETH to the contract, as the refund fails due to insufficient gas funds.

What the attacker needed

User overpays transfer fee; Contract has insufficient ETH for refund gas

The fix

The contract should convert the gas allowance to wei using the gas price before comparing, or otherwise correctly calculate the refundable amount.

How it was found

  1. User calls transferToCoreVault with msg.value = 0.1005 ETH while the required transfer fee is 0.1 ETH.
  2. Contract checks if msg.value > transferFeeWei + TRANSFER_GAS_ALLOWANCE, which evaluates to true because 0.1005 ETH > 0.1001 ETH.
  3. Contract sends 0.1 ETH to the fee address, leaving 0.0005 ETH in the contract.
  4. Contract attempts to refund 0.0005 ETH to the user via transferNATAllowFailure.
  5. The refund fails because the contract lacks enough ETH to cover the gas cost (about 0.00042 ETH), so the 0.0005 ETH remains trapped.

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 send extra money (ETH) to a smart contract, it should return the extra. Here, the contract mistakenly treats a gas limit (a number of gas units) as if it were an amount of ETH (wei), so it thinks the extra is smaller than it is and tries to refund too little. The refund then fails because the contract does not have enough ETH to cover the gas cost, and the extra money stays stuck in the contract.

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 DSbeX

View all

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