Skip to content
Business logic Audit finding Intermediate

Incorrect msg.Value check in CoreVault Transfer

The transferToCoreVault function in CoreVault.sol only refunds the agent when msg.value exceeds the transfer fee plus a gas allowance, so any extra value between the fee and that threshold is kept by the contract instead of being returned. An agent sending a small overpayment therefore loses those funds, which remain stuck in the contract.

aman Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#46119 [SC-Low] Incorrect `msg.Value` check in `CoreVault` Transfer

Submitted on May 25th 2025 at 06:53:02 UTC by @aman for Audit Comp | Flare | FAssets

Description

Brief/Intro

The transferToCoreVault function in CoreVault.sol incorrectly assumes that the TRANSFER_GAS_ALLOWANCE should be retained by the contract, when in fact the gas costs are paid by the agent (msg.sender) directly. This leads to unnecessary retention of funds that should be returned to the agent.

Vulnerability Details

The vulnerable code is in CoreVault.sol:

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

The issue is that the code:

  1. Checks if msg.value is greater than transferFeeWei + TRANSFER_GAS_ALLOWANCE
  2. But the TRANSFER_GAS_ALLOWANCE is unnecessary because:
    • Gas costs are paid by the agent (msg.sender) directly through the transaction
    • The contract doesn't need to retain any additional gas allowance
    • The only fee that should be retained is the transferFeeWei

Impact Details

  • Severity: Medium
  • Impact: Unnecessarily retains funds that should be returned to the agent
  • Likelihood: High - Affects every transfer to core vault where msg.value > transferFeeWei and msg.value <= transferFeeWei + TRANSFER_GAS_ALLOWANCE

References

  • File: contracts/assetManager/library/CoreVault.sol
  • Function: transferToCoreVault

Recommendations

  1. Remove the TRANSFER_GAS_ALLOWANCE check since gas costs are paid by the msg.sender:
Solidity
if (msg.value > transferFeeWei) {
    Transfers.transferNAT(state.nativeAddress, transferFeeWei);
    Transfers.transferNATAllowFailure(payable(msg.sender), msg.value - transferFeeWei);
}

Proof of Concept

Proof of Concept

To proof my point I have added few changed to CoreVault.sol file :

Diff
+    uint256 balNativeAddressBefore=  payable(address(state.nativeAddress)).balance;
        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);
        }
+        uint256 balNativeAddressAfter=  payable(address(state.nativeAddress)).balance;
+        console.log("state.nativeAddress balance After balance " , balNativeAddressAfter - balNativeAddressBefore - transferFeeWei);

And also update the Agent.ts:

Diff
diff --git a/test/integration/utils/Agent.ts b/test/integration/utils/Agent.ts
index 02980151..6ae8697a 100644
--- a/test/integration/utils/Agent.ts
+++ b/test/integration/utils/Agent.ts
@@ -529,7 +537,7 @@ export class Agent extends AssetContextClient {

     async transferToCoreVault(transferAmount: BNish) {
         const cbTransferFee = await this.assetManager.transferToCoreVaultFee(transferAmount);
-        const res = await this.assetManager.transferToCoreVault(this.vaultAddress, transferAmount, { from: this.ownerWorkAddress, value: cbTransferFee });
+        const res = await this.assetManager.transferToCoreVault(this.vaultAddress, transferAmount, { from: this.ownerWorkAddress, value: cbTransferFee.add(toBN(100_000)) });
         const rdreqs = filterEvents(res, "RedemptionRequested").map(evt => evt.args);
         assert.isAtLeast(rdreqs.length, 1);

And than add following test case to CoreVault.ts file:

JavaScript
    it.only("extra amount not return correctly", async () => {
        const agent = await Agent.createTest(context, agentOwner1, underlyingAgent1);
        const agent2 = await Agent.createTest(context, agentOwner2, underlyingAgent2);
        const minter = await Minter.createTest(context, minterAddress1, underlyingMinter1, context.underlyingAmount(10000000));
        const redeemer = await Redeemer.create(context, redeemerAddress1, underlyingRedeemer1);
        let agentInfo1 = await agent.getAgentInfo();

        await prefundCoreVault(minter.underlyingAddress, 1e6);
        // allow CV manager addresses
        await coreVaultManager.addAllowedDestinationAddresses([redeemer.underlyingAddress], { from: governance });
        // make agent available
        await agent.depositCollateralLotsAndMakeAvailable(50);

        // mint
        let [minted] = await minter.performMinting(agent.vaultAddress, 50);


        await minter.transferFAsset(redeemer.address, minted.mintedAmountUBA);
        // agent requests transfer for some backing to core vault
        const transferAmount = context.convertLotsToUBA(49);
        await agent.transferToCoreVault(transferAmount);
    });

Run with command yarn testHH console.logs of this test :

Shell
state.nativeAddress balance After balance  100000 # extra amount nativeAddress receives

The original report as published on Immunefi, by aman. 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 refund condition compares msg.value against the transfer fee plus an unnecessary gas allowance, so overpayments below that combined threshold are never returned to the sender.

Impact

Agents who overpay slightly could have the extra amount permanently retained by the contract, effectively freezing those funds.

What the attacker needed

Agent calls transferToCoreVault; msg.value above fee but below fee plus allowance

The fix

The check should compare msg.value only against the transfer fee and refund the remainder to the sender.

How it was found

  1. Add logging around the balance of the native address in CoreVault.sol.
  2. Modify the test helper to send the transfer fee plus an extra amount as msg.value.
  3. Run a test that performs a transfer to the core vault with the overpayment.
  4. Observe that the extra amount is received by the native address rather than refunded.

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 someone calls a smart contract function they can attach extra cryptocurrency to the call. This contract was meant to keep only the transfer fee and send the rest back, but its check used a higher threshold, so small overpayments were kept by the contract instead of being refunded. The money was not stolen by an outsider, but it was effectively frozen 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 aman

View all

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