Collateral cannot be claimed because there is no mechanism for the config keeper to change the claimable factor
The collateral claim function multiplies the claimable amount by a factor stored in the data store, but the config keeper has no way to set that factor, so it stays at zero. As a result, users can never claim back collateral that was withheld due to capped price impacts, causing a principal loss.
IllIllI Follow with berndartmueller
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/137
Found by
IllIllI, berndartmueller
Summary
Collateral given back to a user due to capped price impacts cannot be claimed because there is no mechanism for the config keeper to set the claimable factor
Vulnerability Detail
The code that claims the collateral for the user only gives back a percentage of the collateral based on a "factor", but there is no function to change the factor from the default of zero.
Impact
The user will never be able to claim any of this collateral back, which is a principal loss.
Needing to let users claim their collateral is mainly for when large liquidations cause there to be large impact amounts. While this is not an everyday occurrence, large price gaps and liquidations are a relatively common occurrence in crypto, happening every couple of months, so needing this functionality will be required in the near future. Fixing the issue would require winding down all open positions and requiring LPs to withdraw their collateral, and re-deploying with new code.
Code Snippet
// File: gmx-synthetics/contracts/market/MarketUtils.sol : MarketUtils.claimCollateral() #1
627 uint256 claimableAmount = dataStore.getUint(Keys.claimableCollateralAmountKey(market, token, timeKey, account));
628 @> uint256 claimableFactor = dataStore.getUint(Keys.claimableCollateralFactorKey(market, token, timeKey, account));
629 uint256 claimedAmount = dataStore.getUint(Keys.claimedCollateralAmountKey(market, token, timeKey, account));
630
631 @> uint256 adjustedClaimableAmount = Precision.applyFactor(claimableAmount, claimableFactor);
632 @> if (adjustedClaimableAmount >= claimedAmount) {
633 revert CollateralAlreadyClaimed(adjustedClaimableAmount, claimedAmount);
634: }
Tool used
Manual Review
Recommendation
diff --git a/gmx-synthetics/contracts/config/Config.sol b/gmx-synthetics/contracts/config/Config.sol
index 9bb382c..7696eb6 100644
--- a/gmx-synthetics/contracts/config/Config.sol
+++ b/gmx-synthetics/contracts/config/Config.sol
@@ -232,6 +232,8 @@ contract Config is ReentrancyGuard, RoleModule, BasicMulticall {
allowedBaseKeys[Keys.MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER] = true;
allowedBaseKeys[Keys.MIN_COLLATERAL_USD] = true;
+ allowedBaseKeys[Keys.CLAIMABLE_COLLATERAL_FACTOR] = true;
+
allowedBaseKeys[Keys.VIRTUAL_TOKEN_ID] = true;
allowedBaseKeys[Keys.VIRTUAL_MARKET_ID] = true;
allowedBaseKeys[Keys.VIRTUAL_INVENTORY_FOR_SWAPS] = true;
Discussion
xvi10
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the claimable collateral factor key was never added to the list of keys the config keeper is permitted to set, so it remains at its default of zero.
Impact
Users will never be able to claim this collateral back, which is a principal loss; the text notes this matters mainly during large liquidations and that fixing it later would require winding down positions and redeploying.
What the attacker needed
A position affected by capped price impact; collateral withheld for later claiming
The fix
The issue was fixed by allowing the claimable collateral factor key to be set through the config, as shown in the linked pull request.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a trade causes a very large price swing, the system holds back part of a user's collateral and lets them claim it later. The claim code multiplies the amount by a setting called a factor, but nobody is allowed to change that setting from its starting value of zero. Multiplying by zero means the user always gets nothing back.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.