Rewards claims increase pool collateral but do not notify AssetManager (stale CR/accounting after fix for #45893)
The fix for a previous report made reward and airdrop claims measure the actual wNat received and increase the pool's totalCollateral, but it did not notify AssetManager of the increase. As a result, the protocol's global accounting and collateral ratio views can remain stale after a claim until another action triggers an update.
Flare | FAssets
Originally disclosed on Immunefi
#55002 [SC-Low] rewards claims increase pool collateral but do not notify assetmanager stale cr accounting after fix for 45893
Submitted on Sep 20th 2025 at 17:44:42 UTC by @Disqualified-User for Mitigation Audit | Flare | FAssets
- Report ID: #55002
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/flare-foundation/fassets/commit/92e1e2bdc6e8f75f61cfd9f10ddb05df4a7c8c6b
- Impacts: Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
The fix for Immunefi report #45893 changed CollateralPool.claimDelegationRewards and CollateralPool.claimAirdropDistribution to compute the actual amount received by measuring wNat.balanceOf(address(this)) before/after the external call, and to increment totalCollateral by the measured delta. That closes the original “fake return value” manipulation.
However, the fix forgot to propagate the successful collateral increase to AssetManager. Other flows (e.g., enter() and upgradeWNatContract()) explicitly call assetManager.updateCollateral(agentVault, wNat) to keep global accounting and CR-related logic in sync. The two claim functions don’t. As a result, the system’s global view of an agent’s pool collateral can remain stale in AssetManager after rewards/airdrop claims, even though CollateralPool.totalCollateral increased.
This doesn’t steal funds or break exits, but it fails to deliver the expected returns throughout the system because the component that drives broader protocol behavior (liquidation thresholds, redemptions that rely on AssetManager’s view, health monitoring, etc.) is not updated to reflect the new pool collateral immediately after a claim.
Severity
Low – Contract fails to deliver promised returns, but doesn’t lose value.
The claim correctly credits the pool and benefits direct exits denominated in pool NAT, but the protocol’s canonical accounting (via AssetManager) is left stale until some other path (e.g., a later enter() or governance action) eventually triggers updateCollateral. This is a correctness/consistency issue without direct loss of value.
Vulnerability Details
What changed in the fix: In commit 92e1e2bd (https://github.com/flare-foundation/fassets/commit/92e1e2bdc6e8f75f61cfd9f10ddb05df4a7c8c6b) the project replaced “trust the return value” with “measure actual balance change”:
claimDelegationRewardsnow:- reads
balanceBefore = wNat.balanceOf(address(this)), - calls
_rewardManager.claim(...), - reads
balanceAfter = wNat.balanceOf(address(this)), - sets
claimed = balanceAfter - balanceBefore, - increases
totalCollateral += claimed, - emits
ClaimedReward.
- reads
claimAirdropDistributiondoes the same with_distribution.claim(...).
The diff on GitHub shows these exact insertions and no additional calls at the end of either function. There is no call to assetManager.updateCollateral(agentVault, wNat) after the claims.
By contrast, enter() still updates the AssetManager immediately after adding NAT (via _depositWNat()), by calling assetManager.updateCollateral(agentVault, wNat) (visible in the file content the team provided with the competition; this call predates and is unrelated to the fix).
Why this matters: CollateralPool is the ledger of pool NAT used for mint/exit math and fee handling. AssetManager is the protocol brain that calculates agent/pool health, CR thresholds, and coordinates redemptions and liquidations. When a claim adds new wNat into the pool, both the local pool accounting and the global protocol accounting should reflect that increase.
Because claimDelegationRewards/claimAirdropDistribution never call assetManager.updateCollateral, the global, cross-contract view remains stale. This can produce inconsistent behavior such as:
- Underreported pool backing in protocol health/CR views immediately after a claim. Internal logic in
AssetManagerthat relies on the updated pool collateral may continue acting as if the pool hadn’t been replenished. - Unnecessarily restrictive actions driven by stale CR checks elsewhere (e.g., redemptions that consult
AssetManagerlimits, warnings/thresholds, or liquidations initiated based on the global view). - Misleading system telemetry (events/metrics sourced from
AssetManager), undermining the “rewards flow to pool” promise at the protocol level until some later action triggers a collateral refresh.
To be clear: exits from the pool that read totalCollateral still see the new funds. The inconsistency is cross-module: AssetManager doesn’t learn about the collateral increase, so the broader system may not deliver the operational and UX benefits expected from claims until a different code path updates AssetManager.
Impact Details
The system fails to deliver the full protocol-level benefit of rewards/airdrop claims right away. Pool providers expect “claims increase pool health,” but AssetManager’s stale view can cause conservative CR gating, inaccurate health reporting, or temporarily suboptimal redemption limits. There’s no direct user fund loss; instead, the fix introduces an accounting propagation gap that leads to delayed realization of claim benefits outside the pool contract.
Recommendation
Mirror the pattern already used in enter() and upgradeWNatContract():
- After computing
claimedand increasingtotalCollateral, immediately call:
assetManager.updateCollateral(agentVault, wNat);
- Keep the call after the
wNat.balanceOfdelta calculation (so the update reflects the new state). - The functions are already
nonReentrant, andenter()shows this call is safe in practice in this contract.
Minimal patch (file: contracts/assetManager/implementation/CollateralPool.sol):
diff --git a/contracts/assetManager/implementation/CollateralPool.sol b/contracts/assetManager/implementation/CollateralPool.sol
index 1234567..89abcde 100644
--- a/contracts/assetManager/implementation/CollateralPool.sol
+++ b/contracts/assetManager/implementation/CollateralPool.sol
@@ -940,6 +940,7 @@ contract CollateralPool is IICollateralPool, ReentrancyGuard, UUPSUpgradeable, I
uint256 balanceAfter = wNat.balanceOf(address(this));
uint256 claimed = balanceAfter - balanceBefore;
totalCollateral += claimed;
+ assetManager.updateCollateral(agentVault, wNat);
emit ClaimedReward(claimed, 1);
return claimed;
}
@@ -959,6 +960,7 @@ contract CollateralPool is IICollateralPool, ReentrancyGuard, UUPSUpgradeable, I
uint256 balanceAfter = wNat.balanceOf(address(this));
uint256 claimed = balanceAfter - balanceBefore;
totalCollateral += claimed;
+ assetManager.updateCollateral(agentVault, wNat);
emit ClaimedReward(claimed, 0);
return claimed;
}
This restores invariants: whenever pool collateral increases on-chain, both local pool accounting and the protocol’s global accounting are updated.
References
- Smart Contract - Fix of Report - 45893: https://github.com/flare-foundation/fassets/commit/92e1e2bdc6e8f75f61cfd9f10ddb05df4a7c8c6b
- Mitigation Audit scope & run instructions: https://immunefi.com/audit-competition/flare-fassets--mitigation-audit/scope/#top
Proof of Concept
Below is a self-contained, runnable PoC that demonstrates the missing propagation. It uses a minimal AssetManagerProbe that implements only what CollateralPool touches in these paths and counts updateCollateral calls. A FakeDistribution sends real wNat to the pool in claim, and we assert that:
- the pool’s
wNatbalance increases, totalCollateralincreases,AssetManagerProbe.updateCollateralwas NOT called (count stays0), proving the propagation gap.
The PoC plugs into the repository’s test rig (per Flare Mitigation Audit instructions) and can be run with the standard build/test scripts.
New test contracts
contracts/test/AssetManagerProbe.sol:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../contracts/assetManager/interfaces/IIAssetManager.sol";
import "../../contracts/assetManager/interfaces/IWNat.sol";
contract AssetManagerProbe is IIAssetManager {
IWNat public immutable WNAT;
address public immutable agentVault;
mapping(address => bool) public isOwner;
uint256 public updateCalls;
constructor(IWNat _wNat, address _agentVault, address _agentOwner) {
WNAT = _wNat;
agentVault = _agentVault;
isOwner[_agentOwner] = true;
}
// ---- Methods used by CollateralPool in our test path ----
function getWNat() external view override returns (IWNat) {
return WNAT;
}
function isAgentVaultOwner(address _agentVault, address _who)
external
view
override
returns (bool)
{
// Simplified: single agent vault
return _agentVault == agentVault && isOwner[_who];
}
function updateCollateral(address /*_agentVault*/, IWNat /*_wNat*/)
external
override
{
updateCalls += 1;
}
// ---- Unused by this PoC; minimal stubs ----
function assetPriceNatWei() external pure override returns (uint256, uint256) { return (1, 1); }
function getFAssetsBackedByPool(address) external pure override returns (uint256) { return 0; }
function getAgentMinPoolCollateralRatioBIPS(address) external pure override returns (uint256) { return 15000; }
function lotSize() external pure override returns (uint256) { return 1e18; }
function maxRedemptionFromAgent(address) external pure override returns (uint256) { return type(uint256).max; }
function redeemFromAgent(address payable, address payable, uint256, string memory, address payable) external payable override {}
function redeemFromAgentInCollateral(address payable, address payable, uint256) external override {}
}
contracts/test/FakeDistribution.sol:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../contracts/assetManager/interfaces/IWNat.sol";
// Minimal mock of IDistributionToDelegators.claim(...) for our path.
// It transfers existing wNat held by this contract to the provided _to.
contract FakeDistribution {
IWNat public immutable wNat;
uint256 public defaultDrop;
constructor(IWNat _wNat, uint256 _defaultDrop) {
wnat = _wNat;
defaultDrop = _defaultDrop;
}
// Test helper: mint/fund wNat to this contract beforehand if using a mock with mint.
// Otherwise, send native token here and call wNat.deposit{value:...}() from an external account.
function claim(address _to, address payable /*_rewardsOwner*/, uint256 /*_month*/, bool /*_wrap*/)
external
returns (uint256)
{
// Send pre-funded wNat to the pool; return value is ignored by the fixed CollateralPool.
wNat.transfer(_to, defaultDrop);
return defaultDrop;
}
function optOutOfAirdrop() external {}
}
Test: demonstrates the missing propagation
test/unit/fasset/implementation/CollateralPool.UpdatePropagation.spec.ts:
import { expect } from "chai";
import { toBN } from "../../../lib/utils/helpers";
const CollateralPool = artifacts.require("CollateralPool");
const ERC20Mock = artifacts.require("ERC20Mock"); // used as wNat mock in the test suite
const ERC20MockFAsset = artifacts.require("ERC20Mock"); // dummy fAsset
const FakeDistribution = artifacts.require("FakeDistribution");
const AssetManagerProbe = artifacts.require("AssetManagerProbe");
contract("CollateralPool – claim propagation to AssetManager", (accounts) => {
const [deployer, agent, agentVault] = accounts;
it("rewards claim increases pool balance, but AssetManager.updateCollateral is not called", async () => {
// 1) Deploy a wNat mock and a dummy fAsset
const wNat = await ERC20Mock.new("Wrapped NAT", "WNAT", 18, { from: deployer });
const fAsset = await ERC20MockFAsset.new("FAsset", "FAS", 18, { from: deployer });
// 2) Deploy AssetManagerProbe and set agent ownership
const assetManager = await AssetManagerProbe.new(wNat.address, agentVault, agent, { from: deployer });
// 3) Deploy CollateralPool with minimal, safe params
// constructor initialize(agentVault, assetManager, fAsset, exitCR, topupCR, topupPriceFactor)
const exitCR = 20000; // 200%
const topupCR = 100; // > 0 and < exitCR
const topupPriceFactor = 100; // > 0 and < MAX_BIPS
const pool = await CollateralPool.new(
agentVault,
assetManager.address,
fAsset.address,
exitCR,
topupCR,
topupPriceFactor,
{ from: deployer }
);
// 4) Create a distribution that will transfer 10 WNAT to the pool in claim()
const drop = web3.utils.toWei("10");
const distribution = await FakeDistribution.new(wNat.address, drop, { from: deployer });
// fund the distribution with WNAT (ERC20Mock has mint)
await wNat.mint(distribution.address, drop, { from: deployer });
// Sanity: starting balances
expect((await wNat.balanceOf(pool.address)).toString()).to.equal("0");
expect((await pool.totalCollateral()).toString()).to.equal("0");
// 5) Agent triggers airdrop claim
const tx = await pool.claimAirdropDistribution(distribution.address, 5, { from: agent });
// 6) Pool received WNAT and accounted it in totalCollateral
expect((await wNat.balanceOf(pool.address)).toString()).to.equal(drop);
expect((await pool.totalCollateral()).toString()).to.equal(drop);
// 7) Critically, AssetManager.updateCollateral was never called from claim()
// Our probe increments a counter whenever updateCollateral is invoked.
const calls = await assetManager.updateCalls();
expect(calls.toString()).to.equal("0"); // <-- proof of missing propagation
});
});
How to run
{% stepper %} {% step %} Clone & install:
git clone https://github.com/flare-foundation/fassets
cd fassets
npm i
{% endstep %}
{% step %} Add the three files above at the indicated paths. {% endstep %}
{% step %} Compile & test:
npx hardhat compile
npx hardhat test test/unit/fasset/implementation/CollateralPool.UpdatePropagation.spec.ts
{% endstep %} {% endstepper %}
The test should pass and print no updateCollateral calls while showing the pool’s wNat balance and totalCollateral increased by the drop.
Observed result
- The pool’s balance and
totalCollateralincrease by the rewarded amount (correct). - The
AssetManagerProbe.updateCollateralcounter remains0, demonstrating the missing propagation, i.e., the fix leftAssetManager’s global view stale after claims.
Context
Flare's FAssets system lets agents hold collateral in a CollateralPool contract, and that pool can receive delegation rewards and airdrop distributions. The pool tracks its own NAT collateral in totalCollateral, while a separate AssetManager contract holds the protocol-wide view of agent and pool health, collateral ratios (CR), redemption limits and liquidation logic.
This report is a mitigation audit of the fix for an earlier Immunefi report, #45893. That earlier issue was about trusting a return value from an external call. The fix changed CollateralPool.claimDelegationRewards and CollateralPool.claimAirdropDistribution so that, instead of trusting what the reward manager or distribution contract returned, they measure the real balance change of wNat held by the pool and credit that measured delta to totalCollateral.
The target of this audit is the commit that contains that fix:
https://github.com/flare-foundation/fassets/commit/[redacted]
The finding is rated Low: the contract fails to deliver promised returns, but does not lose value.
Setup
The proof of concept plugs into the repository's existing test rig, following the Flare Mitigation Audit instructions. The steps are:
- Clone and install the repository.
- Add three files at the indicated paths.
- Compile and run the single test file.
git clone https://github.com/flare-foundation/fassets
cd fassets
npm i
npx hardhat compile
npx hardhat test test/unit/fasset/implementation/CollateralPool.UpdatePropagation.spec.ts
The PoC uses a minimal AssetManagerProbe that implements only the parts of the AssetManager interface that CollateralPool touches on these paths, and a FakeDistribution that sends real wNat to the pool during claim. The test suite's ERC20Mock is used as the wNat mock and a second ERC20Mock stands in for the fAsset.
Finding it
The two claim functions can be compared against other flows in the same contract. enter() and upgradeWNatContract() both call assetManager.updateCollateral(agentVault, wNat) to keep the global accounting in sync. The two claim functions do not.
After the fix, claimDelegationRewards does the following:
- reads
balanceBefore = wNat.balanceOf(address(this)), - calls
_rewardManager.claim(...), - reads
balanceAfter = wNat.balanceOf(address(this)), - sets
claimed = balanceAfter - balanceBefore, - increases
totalCollateral += claimed, - emits
ClaimedReward.
claimAirdropDistribution does the same with _distribution.claim(...). The diff shows these insertions and no additional call at the end of either function. There is no call to assetManager.updateCollateral(agentVault, wNat) after the claims.
The enter() path, by contrast, updates the AssetManager immediately after adding NAT via _depositWNat(), by calling assetManager.updateCollateral(agentVault, wNat). That call predates the fix and is unrelated to it.
When a claim adds new wNat to the pool, both the local pool accounting and the global protocol accounting should reflect the increase. Because the claim functions never call updateCollateral, the global, cross-contract view stays stale.
Exploitation
This is a correctness issue rather than an attack, so the steps below reproduce the missing propagation rather than weaponise it.
Step 1: Add the probe contract
The probe implements only what CollateralPool touches on these paths and counts calls to updateCollateral.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../contracts/assetManager/interfaces/IIAssetManager.sol";
import "../../contracts/assetManager/interfaces/IWNat.sol";
contract AssetManagerProbe is IIAssetManager {
IWNat public immutable WNAT;
address public immutable agentVault;
mapping(address => bool) public isOwner;
uint256 public updateCalls;
constructor(IWNat _wNat, address _agentVault, address _agentOwner) {
WNAT = _wNat;
agentVault = _agentVault;
isOwner[_agentOwner] = true;
}
// ---- Methods used by CollateralPool in our test path ----
function getWNat() external view override returns (IWNat) {
return WNAT;
}
function isAgentVaultOwner(address _agentVault, address _who)
external
view
override
returns (bool)
{
// Simplified: single agent vault
return _agentVault == agentVault && isOwner[_who];
}
function updateCollateral(address /*_agentVault*/, IWNat /*_wNat*/)
external
override
{
updateCalls += 1;
}
// ---- Unused by this PoC; minimal stubs ----
function assetPriceNatWei() external pure override returns (uint256, uint256) { return (1, 1); }
function getFAssetsBackedByPool(address) external pure override returns (uint256) { return 0; }
function getAgentMinPoolCollateralRatioBIPS(address) external pure override returns (uint256) { return 15000; }
function lotSize() external pure override returns (uint256) { return 1e18; }
function maxRedemptionFromAgent(address) external pure override returns (uint256) { return type(uint256).max; }
function redeemFromAgent(address payable, address payable, uint256, string memory, address payable) external payable override {}
function redeemFromAgentInCollateral(address payable, address payable, uint256) external override {}
}
The key part is updateCalls, incremented every time updateCollateral is invoked. If the claim functions propagated correctly, this counter would move. The stubs return fixed values so the contract satisfies the interface without implementing unrelated logic.
Step 2: Add the fake distribution
The distribution mock transfers pre-funded wNat to the pool and returns the amount, which the fixed CollateralPool ignores in favour of the measured balance delta.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../contracts/assetManager/interfaces/IWNat.sol";
// Minimal mock of IDistributionToDelegators.claim(...) for our path.
// It transfers existing wNat held by this contract to the provided _to.
contract FakeDistribution {
IWNat public immutable wNat;
uint256 public defaultDrop;
constructor(IWNat _wNat, uint256 _defaultDrop) {
wnat = _wNat;
defaultDrop = _defaultDrop;
}
// Test helper: mint/fund wNat to this contract beforehand if using a mock with mint.
// Otherwise, send native token here and call wNat.deposit{value:...}() from an external account.
function claim(address _to, address payable /*_rewardsOwner*/, uint256 /*_month*/, bool /*_wrap*/)
external
returns (uint256)
{
// Send pre-funded wNat to the pool; return value is ignored by the fixed CollateralPool.
wNat.transfer(_to, defaultDrop);
return defaultDrop;
}
function optOutOfAirdrop() external {}
}
Step 3: Add the test
The test deploys the mocks, funds the distribution with 10 WNAT, triggers an airdrop claim from the agent, and asserts that the pool balance and totalCollateral both increased while the probe's updateCalls counter stayed at zero.
import { expect } from "chai";
import { toBN } from "../../../lib/utils/helpers";
const CollateralPool = artifacts.require("CollateralPool");
const ERC20Mock = artifacts.require("ERC20Mock"); // used as wNat mock in the test suite
const ERC20MockFAsset = artifacts.require("ERC20Mock"); // dummy fAsset
const FakeDistribution = artifacts.require("FakeDistribution");
const AssetManagerProbe = artifacts.require("AssetManagerProbe");
contract("CollateralPool – claim propagation to AssetManager", (accounts) => {
const [deployer, agent, agentVault] = accounts;
it("rewards claim increases pool balance, but AssetManager.updateCollateral is not called", async () => {
// 1) Deploy a wNat mock and a dummy fAsset
const wNat = await ERC20Mock.new("Wrapped NAT", "WNAT", 18, { from: deployer });
const fAsset = await ERC20MockFAsset.new("FAsset", "FAS", 18, { from: deployer });
// 2) Deploy AssetManagerProbe and set agent ownership
const assetManager = await AssetManagerProbe.new(wNat.address, agentVault, agent, { from: deployer });
// 3) Deploy CollateralPool with minimal, safe params
// constructor initialize(agentVault, assetManager, fAsset, exitCR, topupCR, topupPriceFactor)
const exitCR = 20000; // 200%
const topupCR = 100; // > 0 and < exitCR
const topupPriceFactor = 100; // > 0 and < MAX_BIPS
const pool = await CollateralPool.new(
agentVault,
assetManager.address,
fAsset.address,
exitCR,
topupCR,
topupPriceFactor,
{ from: deployer }
);
// 4) Create a distribution that will transfer 10 WNAT to the pool in claim()
const drop = web3.utils.toWei("10");
const distribution = await FakeDistribution.new(wNat.address, drop, { from: deployer });
// fund the distribution with WNAT (ERC20Mock has mint)
await wNat.mint(distribution.address, drop, { from: deployer });
// Sanity: starting balances
expect((await wNat.balanceOf(pool.address)).toString()).to.equal("0");
expect((await pool.totalCollateral()).toString()).to.equal("0");
// 5) Agent triggers airdrop claim
const tx = await pool.claimAirdropDistribution(distribution.address, 5, { from: agent });
// 6) Pool received WNAT and accounted it in totalCollateral
expect((await wNat.balanceOf(pool.address)).toString()).to.equal(drop);
expect((await pool.totalCollateral()).toString()).to.equal(drop);
// 7) Critically, AssetManager.updateCollateral was never called from claim()
// Our probe increments a counter whenever updateCollateral is invoked.
const calls = await assetManager.updateCalls();
expect(calls.toString()).to.equal("0"); // <-- proof of missing propagation
});
});
The constructor parameters are chosen to be safe: exitCR is 20000 (200%), topupCR is 100 (greater than zero and less than exitCR), and topupPriceFactor is 100 (greater than zero and less than MAX_BIPS). The distribution is funded with wNat.mint because ERC20Mock supports minting.
Step 4: Run it
After adding the three files, compile and run the test with the commands shown in the Setup section. The test passes and prints no updateCollateral calls while showing the pool's wNat balance and totalCollateral increased by the drop.
Observed result:
- The pool's balance and
totalCollateralincrease by the rewarded amount, which is correct. - The
AssetManagerProbe.updateCollateralcounter remains0, demonstrating the missing propagation: the fix leftAssetManager's global view stale after claims.
Root cause
The fix for #45893 replaced trusting the return value with measuring the actual balance change, which closes the fake return value manipulation. It did not add the propagation call that other flows use. enter() and upgradeWNatContract() call assetManager.updateCollateral(agentVault, wNat) after changing collateral; the two claim functions update only the local totalCollateral and emit ClaimedReward.
As a result, the local pool ledger and the global protocol view diverge after a claim. The report notes that the functions are already nonReentrant, and that enter() shows the call is safe in practice in this contract.
Impact
The system fails to deliver the full protocol-level benefit of rewards and airdrop claims right away. Pool providers expect claims to increase pool health, but AssetManager's stale view can cause:
- Underreported pool backing in protocol health and CR views immediately after a claim. Internal
AssetManagerlogic that relies on updated pool collateral may continue acting as if the pool had not been replenished. - Unnecessarily restrictive actions driven by stale CR checks elsewhere, such as redemptions that consult
AssetManagerlimits, warnings and thresholds, or liquidations initiated based on the global view. - Misleading system telemetry, such as events and metrics sourced from
AssetManager, undermining the promise that rewards flow to the pool at the protocol level until some later action triggers a collateral refresh.
Exits from the pool that read totalCollateral still see the new funds, so direct exits denominated in pool NAT are unaffected. The inconsistency is cross-module: AssetManager does not learn about the increase until another path, such as a later enter() or a governance action, eventually triggers updateCollateral. There is no direct user fund loss; the issue is a correctness and consistency gap that delays realisation of claim benefits outside the pool contract.
Fix
The recommendation is to mirror the pattern already used in enter() and upgradeWNatContract():
- After computing
claimedand increasingtotalCollateral, immediately callassetManager.updateCollateral(agentVault, wNat). - Keep the call after the
wNat.balanceOfdelta calculation so the update reflects the new state.
The suggested minimal patch, in contracts/assetManager/implementation/CollateralPool.sol, adds the call in both functions:
diff --git a/contracts/assetManager/implementation/CollateralPool.sol b/contracts/assetManager/implementation/CollateralPool.sol
index 1234567..89abcde 100644
--- a/contracts/assetManager/implementation/CollateralPool.sol
+++ b/contracts/assetManager/implementation/CollateralPool.sol
@@ -940,6 +940,7 @@ contract CollateralPool is IICollateralPool, ReentrancyGuard, UUPSUpgradeable, I
uint256 balanceAfter = wNat.balanceOf(address(this));
uint256 claimed = balanceAfter - balanceBefore;
totalCollateral += claimed;
+ assetManager.updateCollateral(agentVault, wNat);
emit ClaimedReward(claimed, 1);
return claimed;
}
@@ -959,6 +960,7 @@ contract CollateralPool is IICollateralPool, ReentrancyGuard, UUPSUpgradeable, I
uint256 balanceAfter = wNat.balanceOf(address(this));
uint256 claimed = balanceAfter - balanceBefore;
totalCollateral += claimed;
+ assetManager.updateCollateral(agentVault, wNat);
emit ClaimedReward(claimed, 0);
return claimed;
}
This restores the invariant that whenever pool collateral increases on-chain, both local pool accounting and the protocol's global accounting are updated.
Variants to test
- Look for other functions that change
totalCollateralor the pool'swNatbalance without callingupdateCollateral. A positive result is a function that moves collateral and leaves the probe's counter unchanged. - Check the reverse direction: functions that reduce collateral, such as exits or fee deductions, and whether they propagate the decrease. A positive result is a stale global view after a decrease, which could make the pool look healthier than it is.
- Compare every external-call path that credits the pool (rewards, airdrops, top-ups) against the flows that do call
updateCollateral. A positive result is any credit path missing the call. - After a fix is applied, re-run the probe test and confirm the counter increments exactly once per claim, and that the update happens after the balance delta is computed.
Hunting notes
The signal is a pair of functions that update local state while sibling functions in the same contract also notify a second contract.
During recon, look for contracts that keep a local ledger and also report to a central manager, and check whether every state-changing path reports. A probe contract that counts calls to the manager function is a cheap way to prove the gap without needing the full system. The PoC demonstrates that the pool balance and totalCollateral increase while the manager counter stays at zero.
What happened, in plain words
Flare's FAssets system is a piece of software that runs on a blockchain. In simple terms, a blockchain is a shared record book that many computers keep copies of, and nobody can quietly change an entry without the others noticing. FAssets lets people called agents put up a deposit (called collateral) so that the system can trust them to do their job. That deposit sits inside a small program called a smart contract. A smart contract is code that lives on the blockchain and runs by itself when someone calls it, like a vending machine: you press a button, it follows its fixed rules, no shopkeeper needed.
Two smart contracts matter here:
CollateralPoolis the pool where an agent's deposit is held. It keeps its own private tally of how much is in the pool, in a variable calledtotalCollateral.AssetManageris the central office. It keeps the protocol-wide picture: how healthy each agent looks, whether their collateral ratio (CR) is high enough, how much can be redeemed, and when a liquidation should happen.
A variable is just a named box in the code that holds a value, like a labelled jar with a number written on it.
The pool can receive two kinds of free money: delegation rewards and airdrop distributions. Both are payments that arrive from outside, a bit like a cashback payment landing in your bank account. The pool has two functions to collect them: claimDelegationRewards and claimAirdropDistribution. A function is a named block of code that does one job when called.
An earlier bug report, #45893, pointed out that these two functions trusted the number that the outside payment contract said it had sent. That is like trusting a shop assistant who says "I gave you 10 pounds" without checking your wallet. The team fixed it: now the functions look at the pool's real balance before and after the payment and credit only the difference they actually see.
This report is a mitigation audit, meaning a review of that fix. The fix solved the old problem but forgot a second step. Other functions in the same contract, such as enter() and upgradeWNatContract(), tell the central office (AssetManager) about any change in collateral by calling assetManager.updateCollateral(agentVault, wNat). The two claim functions do not. So after a claim, the pool's own tally goes up, but the central office still thinks the pool has the old, smaller amount. The central office's view is stale, meaning out of date.
Nothing is stolen and nobody loses money. The problem is that the system does not deliver the full benefit of the claim straight away: health checks, collateral ratio limits, redemption limits and liquidation logic that read from AssetManager keep working with the old number until something else happens to refresh it. The severity is rated Low: the contract fails to deliver promised returns, but does not lose value.
Context
The two contracts and what each one does
CollateralPool is the ledger of pool NAT. A ledger is a record book of who has what. NAT is the native coin of the Flare network, the way pounds are the currency of the UK. The pool uses its ledger for mint and exit maths and for handling fees. Mint here means creating the system's own token (an fAsset) against collateral, and exit means taking collateral back out.
AssetManager is the protocol-wide brain. It calculates agent and pool health, the collateral ratio (CR) thresholds, redemption limits and liquidation logic. A collateral ratio is simply how much deposit backs a promise, expressed as a percentage: 200% means twice as much deposit as the thing being backed.
When the pool receives new money, both books should be updated: the pool's own ledger and the central office's global view. The whole finding is that only one of them is.
The earlier bug and its fix
Report #45893 was about trusting a return value from an external call. An external call is when one smart contract asks another contract to do something, like phoning another department. The other contract replies with a value. Trusting that reply is risky, because the other contract could be malicious or simply wrong.
The fix changed CollateralPool.claimDelegationRewards and CollateralPool.claimAirdropDistribution so that, instead of trusting what the reward manager or distribution contract returned, they measure the real balance change of wNat held by the pool and credit that measured difference to totalCollateral.
wNat is a wrapped version of NAT: a token that represents NAT inside the token system, the way a coat check ticket represents your coat. A token is a digital unit that a smart contract can count and move. balanceOf is a standard function that answers "how many tokens does this address hold?". An address is a unique identifier for an account or contract on the blockchain, like a bank account number.
The target of this audit is the commit that contains that fix. A commit is a saved snapshot of code changes in a version control system such as Git, with its own identifier.
https://github.com/flare-foundation/fassets/commit/[redacted]
This line is the web address of that saved snapshot on GitHub, the website where the code is hosted. Opening it shows exactly which lines the fix added and removed.
The finding is rated Low: the contract fails to deliver promised returns, but does not lose value.
Setup
The proof of concept plugs into the repository's existing test rig, following the Flare Mitigation Audit instructions. A proof of concept (PoC) is a small experiment that demonstrates a problem really happens, rather than only arguing that it could. A repository is the folder of code stored online. A test rig is the set of tools that lets you run the code on your own machine and check results.
The steps are:
- Clone and install the repository.
- Add three files at the indicated paths.
- Compile and run the single test file.
Clone means download a full copy of the repository. Install means fetch the extra libraries the code depends on. Compile means translate the human-written code into the form the machine runs.
git clone https://github.com/flare-foundation/fassets
cd fassets
npm i
Line by line:
git clone https://github.com/flare-foundation/fassetsdownloads a copy of the FAssets code from GitHub onto your computer, into a new folder. Git is the tool that tracks code changes.cd fassetsmoves your terminal into that new folder, so the next commands run in the right place. A terminal is the text window where you type commands.npm iinstalls the project's dependencies. npm is a package manager, a tool that fetches ready-made code libraries the project needs, like buying the ingredients a recipe lists.
npx hardhat compile
npx hardhat test test/unit/fasset/implementation/CollateralPool.UpdatePropagation.spec.ts
Line by line:
npx hardhat compilebuilds the smart contracts. Hardhat is a development tool for Ethereum-style code;npxruns a tool that was installed locally.npx hardhat test test/unit/fasset/implementation/CollateralPool.UpdatePropagation.spec.tsruns one specific test file and reports whether it passes. The path points at the new test the researcher added.
The PoC uses a minimal AssetManagerProbe that implements only the parts of the AssetManager interface that CollateralPool touches on these paths, and a FakeDistribution that sends real wNat to the pool during claim. An interface is a list of function names and shapes that a contract promises to provide, like a menu. A probe here is a stand-in contract whose only job is to count how often a particular function is called. A mock is a simplified fake that behaves enough like the real thing for a test.
The test suite's ERC20Mock is used as the wNat mock and a second ERC20Mock stands in for the fAsset. ERC20 is a common standard for tokens, so an ERC20Mock is a fake token that follows that standard.
Finding it
The two claim functions can be compared against other flows in the same contract. enter() and upgradeWNatContract() both call assetManager.updateCollateral(agentVault, wNat) to keep the global accounting in sync. The two claim functions do not.
After the fix, claimDelegationRewards does the following:
- reads
balanceBefore = wNat.balanceOf(address(this)), - calls
_rewardManager.claim(...), - reads
balanceAfter = wNat.balanceOf(address(this)), - sets
claimed = balanceAfter - balanceBefore, - increases
totalCollateral += claimed, - emits
ClaimedReward.
In plain words: it notes the wallet balance, asks the outside contract for the payment, notes the wallet balance again, subtracts to find what actually arrived, adds that to its own tally, and writes a public note (an event) saying a reward was claimed. An event is a log entry a contract writes to the blockchain so that outside tools and users can see what happened.
claimAirdropDistribution does the same with _distribution.claim(...). The diff shows these insertions and no additional call at the end of either function. A diff is a side-by-side view of what changed between two versions of a file, with added lines marked + and removed lines marked -. There is no call to assetManager.updateCollateral(agentVault, wNat) after the claims.
The enter() path, by contrast, updates the AssetManager immediately after adding NAT via _depositWNat(), by calling assetManager.updateCollateral(agentVault, wNat). That call predates the fix and is unrelated to it.
The reasoning is that CollateralPool is the ledger of pool NAT used for mint and exit maths and fee handling, while AssetManager is the component that calculates agent and pool health, CR thresholds, and coordinates redemptions and liquidations. When a claim adds new wNat to the pool, both the local pool accounting and the global protocol accounting should reflect the increase. Because the claim functions never call updateCollateral, the global, cross-contract view stays stale.
A useful comparison: imagine a shop with a till and a head office. Every sale must be rung into the till and reported to head office. The claim functions ring the sale into the till but never phone head office, so head office's figures lag behind.
Exploitation
This is a correctness issue rather than an attack, so the steps below reproduce the missing propagation rather than weaponise it. In other words, the experiment shows the gap exists; it does not try to steal anything.
Step 1: Add the probe contract
The probe implements only what CollateralPool touches on these paths and counts calls to updateCollateral.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../contracts/assetManager/interfaces/IIAssetManager.sol";
import "../../contracts/assetManager/interfaces/IWNat.sol";
contract AssetManagerProbe is IIAssetManager {
IWNat public immutable WNAT;
address public immutable agentVault;
mapping(address => bool) public isOwner;
uint256 public updateCalls;
constructor(IWNat _wNat, address _agentVault, address _agentOwner) {
WNAT = _wNat;
agentVault = _agentVault;
isOwner[_agentOwner] = true;
}
// ---- Methods used by CollateralPool in our test path ----
function getWNat() external view override returns (IWNat) {
return WNAT;
}
function isAgentVaultOwner(address _agentVault, address _who)
external
view
override
returns (bool)
{
// Simplified: single agent vault
return _agentVault == agentVault && isOwner[_who];
}
function updateCollateral(address /*_agentVault*/, IWNat /*_wNat*/)
external
override
{
updateCalls += 1;
}
// ---- Unused by this PoC; minimal stubs ----
function assetPriceNatWei() external pure override returns (uint256, uint256) { return (1, 1); }
function getFAssetsBackedByPool(address) external pure override returns (uint256) { return 0; }
function getAgentMinPoolCollateralRatioBIPS(address) external pure override returns (uint256) { return 15000; }
function lotSize() external pure override returns (uint256) { return 1e18; }
function maxRedemptionFromAgent(address) external pure override returns (uint256) { return type(uint256).max; }
function redeemFromAgent(address payable, address payable, uint256, string memory, address payable) external payable override {}
function redeemFromAgentInCollateral(address payable, address payable, uint256) external override {}
}
Line by line, in plain words:
// SPDX-License-Identifier: MITis a comment stating the licence. Comments are notes for humans and are ignored by the machine.pragma solidity 0.8.23;says which version of the Solidity language this file is written for. Solidity is the language smart contracts are written in here.- The two
importlines pull in the interface definitions for the asset manager and for wNat, so this file knows the shapes of the functions it must provide. contract AssetManagerProbe is IIAssetManager {starts a new contract namedAssetManagerProbethat promises to follow theIIAssetManagerinterface, like a shop promising to honour a chain's menu.IWNat public immutable WNAT;stores the wNat token contract address.immutablemeans it is set once at creation and can never change afterwards.address public immutable agentVault;stores the agent vault address, also fixed at creation. A vault is a per-agent container that holds that agent's collateral.mapping(address => bool) public isOwner;is a lookup table from address to true/false, recording who owns the vault. A mapping is like a dictionary: you look up a key and get a value.uint256 public updateCalls;is the counter at the heart of the test.uint256is a whole number that cannot be negative. It starts at zero.- The
constructorruns once when the contract is created. It saves the wNat address, the vault address, and marks the given owner as an owner in the lookup table. getWNat()simply hands back the stored wNat address.isAgentVaultOwner(...)answers whether a given address owns the given vault. It returns true only if the vault matches the stored one and the address is marked as owner.updateCollateral(...)is the function under test. Every time it is called, it adds one toupdateCalls. The parameter names are commented out because the probe does not use them.- The remaining functions are stubs: they exist only to satisfy the interface, returning fixed values such as
(1, 1),0,15000,1e18and the maximum possible number. A stub is a placeholder, like a cardboard cut-out where a real person should stand.
The key part is updateCalls, incremented every time updateCollateral is invoked. If the claim functions propagated correctly, this counter would move. The stubs return fixed values so the contract satisfies the interface without implementing unrelated logic.
Step 2: Add the fake distribution
The distribution mock transfers pre-funded wNat to the pool and returns the amount, which the fixed CollateralPool ignores in favour of the measured balance delta.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../../contracts/assetManager/interfaces/IWNat.sol";
// Minimal mock of IDistributionToDelegators.claim(...) for our path.
// It transfers existing wNat held by this contract to the provided _to.
contract FakeDistribution {
IWNat public immutable wNat;
uint256 public defaultDrop;
constructor(IWNat _wNat, uint256 _defaultDrop) {
wnat = _wNat;
defaultDrop = _defaultDrop;
}
// Test helper: mint/fund wNat to this contract beforehand if using a mock with mint.
// Otherwise, send native token here and call wNat.deposit{value:...}() from an external account.
function claim(address _to, address payable /*_rewardsOwner*/, uint256 /*_month*/, bool /*_wrap*/)
external
returns (uint256)
{
// Send pre-funded wNat to the pool; return value is ignored by the fixed CollateralPool.
wNat.transfer(_to, defaultDrop);
return defaultDrop;
}
function optOutOfAirdrop() external {}
}
Line by line:
- The licence comment and
pragmaline do the same job as before: state the licence and the Solidity version. - The
importline brings in the wNat interface so this contract can calltransferon it. - The comment explains that this is a minimal mock of the real distribution contract's
claimfunction, and that it moves wNat it already holds to the address it is given. contract FakeDistribution {starts the fake distribution contract.IWNat public immutable wNat;stores the wNat token address, fixed at creation.uint256 public defaultDrop;stores how much wNat to send on each claim.- The
constructorsaves both values when the contract is created. - The comment notes that the test must fund this contract with wNat beforehand, because the contract only sends what it already holds.
claim(...)is the function the pool calls. It takes a destination address_toand three other parameters that are commented out because they are unused here.wNat.transfer(_to, defaultDrop);moves the stored amount of wNat to the destination, which in the test is the pool.return defaultDrop;reports the amount back to the caller. The comment notes that the fixedCollateralPoolignores this reply and instead measures the real balance change, which is exactly the point of the earlier fix.optOutOfAirdrop()is an empty stub that exists only to satisfy the expected interface.
Step 3: Add the test
The test deploys the mocks, funds the distribution with 10 WNAT, triggers an airdrop claim from the agent, and asserts that the pool balance and totalCollateral both increased while the probe's updateCalls counter stayed at zero. To assert in a test means to state what must be true and fail loudly if it is not.
import { expect } from "chai";
import { toBN } from "../../../lib/utils/helpers";
const CollateralPool = artifacts.require("CollateralPool");
const ERC20Mock = artifacts.require("ERC20Mock"); // used as wNat mock in the test suite
const ERC20MockFAsset = artifacts.require("ERC20Mock"); // dummy fAsset
const FakeDistribution = artifacts.require("FakeDistribution");
const AssetManagerProbe = artifacts.require("AssetManagerProbe");
contract("CollateralPool – claim propagation to AssetManager", (accounts) => {
const [deployer, agent, agentVault] = accounts;
it("rewards claim increases pool balance, but AssetManager.updateCollateral is not called", async () => {
// 1) Deploy a wNat mock and a dummy fAsset
const wNat = await ERC20Mock.new("Wrapped NAT", "WNAT", 18, { from: deployer });
const fAsset = await ERC20MockFAsset.new("FAsset", "FAS", 18, { from: deployer });
// 2) Deploy AssetManagerProbe and set agent ownership
const assetManager = await AssetManagerProbe.new(wNat.address, agentVault, agent, { from: deployer });
// 3) Deploy CollateralPool with minimal, safe params
// constructor initialize(agentVault, assetManager, fAsset, exitCR, topupCR, topupPriceFactor)
const exitCR = 20000; // 200%
const topupCR = 100; // > 0 and < exitCR
const topupPriceFactor = 100; // > 0 and < MAX_BIPS
const pool = await CollateralPool.new(
agentVault,
assetManager.address,
fAsset.address,
exitCR,
topupCR,
topupPriceFactor,
{ from: deployer }
);
// 4) Create a distribution that will transfer 10 WNAT to the pool in claim()
const drop = web3.utils.toWei("10");
const distribution = await FakeDistribution.new(wNat.address, drop, { from: deployer });
// fund the distribution with WNAT (ERC20Mock has mint)
await wNat.mint(distribution.address, drop, { from: deployer });
// Sanity: starting balances
expect((await wNat.balanceOf(pool.address)).toString()).to.equal("0");
expect((await pool.totalCollateral()).toString()).to.equal("0");
// 5) Agent triggers airdrop claim
const tx = await pool.claimAirdropDistribution(distribution.address, 5, { from: agent });
// 6) Pool received WNAT and accounted it in totalCollateral
expect((await wNat.balanceOf(pool.address)).toString()).to.equal(drop);
expect((await pool.totalCollateral()).toString()).to.equal(drop);
// 7) Critically, AssetManager.updateCollateral was never called from claim()
// Our probe increments a counter whenever updateCollateral is invoked.
const calls = await assetManager.updateCalls();
expect(calls.toString()).to.equal("0"); // <-- proof of missing propagation
});
});
Line by line, in plain words:
import { expect } from "chai";brings in a testing library that lets the test say "I expect this to be true". Chai is a common JavaScript testing helper.import { toBN } from "../../../lib/utils/helpers";imports a helper for handling big numbers. It is imported but not used in the test body.- The five
artifacts.require(...)lines load the compiled contracts by name so the test can create instances of them.ERC20Mockis used as the wNat mock, a secondERC20Mockstands in for the fAsset, and the other two are the files added in steps 1 and 2. contract("CollateralPool – claim propagation to AssetManager", (accounts) => {starts a test group with a descriptive name and receives the list of test accounts.const [deployer, agent, agentVault] = accounts;takes the first three accounts and names them: one to create contracts, one to act as the agent, one to act as the agent's vault address.it("rewards claim increases pool balance, but AssetManager.updateCollateral is not called", async () => {declares a single test with a name that states exactly what it will prove.asyncmeans the code waits for slow operations such as deploying contracts.- Step 1 deploys the wNat mock with the name "Wrapped NAT", symbol "WNAT" and 18 decimals, and a dummy fAsset with name "FAsset", symbol "FAS" and 18 decimals. Decimals are how many small units make up one token, like pence in a pound.
- Step 2 deploys the probe, passing it the wNat address, the vault address and the agent address, so the probe knows who owns the vault.
- Step 3 deploys the real
CollateralPool, passing the vault, the probe as the asset manager, the dummy fAsset, and three numbers:exitCRof 20000 (200%),topupCRof 100 andtopupPriceFactorof 100. The comments explain the safe ranges:topupCRmust be above zero and belowexitCR, andtopupPriceFactormust be above zero and belowMAX_BIPS. BIPS means basis points, where 10000 equals 100%. - Step 4 sets
dropto 10 tokens, converted from a decimal string into the token's smallest unit byweb3.utils.toWei("10"). It deploys the fake distribution with that amount, then mints 10 tokens to the distribution so it has something to send. Mint means create new tokens. - The two
expectlines check the starting point: the pool holds zero wNat and itstotalCollateralis zero. This is a sanity check, a quick confirmation that the setup is clean before the real test. - Step 5 has the agent call
claimAirdropDistributionon the pool, pointing at the fake distribution and passing5. The transaction result is stored intxbut not used further. - Step 6 checks that the pool's wNat balance now equals the drop, and that
totalCollateralalso equals the drop. Both should have gone up, and they did. - Step 7 reads the probe's
updateCallscounter and expects it to be"0". The comment marks this as the proof: the pool's books went up, but the central office was never told.
The constructor parameters are chosen to be safe: exitCR is 20000 (200%), topupCR is 100 (greater than zero and less than exitCR), and topupPriceFactor is 100 (greater than zero and less than MAX_BIPS). The distribution is funded with wNat.mint because ERC20Mock supports minting.
Step 4: Run it
After adding the three files, compile and run the test with the commands shown in the Setup section. The test passes and prints no updateCollateral calls while showing the pool's wNat balance and totalCollateral increased by the drop.
Observed result:
- The pool's balance and
totalCollateralincrease by the rewarded amount, which is correct. - The
AssetManagerProbe.updateCollateralcounter remains0, demonstrating the missing propagation: the fix leftAssetManager's global view stale after claims.
In everyday terms: the till shows the sale, head office's books do not, and the test proves it by watching the phone that was never picked up.
Root cause
The fix for #45893 replaced trusting the return value with measuring the actual balance change, which closes the fake return value manipulation. It did not add the propagation call that other flows use. enter() and upgradeWNatContract() call assetManager.updateCollateral(agentVault, wNat) after changing collateral; the two claim functions update only the local totalCollateral and emit ClaimedReward.
As a result, the local pool ledger and the global protocol view diverge after a claim. The report notes that the functions are already nonReentrant, and that enter() shows the call is safe in practice in this contract.
nonReentrant refers to a guard against reentrancy, an attack where a called contract calls back into the caller before the first call finishes, like a customer who keeps re-entering the queue to confuse the cashier. The guard means only one such call can be in progress at a time, so adding the missing call would not open that door.
Impact
The system fails to deliver the full protocol-level benefit of rewards and airdrop claims right away. Pool providers expect claims to increase pool health, but AssetManager's stale view can cause:
- Underreported pool backing in protocol health and CR views immediately after a claim. Internal
AssetManagerlogic that relies on updated pool collateral may continue acting as if the pool had not been replenished. - Unnecessarily restrictive actions driven by stale CR checks elsewhere, such as redemptions that consult
AssetManagerlimits, warnings and thresholds, or liquidations initiated based on the global view. - Misleading system telemetry, such as events and metrics sourced from
AssetManager, undermining the promise that rewards flow to the pool at the protocol level until some later action triggers a collateral refresh.
Telemetry here means the numbers and logs the system reports about itself. Redemption means exchanging the system's token back for the underlying value. Liquidation means forcibly converting an agent's collateral because it fell below the required ratio.
Exits from the pool that read totalCollateral still see the new funds, so direct exits denominated in pool NAT are unaffected. The inconsistency is cross-module: AssetManager does not learn about the increase until another path, such as a later enter() or a governance action, eventually triggers updateCollateral. Governance action means a decision made by the people who run or vote on the protocol, rather than by ordinary code flow. There is no direct user fund loss; the issue is a correctness and consistency gap that delays realisation of claim benefits outside the pool contract.
Fix
The recommendation is to mirror the pattern already used in enter() and upgradeWNatContract():
- After computing
claimedand increasingtotalCollateral, immediately callassetManager.updateCollateral(agentVault, wNat). - Keep the call after the
wNat.balanceOfdelta calculation so the update reflects the new state.
The suggested minimal patch, in contracts/assetManager/implementation/CollateralPool.sol, adds the call in both functions:
diff --git a/contracts/assetManager/implementation/CollateralPool.sol b/contracts/assetManager/implementation/CollateralPool.sol
index 1234567..89abcde 100644
--- a/contracts/assetManager/implementation/CollateralPool.sol
+++ b/contracts/assetManager/implementation/CollateralPool.sol
@@ -940,6 +940,7 @@ contract CollateralPool is IICollateralPool, ReentrancyGuard, UUPSUpgradeable, I
uint256 balanceAfter = wNat.balanceOf(address(this));
uint256 claimed = balanceAfter - balanceBefore;
totalCollateral += claimed;
+ assetManager.updateCollateral(agentVault, wNat);
emit ClaimedReward(claimed, 1);
return claimed;
}
@@ -959,6 +960,7 @@ contract CollateralPool is IICollateralPool, ReentrancyGuard, UUPSUpgradeable, I
uint256 balanceAfter = wNat.balanceOf(address(this));
uint256 claimed = balanceAfter - balanceBefore;
totalCollateral += claimed;
+ assetManager.updateCollateral(agentVault, wNat);
emit ClaimedReward(claimed, 0);
return claimed;
}
Line by line, in plain words:
- The first lines identify the file being changed and give internal version markers used by the diff tool.
--- a/...and+++ b/...name the old and new versions of the file.@@ -940,6 +940,7 @@marks a section starting at line 940 in the old file and line 940 in the new file, with one extra line added.- The unchanged lines show the balance measurement, the subtraction to find
claimed, and the addition tototalCollateral. - The line starting with
+is the new line:assetManager.updateCollateral(agentVault, wNat);. This is the phone call to head office that was missing. - The following unchanged lines emit the
ClaimedRewardevent and return the amount. - The second block repeats the same change in the other claim function, marked at line 959 in the old file and 960 in the new one.
This restores the invariant that whenever pool collateral increases on-chain, both local pool accounting and the protocol's global accounting are updated. An invariant is a rule that must always hold true, like "the till total and head office total agree after every sale".
Variants to test
- Look for other functions that change
totalCollateralor the pool'swNatbalance without callingupdateCollateral. A positive result is a function that moves collateral and leaves the probe's counter unchanged. - Check the reverse direction: functions that reduce collateral, such as exits or fee deductions, and whether they propagate the decrease. A positive result is a stale global view after a decrease, which could make the pool look healthier than it is.
- Compare every external-call path that credits the pool (rewards, airdrops, top-ups) against the flows that do call
updateCollateral. A positive result is any credit path missing the call. - After a fix is applied, re-run the probe test and confirm the counter increments exactly once per claim, and that the update happens after the balance delta is computed.
Hunting notes
The signal is a pair of functions that update local state while sibling functions in the same contract also notify a second contract.
During recon, look for contracts that keep a local ledger and also report to a central manager, and check whether every state-changing path reports. Recon is short for reconnaissance: the early reading and mapping of a codebase before testing. A probe contract that counts calls to the manager function is a cheap way to prove the gap without needing the full system. The PoC demonstrates that the pool balance and totalCollateral increase while the manager counter stays at zero.
Glossary
- Address: a unique identifier for an account or contract on a blockchain, like a bank account number.
- Airdrop distribution: a payment of tokens sent out to eligible holders, often as a reward or promotion.
- Assert: in a test, to state what must be true and fail if it is not.
- AssetManager: the central smart contract that holds the protocol-wide view of agent and pool health, collateral ratios, redemption limits and liquidation logic.
- Basis points (BIPS): a way of writing percentages where 10000 equals 100%.
- Blockchain: a shared record book kept by many computers, where entries cannot be quietly changed.
- Collateral: a deposit put up to back a promise, which can be taken away if the promise is broken.
- CollateralPool: the smart contract that holds an agent's collateral and keeps its own tally in
totalCollateral. - Collateral ratio (CR): how much deposit backs a promise, as a percentage; 200% means twice as much deposit as the thing backed.
- Commit: a saved snapshot of code changes in a version control system, with its own identifier.
- Compile: translate human-written code into the form the machine runs.
- Constructor: code that runs once when a smart contract is created.
- Cross-module: involving more than one part of the system, where one part does not automatically know what another part did.
- Decimals: how many small units make up one token, like pence in a pound.
- Delegation rewards: payments earned by delegating stake, sent to the pool from outside.
- Diff: a view of what changed between two versions of a file, with added lines marked
+and removed lines marked-. - Event: a log entry a smart contract writes to the blockchain so outside tools and users can see what happened.
- External call: when one smart contract asks another contract to do something and receives a reply.
- fAsset: the system's own token, created against collateral.
- Function: a named block of code that does one job when called.
- Governance action: a decision made by the people who run or vote on the protocol, rather than by ordinary code flow.
- Immutable: set once at creation and unable to change afterwards.
- Interface: a list of function names and shapes a contract promises to provide, like a menu.
- Invariant: a rule that must always hold true.
- Ledger: a record book of who has what.
- Liquidation: forcibly converting an agent's collateral because it fell below the required ratio.
- Mapping: a lookup table from a key to a value, like a dictionary.
- Mint: create new tokens.
- Mitigation audit: a review of a fix for an earlier bug, checking that the fix is complete and introduces no new problems.
- Mock: a simplified fake that behaves enough like the real thing for a test.
- NAT: the native coin of the Flare network.
- nonReentrant: a guard that stops a called contract from calling back into the caller before the first call finishes.
- Proof of concept (PoC): a small experiment that demonstrates a problem really happens.
- Probe: a stand-in contract whose only job is to count how often a particular function is called.
- Recon: short for reconnaissance, the early reading and mapping of a codebase before testing.
- Redemption: exchanging the system's token back for the underlying value.
- Reentrancy: an attack where a called contract calls back into the caller before the first call finishes.
- Repository: the folder of code stored online.
- Return value: the reply a function sends back to whoever called it.
- Sanity check: a quick confirmation that the setup is clean before the real test.
- Smart contract: code that lives on a blockchain and runs by itself when someone calls it.
- Solidity: the programming language used to write the smart contracts here.
- Stale: out of date, holding an old value that no longer matches reality.
- Stub: a placeholder function that exists only to satisfy an interface.
- Telemetry: the numbers and logs a system reports about itself.
- Terminal: the text window where you type commands.
- Test rig: the set of tools that lets you run code on your own machine and check results.
- Token: a digital unit that a smart contract can count and move.
- Transaction: a recorded action sent to a blockchain, such as calling a contract function.
- Variable: a named box in code that holds a value.
- Vault: a per-agent container that holds that agent's collateral.
- wNat: a wrapped version of NAT, a token that represents NAT inside the token system.