Wrong comment in _getFAssetRequiredToNotSpoilCR
The comment in the else branch of _getFAssetRequiredToNotSpoilCR incorrectly states the formula for the required f-asset amount, describing it as n = N f / F when the code actually computes f = F * n / N. This is a documentation error with no direct security impact.
- Disclosed after under an hour
#46677 [SC-Insight] Wrong comment in _getFAssetRequiredToNotSpoilCR
Submitted on Jun 3rd 2025 at 08:56:15 UTC by @Paludo0x for Audit Comp | Flare | FAssets
- Report ID: #46677
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/flare-foundation/fassets/blob/main/contracts/assetManager/implementation/CollateralPool.sol
- Impacts:
Description
Vulnerability Details
In CollateralPool._getFAssetRequiredToNotSpoilCR, the else‐branch carries this comment:
// f-asset that preserves pool CR (assume poolNatBalance >= natShare > 0)
// solve (N - n) / (F - f) = N / F get n = N f / F
return _assetData.agentBackedFAsset.mulDiv(_natShare, _assetData.poolNatBalance);
Here “N” refers to poolNatBalance, “F” to agentBackedFAsset, and “n” to the NAT withdrawn. But the code inside this branch computes
f = F * n / N
This should be a copy/paste error from function _getNatRequiredToNotSpoilCR which is correct.
Proof of Concept
Proof of Concept
Snippets from relevant code
function _getFAssetRequiredToNotSpoilCR(
AssetData memory _assetData,
uint256 _natShare
)
internal pure
returns (uint256)
{
// calculate f-assets required for CR to stay above min(exitCR, poolCR) when taking out _natShare
// if pool is below exitCR, we shouldn't require it be increased above exitCR, only preserved
// if pool is above exitCR, we require only for it to stay that way (like in the normal exit)
if (_staysAboveCR(_assetData, 0, _assetData.exitCR)) {
// f-asset required for CR to stay above exitCR (might not be needed)
// solve (N - n) / (p / q (F - f)) >= cr get f = max(0, F - q (N - n) / (p cr))
return MathUtils.subOrZero(_assetData.agentBackedFAsset, _assetData.assetPriceDiv *
(_assetData.poolNatBalance - _natShare) * SafePct.MAX_BIPS /
(_assetData.assetPriceMul * _assetData.exitCR)
); // _assetPriceMul > 0, exitCR > 1
} else {
// f-asset that preserves pool CR (assume poolNatBalance >= natShare > 0)
// solve (N - n) / (F - f) = N / F get n = N f / F
return _assetData.agentBackedFAsset.mulDiv(_natShare, _assetData.poolNatBalance);
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a copy/paste error from the related function _getNatRequiredToNotSpoilCR, where the comment was correct for that function but not updated for this one.
Impact
No security impact; the code behaves correctly, only the comment is misleading.
What the attacker needed
None
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a report about a wrong comment in a smart contract. The comment explains a maths formula, but the formula written in the comment does not match what the code actually calculates. It is like a recipe saying 'add sugar' when the steps say 'add salt' — confusing, but the cake (the code) still works as intended.