stopthecap - Unpaid funding fees from wrong calculation are going to be substracted from the pool #67
Description
stopthecap
high
Unpaid funding fees from wrong calculation are going to be substracted from the pool
Summary
The vulnerability start at the function getNextFundingAmountPerSize:
Basically, GMX is handling incorrectly the way on how they calculate the FundingFees to be paid because they calculate the amount using the getOpenInterest
from both the short and long tokens.
Vulnerability Detail
The detailed issue here is that GMX is incorrectly handling the calculation with the getOpenInterest
(the open Interest) of the two tokens, short and long. They are dividing the cache.fundingUsd
for the interest of the two tokens:
After dividing, you get the cache.fundingUsdForLongCollateral
which is basically the amount that has to be paid or paidTo for any of both collaterals and positions.
That is a big problem in one case, when users need to pay those feed. When the user does have to pay the fundingFees. Because customers can only pay those fundingFees for their collateral token, not for both.
As said, this is not an issue when users do receive the fundingFees because you can claim both tokens, but it is an issue when paying the fees.
This will result in less fundingFees being paid by users.
Impact
2 Impacts:
1:
A missmatch in the pools accounting will occur over time which might have unexpected results in terms of insolvency's.
2:
High because users are not paying the fees that they should pay, so there is an economic damage. Specifically because the bug just described, does reduce the variable fundingAmountPerSizePortion
:
which is what user pays for the collateral token. As said before, the amounts are being divided by the entire interest, therefore, just a small part only a portion of the FundingFees will be paid, meanwhile the entire amount can be claimed.
Code Snippet
Tool used
Manual Review
Recommendation
The way on how the funding fees are calculate for users that have to pay them has to change in a way that it is not calculated accounting all the open interest. The calculation of the funding fees for users that have to claim fundingFees, not necessarily has to change.