Corevault refund failure can permanently freeze overpaid nat on assetmanager
When an agent overpays the transfer fee to the Core Vault, the contract attempts a refund but ignores the result of the refund transfer. If the refund fails, the overpaid native tokens remain stuck on the Asset Manager contract with no recovery path.
Flare | FAssets
Originally disclosed on Immunefi
#55025 [SC-Insight] corevault refund failure can permanently freeze overpaid nat on assetmanager
- Report ID: #55025
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/flare-foundation/fassets/commit/7aa02b62285cd5313032103710c2e083b166bf60
- Impacts: Permanent freezing of funds
Description
When an agent transfers underlying to the Core Vault via transferToCoreVault and overpays the required fee, the contract attempts to refund the difference using a 100k gas native transfer. If that refund fails (for example, the caller is a contract that reverts in receive() or requires more than 100k gas), the return value is ignored and the overpaid NAT remains stuck on the Asset Manager (diamond) contract with no recovery path.
Vulnerability Details
Relevant snippet from CoreVault:
// pay the transfer fee and return overpaid transfer fee when the difference is larger than gas use
// (all transfers are guarded by nonReentrant in the facet)
if (msg.value > transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice) {
Transfers.transferNAT(state.nativeAddress, transferFeeWei);
Transfers.transferNATAllowFailure(payable(msg.sender), msg.value - transferFeeWei);
} else {
Transfers.transferNAT(state.nativeAddress, msg.value);
}
Transfers.transferNATAllowFailure(address payable, uint256) returns bool to indicate success/failure of the 100k-gas NAT transfer, but the result is ignored here. If the recipient cannot accept the transfer (reverts in receive() or needs more than the fixed TRANSFER_GAS_ALLOWANCE = 100_000 gas), the function returns false. Because the return is ignored, the overpaid amount remains held by the asset manager contract and is never forwarded or burned.
For context: the threshold transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice is correct and ensures wei-to-wei comparison. The bug is independent of that threshold — it’s about ignoring the refund failure.
A similar pattern is handled correctly in CollateralReservations.sol:
bool success = Transfers.transferNATAllowFailure(minter, returnFee);
// if failed, burn the whole fee, otherwise burn the difference
if (!success) {
Agents.burnDirectNAT(totalFee);
}
Preconditions for the issue:
- Caller is the authorized agent vault owner but is a contract that reverts in
receiveor requires >100k gas to accept ETH. - Caller overpays
msg.valueenough to enter the refund branch.
Impact
Overpaid NAT remains in the Asset Manager’s balance indefinitely, with no generic sweep or recovery function exposed to return it.
Recommended mitigation steps
Update CoreVault.transferToCoreVault to handle failed refunds the same way as CollateralReservations — check the return value of Transfers.transferNATAllowFailure(...) and, on failure, execute an alternative such as burning the fee or forwarding it to a recovery/burn address so funds are not permanently stuck.
(Reference to the function: https://github.com/flare-foundation/fassets/blob/59373cee12e6d2a9fa0a9cc8735bb486faa51b36/contracts/assetManager/library/CoreVault.sol#L45)
Proof of Concept
The PoC demonstrates the issue by calling transferToCoreVault from a contract whose receive() reverts, ensuring the 100k gas refund fails and the overpaid NAT stays in the AssetManager.
PoC helper contract:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../userInterfaces/IAssetManager.sol";
/**
* RefundRejector is a helper contract for PoC.
* - It can be set as the agent's work address so that AssetManager recognizes it as the agent owner.
* - It calls AssetManager.transferToCoreVault from within the contract (so msg.sender is this contract).
* - Its receive() reverts, which makes Transfers.transferNATAllowFailure(...) return false when trying to refund.
* - It has a payable deposit() method to allow funding it despite the reverting receive().
*/
contract RefundRejector {
// allow funding via explicit function call
function deposit() external payable {}
// revert on plain ETH transfers (as used by Transfers.transferNATAllowFailure)
receive() external payable {
revert("RefundRejector: reject receive");
}
// call transferToCoreVault on AssetManager diamond, forwarding the provided value
function callTransferToCoreVault(IAssetManager assetManager, address agentVault, uint256 amountUBA) external payable {
assetManager.transferToCoreVault{ value: msg.value }(agentVault, amountUBA);
}
}
Integration test (create file test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts):
import { expectRevert, time } from "@openzeppelin/test-helpers";
import { filterEvents } from "../../../lib/utils/events/truffle";
import { BNish, toBN, toWei } from "../../../lib/utils/helpers";
import { getTestFile, loadFixtureCopyVars } from "../../utils/test-helpers";
import { Agent } from "../utils/Agent";
import { AssetContext } from "../utils/AssetContext";
import { CommonContext } from "../utils/CommonContext";
import { Minter } from "../utils/Minter";
import { testChainInfo } from "../utils/TestChainInfo";
import { assertWeb3Equal } from "../../utils/web3assertions";
const RefundRejector = artifacts.require("RefundRejector");
contract(`AssetManagerSimulation.sol; ${getTestFile(__filename)}; CoreVault refund failure PoC`, async accounts => {
const governance = accounts[10];
const agentOwner1 = accounts[20];
const minterAddress1 = accounts[30];
const underlyingAgent1 = "Agent1";
const underlyingMinter1 = "Minter1";
let commonContext: CommonContext;
let context: AssetContext;
async function initialize() {
commonContext = await CommonContext.createTest(governance);
context = await AssetContext.createTest(commonContext, testChainInfo.xrp);
// Enable Core Vault so transferToCoreVault passes onlyEnabled checks
await context.assignCoreVaultManager();
return { commonContext, context };
}
beforeEach(async () => {
({ commonContext, context } = await loadFixtureCopyVars(initialize));
});
it("PoC: refund failure traps overpaid NAT in AssetManager", async () => {
// 1) Create agent and make available
const agent = await Agent.createTest(context, agentOwner1, underlyingAgent1);
await agent.depositCollateralLotsAndMakeAvailable(100);
// 2) Mint so that we have backing to transfer
const minter = await Minter.createTest(context, minterAddress1, underlyingMinter1, context.underlyingAmount(1_000_000));
const [minted] = await minter.performMinting(agent.vaultAddress, 10);
await context.updateUnderlyingBlock();
// 3) Determine transfer amount (all backing)
const info = await agent.getAgentInfo();
const transferAmount = info.mintedUBA; // includes pool fee component
const cbTransferFee = await context.assetManager.transferToCoreVaultFee(transferAmount);
const overpay = toWei(10); // exceeds TRANSFER_GAS_ALLOWANCE * gasprice in HH env
const payTransferFee = cbTransferFee.add(overpay);
// 4) Deploy refund-rejecting caller and set it as agent work address
const rr = await RefundRejector.new();
await context.agentOwnerRegistry.setWorkAddress(rr.address, { from: agent.ownerManagementAddress });
// 5) Observe balances before
const amBefore = toBN(await web3.eth.getBalance(context.assetManager.address));
const rrBefore = toBN(await web3.eth.getBalance(rr.address));
// 6) Initiate transfer to core vault via RefundRejector (msg.sender = rr)
await rr.callTransferToCoreVault(context.assetManager.address, agent.vaultAddress, transferAmount, { value: payTransferFee });
// 7) Balances after: refund fails, so overpayment remains in AssetManager
const amAfter = toBN(await web3.eth.getBalance(context.assetManager.address));
const rrAfter = toBN(await web3.eth.getBalance(rr.address));
// AssetManager balance increased by overpayment only (transfer fee forwarded out)
assertWeb3Equal(amAfter.sub(amBefore), overpay);
// RefundRejector didn't receive refund (receive() reverts)
assertWeb3Equal(rrAfter.sub(rrBefore), 0);
});
});
Run the test with:
yarn hardhat test test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts
Logs from the PoC run:
Contract: AssetManagerSimulation.sol; test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts; CoreVault refund failure PoC
✔ PoC: refund failure traps overpaid NAT in AssetManager (78ms)
1 passing (1s)
✨ Done in 4.18s.
Steps to reproduce (high-level)
{% stepper %} {% step %}
Prepare environment
Deploy the AssetManager/fassets stack and ensure Core Vault is enabled (so transferToCoreVault is allowed).
{% endstep %}
{% step %}
Create agent and mint
- Create an agent and make it available.
- Perform minting to create backing for the agent so there is underlying to transfer. {% endstep %}
{% step %}
Deploy RefundRejector and set as agent work address
- Deploy the
RefundRejectorhelper contract (itsreceive()reverts). - Set
RefundRejectoras the agent's work address so that it is recognized as the agent owner. {% endstep %}
{% step %}
Trigger transfer with overpayment
- Call
transferToCoreVaultfromRefundRejector, forwarding amsg.valuethat overpays the transfer fee enough to trigger the refund branch. - The contract will attempt the 100k-gas refund to
RefundRejector, which will fail due to its revertingreceive(). {% endstep %}
{% step %}
Observe balances
- AssetManager balance increases by the overpaid amount.
- RefundRejector does not receive the refund — funds remain stuck on AssetManager. {% endstep %} {% endstepper %}
Context
This report concerns the FAssets smart contract system from Flare, specifically the Asset Manager diamond and its Core Vault feature. An agent in FAssets holds collateral and mints FAssets against it. When an agent wants to move underlying assets into the Core Vault, it calls transferToCoreVault on the Asset Manager. That call carries a native (NAT) transfer fee, and the Core Vault code is written to refund any overpayment back to the caller.
The target in the report is a specific commit of the flare-foundation/fassets repository:
https://github.com/flare-foundation/fassets/commit/[redacted]
The report is filed as a smart contract insight with the impact "Permanent freezing of funds". The relevant function is in contracts/assetManager/library/CoreVault.sol.
Setup
The proof of concept is an integration test in the project's Hardhat test suite, placed at test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts. It uses the existing simulation harness (CommonContext, AssetContext, Agent, Minter, testChainInfo) and a helper contract, RefundRejector, written in Solidity 0.8.23.
The preconditions the report lists for the issue are:
- The caller is the authorised agent vault owner, but is a contract that reverts in
receiveor requires more than 100k gas to accept ETH. - The caller overpays
msg.valueenough to enter the refund branch.
The test accounts are set up as follows: governance = accounts[10], agentOwner1 = accounts[20], minterAddress1 = accounts[30], with underlying labels Agent1 and Minter1. Core Vault is enabled through context.assignCoreVaultManager() so that transferToCoreVault passes its onlyEnabled checks.
Finding it
The researcher looked at the fee handling in CoreVault.transferToCoreVault. The snippet quoted from the contract is:
// pay the transfer fee and return overpaid transfer fee when the difference is larger than gas use
// (all transfers are guarded by nonReentrant in the facet)
if (msg.value > transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice) {
Transfers.transferNAT(state.nativeAddress, transferFeeWei);
Transfers.transferNATAllowFailure(payable(msg.sender), msg.value - transferFeeWei);
} else {
Transfers.transferNAT(state.nativeAddress, msg.value);
}
Transfers.transferNATAllowFailure(address payable, uint256) returns a bool indicating whether the 100k-gas NAT transfer succeeded, but the return value is discarded here. If the recipient cannot accept the transfer, either because it reverts in receive() or because it needs more than the fixed TRANSFER_GAS_ALLOWANCE = 100_000 gas, the function returns false. Because the return is ignored, the overpaid amount stays with the Asset Manager contract and is never forwarded or burned.
The researcher notes that the threshold transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice is itself correct, since it compares wei to wei. The bug is independent of that threshold: it is purely about ignoring the refund failure.
A comparable pattern in CollateralReservations.sol does check the result:
bool success = Transfers.transferNATAllowFailure(minter, returnFee);
// if failed, burn the whole fee, otherwise burn the difference
if (!success) {
Agents.burnDirectNAT(totalFee);
}
The report uses this contrast as context for the omission in CoreVault.
Exploitation
Step 1: Prepare the environment
Deploy the AssetManager/fassets stack and enable Core Vault so that transferToCoreVault is allowed. In the test this is done in the initialize fixture:
commonContext = await CommonContext.createTest(governance);
context = await AssetContext.createTest(commonContext, testChainInfo.xrp);
// Enable Core Vault so transferToCoreVault passes onlyEnabled checks
await context.assignCoreVaultManager();
Step 2: Create an agent and mint backing
An agent is created, given collateral and made available, then a minter mints FAssets against it so there is underlying to transfer:
const agent = await Agent.createTest(context, agentOwner1, underlyingAgent1);
await agent.depositCollateralLotsAndMakeAvailable(100);
// 2) Mint so that we have backing to transfer
const minter = await Minter.createTest(context, minterAddress1, underlyingMinter1, context.underlyingAmount(1_000_000));
const [minted] = await minter.performMinting(agent.vaultAddress, 10);
await context.updateUnderlyingBlock();
Step 3: Deploy the refund-rejecting caller and set it as the agent work address
The helper contract is deployed and registered as the agent's work address, so the Asset Manager recognises it as the agent owner:
const rr = await RefundRejector.new();
await context.agentOwnerRegistry.setWorkAddress(rr.address, { from: agent.ownerManagementAddress });
The helper contract itself is:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../userInterfaces/IAssetManager.sol";
/**
* RefundRejector is a helper contract for PoC.
* - It can be set as the agent's work address so that AssetManager recognizes it as the agent owner.
* - It calls AssetManager.transferToCoreVault from within the contract (so msg.sender is this contract).
* - Its receive() reverts, which makes Transfers.transferNATAllowFailure(...) return false when trying to refund.
* - It has a payable deposit() method to allow funding it despite the reverting receive().
*/
contract RefundRejector {
// allow funding via explicit function call
function deposit() external payable {}
// revert on plain ETH transfers (as used by Transfers.transferNATAllowFailure)
receive() external payable {
revert("RefundRejector: reject receive");
}
// call transferToCoreVault on AssetManager diamond, forwarding the provided value
function callTransferToCoreVault(IAssetManager assetManager, address agentVault, uint256 amountUBA) external payable {
assetManager.transferToCoreVault{ value: msg.value }(agentVault, amountUBA);
}
}
The receive() function reverts on any plain ETH transfer, which is exactly the path Transfers.transferNATAllowFailure uses for the refund. The deposit() function exists so the contract can still be funded despite the reverting receive(). The callTransferToCoreVault wrapper makes the helper contract itself the msg.sender of the Asset Manager call.
Step 4: Trigger the transfer with an overpayment
The test computes the transfer amount from the agent's minted balance, queries the fee, and adds an overpayment large enough to enter the refund branch:
const info = await agent.getAgentInfo();
const transferAmount = info.mintedUBA; // includes pool fee component
const cbTransferFee = await context.assetManager.transferToCoreVaultFee(transferAmount);
const overpay = toWei(10); // exceeds TRANSFER_GAS_ALLOWANCE * gasprice in HH env
const payTransferFee = cbTransferFee.add(overpay);
Balances are recorded before the call, then the call is made through the helper:
const amBefore = toBN(await web3.eth.getBalance(context.assetManager.address));
const rrBefore = toBN(await web3.eth.getBalance(rr.address));
// 6) Initiate transfer to core vault via RefundRejector (msg.sender = rr)
await rr.callTransferToCoreVault(context.assetManager.address, agent.vaultAddress, transferAmount, { value: payTransferFee });
Inside transferToCoreVault, the fee is forwarded to the native address and the refund is attempted to msg.sender (the helper). The helper's receive() reverts, so transferNATAllowFailure returns false, and the return value is ignored.
Step 5: Observe the balances
The test asserts that the Asset Manager balance grew by exactly the overpayment and that the helper received nothing:
const amAfter = toBN(await web3.eth.getBalance(context.assetManager.address));
const rrAfter = toBN(await web3.eth.getBalance(rr.address));
// AssetManager balance increased by overpayment only (transfer fee forwarded out)
assertWeb3Equal(amAfter.sub(amBefore), overpay);
// RefundRejector didn't receive refund (receive() reverts)
assertWeb3Equal(rrAfter.sub(rrBefore), 0);
The test is run with:
yarn hardhat test test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts
and the logged output is:
Contract: AssetManagerSimulation.sol; test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts; CoreVault refund failure PoC
✔ PoC: refund failure traps overpaid NAT in AssetManager (78ms)
1 passing (1s)
✨ Done in 4.18s.
Root cause
CoreVault.transferToCoreVault calls Transfers.transferNATAllowFailure for the refund and ignores its boolean return value. The function is explicitly designed to fail softly: it uses a fixed TRANSFER_GAS_ALLOWANCE = 100_000 gas and returns false when the transfer cannot be completed. Ignoring that signal means the overpaid NAT is neither delivered to the caller nor burned or redirected. It simply stays in the Asset Manager's balance.
The nonReentrant guard mentioned in the code comment protects against reentrancy during the transfers, but it does nothing about a refund that fails outright. The correct handling pattern already exists in CollateralReservations.sol, where a failed refund leads to burning the whole fee. The report does not describe any other defence that would recover the stranded funds.
Impact
Overpaid NAT remains in the Asset Manager's balance indefinitely. According to the report, no generic sweep or recovery function is exposed that could return it. It requires the specific precondition that the caller is a contract acting as the agent vault owner whose receive() reverts or needs more than 100k gas. The report classifies the impact as permanent freezing of funds.
Fix
The recommended mitigation is to update CoreVault.transferToCoreVault to handle a failed refund the same way CollateralReservations does: check the return value of Transfers.transferNATAllowFailure(...) and, on failure, execute an alternative such as burning the fee or forwarding it to a recovery or burn address, so the funds are not permanently stuck.
Variants to test
- Other
transferNATAllowFailurecall sites: search the codebase for every use of the helper and check whether the boolean is consumed. A positive result is a call site where the return value is discarded and the recipient can be made to reject the transfer. - Gas-starved recipients: instead of a reverting
receive(), use a recipient whosereceive()succeeds only with more than 100k gas. A positive result is the same stranded balance with no revert surfaced to the caller. - Other refund and change-returning paths: any function that sends native value back to
msg.senderafter taking a fee is a candidate. A positive result is a balance increase on the contract that matches the unreturned amount. - Agent work address substitution: check whether other roles (work address, management address) can be pointed at a contract with a hostile
receive(), widening who can trigger the condition.
Hunting notes
This kind of bug hides in fee-handling branches where a soft-failure transfer helper is used for a refund. The signal during review is a call to a function whose name or signature returns bool (or an equivalent success flag) where the result is not assigned or checked. Comparing sibling contracts that implement the same pattern is a reliable way to spot the omission: here, CollateralReservations.sol checks the result and burns on failure, while CoreVault.sol does not.
The researcher demonstrated impact with an integration test that asserts both sides of the balance change: the Asset Manager keeps exactly the overpayment, and the helper's balance does not change. That concrete, reproducible balance assertion, together with the explicit precondition (a contract caller with a reverting receive()), is what turns a code observation into a reportable finding.
What happened, in plain words
This report is about a piece of software called FAssets, made by a company called Flare. FAssets runs on a blockchain, which is a shared record book that many computers keep copies of. Programs that live on a blockchain are called smart contracts: they are small programs that hold and move digital money automatically, following rules written in code. Nobody can quietly change the rules after the fact, and nobody can press an undo button.
In FAssets there is a role called an agent. An agent puts up a deposit (called collateral) and, against that deposit, creates digital tokens called FAssets. Think of it like a pawn shop: you leave something valuable behind, and you get a receipt you can use. The agent also has a place called the Core Vault, a kind of central storage for the underlying assets that back those tokens.
When an agent wants to move underlying assets into the Core Vault, it calls a function named transferToCoreVault on a central contract called the Asset Manager. A function is a named action a program can perform, like a button you press. This particular button costs a fee, paid in the chain's own money, called NAT here. The code is written so that if the agent sends more money than the fee, the extra is sent back to the caller. That sending-back is called a refund.
The problem: the refund can fail, and when it does, the code does not notice. The extra money then sits inside the Asset Manager contract forever. The report calls this "permanent freezing of funds": the money is not stolen, but it can never be moved again. The report is filed as an insight, and the stated impact is exactly that permanent freezing.
Context
This report concerns the FAssets smart contract system from Flare, specifically the Asset Manager diamond and its Core Vault feature. A diamond is a way of building one contract out of several smaller pieces, so a single address behaves like a set of features bolted together. An agent in FAssets holds collateral and mints FAssets against it. Minting means creating new tokens. When an agent wants to move underlying assets into the Core Vault, it calls transferToCoreVault on the Asset Manager. That call carries a native (NAT) transfer fee, and the Core Vault code is written to refund any overpayment back to the caller.
The target in the report is a specific commit of the flare-foundation/fassets repository. A repository is a shared folder of code with full history, and a commit is one saved snapshot of that folder, identified by a long code. Pinning the exact commit matters because code changes over time; a report is only meaningful against the version that was actually tested.
https://github.com/flare-foundation/fassets/commit/[redacted]
This is simply the web address of that saved snapshot on GitHub, a website where code repositories are hosted. Opening it shows the project exactly as it stood when the researcher looked at it.
The report is filed as a smart contract insight with the impact "Permanent freezing of funds". The relevant function is in contracts/assetManager/library/CoreVault.sol. That path is the location of the file inside the repository: a folder called contracts, then assetManager, then library, then the file CoreVault.sol. The .sol ending means it is written in Solidity, the main programming language for smart contracts on this kind of blockchain.
Setup
The proof of concept is an integration test in the project's Hardhat test suite, placed at test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts. A proof of concept is a small demonstration that proves a problem is real rather than theoretical. Hardhat is a tool that lets developers run a pretend blockchain on their own computer, so tests can be repeated safely without spending real money. An integration test is a test that runs several parts of the system together, rather than one isolated piece. The .ts ending means TypeScript, a language often used for this kind of test code.
The test uses the existing simulation harness (CommonContext, AssetContext, Agent, Minter, testChainInfo) and a helper contract, RefundRejector, written in Solidity 0.8.23. A harness is reusable setup code that saves the test from rebuilding the whole world each time. The number 0.8.23 is the version of the Solidity compiler used to build the helper contract.
The preconditions the report lists for the issue are:
- The caller is the authorised agent vault owner, but is a contract that reverts in
receiveor requires more than 100k gas to accept ETH. - The caller overpays
msg.valueenough to enter the refund branch.
Two of those terms need unpacking. A revert is a deliberate refusal: the program stops and undoes its work, like a cashier handing your money back and saying "no". Gas is the unit that measures computing effort on this kind of blockchain; every operation costs a little gas, and 100k means one hundred thousand units. msg.value is the amount of money attached to a call, the digital equivalent of the note you hand over at a till. A branch is a fork in the code: one path is taken if a condition is true, another if it is false.
The test accounts are set up as follows: governance = accounts[10], agentOwner1 = accounts[20], minterAddress1 = accounts[30], with underlying labels Agent1 and Minter1. An account here is just a numbered pretend wallet supplied by the test tool, so the test can act as several different people at once. Core Vault is enabled through context.assignCoreVaultManager() so that transferToCoreVault passes its onlyEnabled checks. onlyEnabled is a guard: the function refuses to run unless the feature has been switched on first.
Finding it
The researcher looked at the fee handling in CoreVault.transferToCoreVault. The snippet quoted from the contract is:
// pay the transfer fee and return overpaid transfer fee when the difference is larger than gas use
// (all transfers are guarded by nonReentrant in the facet)
if (msg.value > transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice) {
Transfers.transferNAT(state.nativeAddress, transferFeeWei);
Transfers.transferNATAllowFailure(payable(msg.sender), msg.value - transferFeeWei);
} else {
Transfers.transferNAT(state.nativeAddress, msg.value);
}
Line by line, in plain words:
- The first two lines are comments, notes for humans that the computer ignores. They say the code is about paying the transfer fee and returning any overpayment, and that all transfers are protected by a
nonReentrantguard. A guard is a lock that stops a second call slipping in while the first is still running, a bit like a shop locking the door while it counts the till. if (msg.value > transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice)is the fork. It asks: is the money attached to this call bigger than the fee plus the cost of the gas allowance?transferFeeWeiis the fee, measured in wei, the smallest unit of this currency.tx.gaspriceis the price of one unit of gas at that moment. Multiplying the allowance by the price converts gas into money, so both sides of the comparison are in the same unit. If the answer is yes, the caller has overpaid and the refund path is taken.Transfers.transferNAT(state.nativeAddress, transferFeeWei);sends the actual fee to the native address, the place where fees are collected.Transfers.transferNATAllowFailure(payable(msg.sender), msg.value - transferFeeWei);tries to send the difference back tomsg.sender, the caller. The name says it all: this helper is built to allow failure. It gives the transfer a fixed budget of gas and, if the transfer does not work, it does not blow up the whole call; it simply reports back that it failed.} else {is the other path, taken when there is no overpayment.Transfers.transferNAT(state.nativeAddress, msg.value);then sends the whole attached amount as the fee.
Transfers.transferNATAllowFailure(address payable, uint256) returns a bool indicating whether the 100k-gas NAT transfer succeeded, but the return value is discarded here. A bool is a value that is either true or false, like a light switch. Discarding it means the code asks "did that work?" and then ignores the answer. If the recipient cannot accept the transfer, either because it reverts in receive() or because it needs more than the fixed TRANSFER_GAS_ALLOWANCE = 100_000 gas, the function returns false. receive() is a special function that runs automatically when a contract is sent plain money, the equivalent of a letterbox; if that letterbox is nailed shut, the money bounces. Because the return is ignored, the overpaid amount stays with the Asset Manager contract and is never forwarded or burned. Burning means deliberately destroying tokens so they can never be used again.
The researcher notes that the threshold transferFeeWei + Transfers.TRANSFER_GAS_ALLOWANCE * tx.gasprice is itself correct, since it compares wei to wei. The bug is independent of that threshold: it is purely about ignoring the refund failure. In other words, the maths that decides whether a refund is owed is fine; the mistake is in what happens when paying that refund does not work.
A comparable pattern in CollateralReservations.sol does check the result:
bool success = Transfers.transferNATAllowFailure(minter, returnFee);
// if failed, burn the whole fee, otherwise burn the difference
if (!success) {
Agents.burnDirectNAT(totalFee);
}
Here the same helper is used, but its answer is stored in a variable called success. The if (!success) line reads as "if not successful", and in that case the code burns the whole fee instead of leaving it lying around. The report uses this contrast as context for the omission in CoreVault.
Exploitation
Step 1: Prepare the environment
Deploy the AssetManager/fassets stack and enable Core Vault so that transferToCoreVault is allowed. Deploying means putting a program onto the blockchain so it can be called. In the test this is done in the initialize fixture:
commonContext = await CommonContext.createTest(governance);
context = await AssetContext.createTest(commonContext, testChainInfo.xrp);
// Enable Core Vault so transferToCoreVault passes onlyEnabled checks
await context.assignCoreVaultManager();
- The first line builds a shared test world, with
governanceacting as the account in charge. - The second line builds the asset-specific part of that world on top of it, using a test configuration for XRP, a real cryptocurrency used here as the underlying asset.
- The third line switches on the Core Vault feature. Without it, the function under test would refuse to run because of its
onlyEnabledguard, and the test would prove nothing.
Step 2: Create an agent and mint backing
An agent is created, given collateral and made available, then a minter mints FAssets against it so there is underlying to transfer:
const agent = await Agent.createTest(context, agentOwner1, underlyingAgent1);
await agent.depositCollateralLotsAndMakeAvailable(100);
// 2) Mint so that we have backing to transfer
const minter = await Minter.createTest(context, minterAddress1, underlyingMinter1, context.underlyingAmount(1_000_000));
const [minted] = await minter.performMinting(agent.vaultAddress, 10);
await context.updateUnderlyingBlock();
- The first line creates an agent owned by
agentOwner1, labelledAgent1. - The second line deposits 100 lots of collateral and marks the agent as available, meaning it is allowed to do business. Collateral is the deposit that makes the agent trustworthy.
- The third line creates a minter, the customer side that will create tokens, funded with a test amount of underlying.
- The fourth line performs the minting itself, creating tokens against the agent's vault. This is what gives the agent something to transfer later; without backing, there would be nothing to move.
- The fifth line refreshes the test's view of the underlying chain, so the simulation stays consistent.
Step 3: Deploy the refund-rejecting caller and set it as the agent work address
The helper contract is deployed and registered as the agent's work address, so the Asset Manager recognises it as the agent owner:
const rr = await RefundRejector.new();
await context.agentOwnerRegistry.setWorkAddress(rr.address, { from: agent.ownerManagementAddress });
- The first line deploys the helper contract and keeps a handle to it called
rr. - The second line tells the registry, the system's list of who is who, that the helper's address is the agent's work address. A work address is the address the agent uses to act. This step matters because the function under test only lets the authorised agent call it; making the helper the work address is how the test gets past that gate.
The helper contract itself is:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../userInterfaces/IAssetManager.sol";
/**
* RefundRejector is a helper contract for PoC.
* - It can be set as the agent's work address so that AssetManager recognizes it as the agent owner.
* - It calls AssetManager.transferToCoreVault from within the contract (so msg.sender is this contract).
* - Its receive() reverts, which makes Transfers.transferNATAllowFailure(...) return false when trying to refund.
* - It has a payable deposit() method to allow funding it despite the reverting receive().
*/
contract RefundRejector {
// allow funding via explicit function call
function deposit() external payable {}
// revert on plain ETH transfers (as used by Transfers.transferNATAllowFailure)
receive() external payable {
revert("RefundRejector: reject receive");
}
// call transferToCoreVault on AssetManager diamond, forwarding the provided value
function callTransferToCoreVault(IAssetManager assetManager, address agentVault, uint256 amountUBA) external payable {
assetManager.transferToCoreVault{ value: msg.value }(agentVault, amountUBA);
}
}
- The first line is a licence note, a standard label saying how others may reuse the code.
pragma solidity 0.8.23;pins the compiler version, so the code is built exactly as intended.- The
importline pulls in the definition of the Asset Manager's interface, so this contract knows the shape of the function it wants to call. - The block between
/**and*/is a comment describing the helper's purpose: it can pose as the agent's work address, it calls the Asset Manager from inside itself so that it, not a person, is the caller, itsreceive()refuses money, and it has a separate way in for funding. contract RefundRejector {starts the definition of the helper.function deposit() external payable {}is an empty function that accepts money. It exists because the normal letterbox is nailed shut, so the test needs a side door to put funds in.receive() external payable { revert("RefundRejector: reject receive"); }is the nailed-shut letterbox. Any plain money transfer to this contract hits this function, which immediately refuses with the message shown. This is the heart of the demonstration: the refund will be aimed here and will bounce.function callTransferToCoreVault(...)is a wrapper. It takes the Asset Manager, the agent vault and an amount, and callstransferToCoreVaulton the Asset Manager while forwarding the attached money. Because the call is made from inside the helper, the Asset Manager sees the helper as the caller. That is what makes the refund come back to the helper, where it can be refused.
The receive() function reverts on any plain ETH transfer, which is exactly the path Transfers.transferNATAllowFailure uses for the refund. The deposit() function exists so the contract can still be funded despite the reverting receive(). The callTransferToCoreVault wrapper makes the helper contract itself the msg.sender of the Asset Manager call.
Step 4: Trigger the transfer with an overpayment
The test computes the transfer amount from the agent's minted balance, queries the fee, and adds an overpayment large enough to enter the refund branch:
const info = await agent.getAgentInfo();
const transferAmount = info.mintedUBA; // includes pool fee component
const cbTransferFee = await context.assetManager.transferToCoreVaultFee(transferAmount);
const overpay = toWei(10); // exceeds TRANSFER_GAS_ALLOWANCE * gasprice in HH env
const payTransferFee = cbTransferFee.add(overpay);
- The first line asks the agent for its current information.
- The second line takes the minted amount as the amount to transfer. The comment notes it includes a pool fee component, meaning the figure already accounts for a share taken by a shared pool.
- The third line asks the Asset Manager what the fee would be for that amount. Asking first is important: the test needs to know the exact fee so it can deliberately pay more.
- The fourth line sets the overpayment to 10 units of the currency. The comment explains why this is enough: in the test environment it exceeds the gas allowance multiplied by the gas price, so the refund branch will be entered.
- The fifth line adds the two together, giving the total the test will attach to the call.
Balances are recorded before the call, then the call is made through the helper:
const amBefore = toBN(await web3.eth.getBalance(context.assetManager.address));
const rrBefore = toBN(await web3.eth.getBalance(rr.address));
// 6) Initiate transfer to core vault via RefundRejector (msg.sender = rr)
await rr.callTransferToCoreVault(context.assetManager.address, agent.vaultAddress, transferAmount, { value: payTransferFee });
- The first two lines read the money held by the Asset Manager and by the helper before anything happens. Recording the starting point is what makes the later comparison meaningful; without it, a final balance tells you nothing.
- The third line is the actual trigger. It calls the helper's wrapper, which in turn calls the Asset Manager, attaching the fee plus the overpayment. The comment restates that the helper is the caller.
Inside transferToCoreVault, the fee is forwarded to the native address and the refund is attempted to msg.sender (the helper). The helper's receive() reverts, so transferNATAllowFailure returns false, and the return value is ignored.
Step 5: Observe the balances
The test asserts that the Asset Manager balance grew by exactly the overpayment and that the helper received nothing:
const amAfter = toBN(await web3.eth.getBalance(context.assetManager.address));
const rrAfter = toBN(await web3.eth.getBalance(rr.address));
// AssetManager balance increased by overpayment only (transfer fee forwarded out)
assertWeb3Equal(amAfter.sub(amBefore), overpay);
// RefundRejector didn't receive refund (receive() reverts)
assertWeb3Equal(rrAfter.sub(rrBefore), 0);
- The first two lines read the same two balances again, after the call.
assertWeb3Equal(amAfter.sub(amBefore), overpay);subtracts the before figure from the after figure and checks the result equals the overpayment. An assertion is a check that must hold; if it does not, the test fails. This line proves the extra money ended up inside the Asset Manager.assertWeb3Equal(rrAfter.sub(rrBefore), 0);checks that the helper's balance did not change at all. This proves the refund never arrived.
Together the two checks show the extra stayed behind in the Asset Manager and the helper received no refund.
The test is run with:
yarn hardhat test test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts
This is a command typed into a terminal, a text window where you type instructions instead of clicking. yarn is a tool that runs project commands, hardhat test tells the test framework to run tests, and the path points at the single test file to run.
and the logged output is:
Contract: AssetManagerSimulation.sol; test/integration/fasset-simulation/15-CoreVault-RefundPoC.ts; CoreVault refund failure PoC
✔ PoC: refund failure traps overpaid NAT in AssetManager (78ms)
1 passing (1s)
✨ Done in 4.18s.
The tick next to the test name means it passed, and the summary confirms one test passed. In other words, the demonstration behaved exactly as predicted.
Root cause
CoreVault.transferToCoreVault calls Transfers.transferNATAllowFailure for the refund and ignores its boolean return value. The function is explicitly designed to fail softly: it uses a fixed TRANSFER_GAS_ALLOWANCE = 100_000 gas and returns false when the transfer cannot be completed. Failing softly means it does not crash the whole operation; it just reports the bad news. Ignoring that signal means the overpaid NAT is neither delivered to the caller nor burned or redirected. It simply stays in the Asset Manager's balance.
The nonReentrant guard mentioned in the code comment protects against reentrancy during the transfers, but it does nothing about a refund that fails outright. Reentrancy is an attack where a contract is called back into while it is still mid-operation, like a customer who keeps interrupting the cashier to start a new transaction before the first is finished. The guard stops that, but it is irrelevant to a refund that simply bounces. The correct handling pattern already exists in CollateralReservations.sol, where a failed refund leads to burning the whole fee. The report does not describe any other defence that would recover the stranded funds.
Impact
Overpaid NAT remains in the Asset Manager's balance indefinitely. According to the report, no generic sweep or recovery function is exposed that could return it. A sweep function would be a general "collect stray money" button; without one, there is no route out. It requires the specific precondition that the caller is a contract acting as the agent vault owner whose receive() reverts or needs more than 100k gas. The report classifies the impact as permanent freezing of funds.
Fix
The recommended mitigation is to update CoreVault.transferToCoreVault to handle a failed refund the same way CollateralReservations does: check the return value of Transfers.transferNATAllowFailure(...) and, on failure, execute an alternative such as burning the fee or forwarding it to a recovery or burn address, so the funds are not permanently stuck. A mitigation is a change that removes or reduces the problem. The key idea is simple: if the refund cannot be delivered, do something deliberate with the money instead of leaving it in limbo.
Variants to test
- Other
transferNATAllowFailurecall sites: search the codebase for every use of the helper and check whether the boolean is consumed. A positive result is a call site where the return value is discarded and the recipient can be made to reject the transfer. - Gas-starved recipients: instead of a reverting
receive(), use a recipient whosereceive()succeeds only with more than 100k gas. A positive result is the same stranded balance with no revert surfaced to the caller. - Other refund and change-returning paths: any function that sends native value back to
msg.senderafter taking a fee is a candidate. A positive result is a balance increase on the contract that matches the unreturned amount. - Agent work address substitution: check whether other roles (work address, management address) can be pointed at a contract with a hostile
receive(), widening who can trigger the condition.
Hunting notes
This kind of bug hides in fee-handling branches where a soft-failure transfer helper is used for a refund. The signal during review is a call to a function whose name or signature returns bool (or an equivalent success flag) where the result is not assigned or checked. Comparing sibling contracts that implement the same pattern is a reliable way to spot the omission: here, CollateralReservations.sol checks the result and burns on failure, while CoreVault.sol does not.
The researcher demonstrated impact with an integration test that asserts both sides of the balance change: the Asset Manager keeps exactly the overpayment, and the helper's balance does not change. That concrete, reproducible balance assertion, together with the explicit precondition (a contract caller with a reverting receive()), is what turns a code observation into a reportable finding.
Glossary
- Smart contract: a small program that lives on a blockchain and moves digital money automatically according to fixed rules.
- Blockchain: a shared record book kept by many computers, where entries are very hard to change after the fact.
- FAssets: the Flare product described here, where agents deposit collateral and create tokens against it.
- Agent: the role that deposits collateral and creates FAssets tokens.
- Collateral: a deposit held as security, like a pawn shop keeping your valuables.
- Mint: to create new tokens.
- Core Vault: the central storage for the underlying assets that back the tokens.
- Asset Manager: the central contract that coordinates the system's actions.
- Diamond: a way of building one contract out of several smaller pieces so one address offers many features.
- Function: a named action a program can perform, like a button.
- Fee: money charged for an action.
- NAT: the name used here for the blockchain's own currency.
- Refund: sending back money that was paid in excess.
- Insight: the report label used for this finding.
- Permanent freezing of funds: money that is not stolen but can never be moved again.
- Repository: a shared folder of code with its full history.
- Commit: one saved snapshot of a repository, identified by a long code.
- GitHub: a website that hosts code repositories.
- Solidity: the main programming language for smart contracts on this kind of blockchain.
- Hardhat: a tool that runs a pretend blockchain on your own computer for testing.
- Integration test: a test that runs several parts of a system together.
- TypeScript: a programming language often used for test code.
- Harness: reusable setup code that builds a test world.
- Compiler: the program that turns written code into something the blockchain can run.
- Revert: a deliberate refusal that stops the program and undoes its work.
- Gas: the unit that measures computing effort on the blockchain.
msg.value: the amount of money attached to a call.- Branch: a fork in code, where one path or another is taken depending on a condition.
- Account: a wallet, real or simulated, that can hold money and make calls.
- Guard: a check that stops a function running unless conditions are met.
nonReentrant: a lock that stops a second call slipping in while the first is still running.- Reentrancy: an attack where a contract is called back into while it is still mid-operation.
- Wei: the smallest unit of this currency.
tx.gasprice: the price of one unit of gas at the moment of the transaction.bool: a value that is either true or false.receive(): a special function that runs automatically when a contract is sent plain money.- Burn: to deliberately destroy tokens so they can never be used again.
- Deploy: to put a program onto the blockchain so it can be called.
- Fixture: reusable setup code that prepares a test.
- Work address: the address an agent uses to act in the system.
- Interface: a description of the functions a contract offers, so other code knows how to call it.
- Wrapper: a small function that calls another function on your behalf.
- Assertion: a check in a test that must hold, or the test fails.
- Terminal: a text window where you type instructions instead of clicking.
- Mitigation: a change that removes or reduces a problem.
- Sweep function: a general function that collects stray money held by a contract.
- Proof of concept: a small demonstration that proves a problem is real rather than theoretical.