Settlement fee of unused markets is still charged in Vault
A vault charges the fixed settlement fee of every registered market, including markets whose weight has been set to zero to retire them. Because those fees are deducted from the amount users can claim, each settlement leaks funds from vault users.
Source: https://github.com/sherlock-audit/2023-10-perennial-judging/issues/33
Found by
0xkaden
Summary
When markets are removed from usage in a vault, their weight is set to 0. However, their fixed market settlement fee is always charged regardless of whether the market is actually being used.
Vulnerability Detail
The only way to remove a market in Vault.sol is by updating the market weight and leverage to 0 with updateMarket. However, the market will still be listed as a market, in which case its fixed settlement fee will be included in the total settlementFee amount to be paid whenever a position is changed.
This results in the market's settlementFee being excluded from vault users claim amounts, effectively resulting in a material loss of funds for vault users.
Impact
Markets can't be removed from use in a vault without incurring a loss of user funds with each claim.
Code Snippet
Can only update market weight and leverage:
/// @notice Settles, then updates the registration parameters for a given market
/// @param marketId The market id
/// @param newWeight The new weight
/// @param newLeverage The new leverage
function updateMarket(uint256 marketId, uint256 newWeight, UFixed6 newLeverage) external onlyOwner {
settle(address(0));
_updateMarket(marketId, newWeight, newLeverage);
}
/// @notice Updates the registration parameters for a given market
/// @param marketId The market id
/// @param newWeight The new weight
/// @param newLeverage The new leverage
function _updateMarket(uint256 marketId, uint256 newWeight, UFixed6 newLeverage) private {
if (marketId >= totalMarkets) revert VaultMarketDoesNotExistError();
Registration memory registration = _registrations[marketId].read();
registration.weight = newWeight;
registration.leverage = newLeverage;
_registrations[marketId].store(registration);
emit MarketUpdated(marketId, newWeight, newLeverage);
}
For each market we add the settlementFee regardless of weight.
for (uint256 marketId; marketId < totalMarkets; marketId++) {
...
context.settlementFee = context.settlementFee.add(marketParameter.settlementFee);
...
}
Tool used
Manual Review
Recommendation
Include a function to remove markets from use within a vault such that totalMarkets is decremented and the marketId is somehow marked as unused.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
panprog commented:
borderline low/medium, settlement fee does include markets with weight 0, although they can still require updates if vault position in the market can't be decreased due to market limitations. However, once collateral and position are 0, there should be a way to remove the market from the vault not to overpay settlement fees
kbrizzle
Valid, but in order to not charge the interface fee for the zero-weight market, you'd need to make several material refactors in the vault (skipping settlement of that market / handling null ids in the Mappings) -- the complexity of the potential fix here outweighs the marginal gain, so we will not be fixing this at this time. We may revisit this in a future update.
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 fee loop sums the settlement fee of every registered market without checking whether its weight is zero, and there is no way to actually remove a market.
Impact
Markets cannot be retired from a vault without a loss of user funds on each claim, though the maintainer judged the gain from fixing it too small relative to the refactor needed.
What the attacker needed
Vault owner sets a market weight to zero; vault still holds that market registration
The fix
The maintainer declined to fix it at this time, noting that skipping settlement for zero-weight markets would require material refactors.
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.
A vault spreads money across several markets and pays a small fixed fee each time it settles. To retire a market, the owner can only set its weight to zero, but the code still counts that market's fee. So users quietly lose a bit of money on every settlement even though the market is no longer used.
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.