Incorrect function call leads to stale borrowing fees
The function getTotalBorrowingFees used a stale cumulative borrowing factor instead of the next one, so the calculated borrowing fees were inaccurate. This could affect the valuation of market tokens for deposits and withdrawals, impacting liquidity providers.
Due to an incorrect function call while getting the total borrow fees, the returned fees will be an inaccurate and stale amount. Which will have an impact on liquidity providers
which is the wrong function to call because it returns a stale borrowing factor. To get the actual borrowing factor and calculate correctly the borrowing fees, GMX should call the getNextCumulativeBorrowingFactor function:
Ass fee calculation will not be accurate, liquidity providers will be have a less-worth token because pending fees are not accounted in the pool's value
In order to mitigate the issue, call the function getNextCumulativeBorrowingFactor instead of the function getCumulativeBorrowingFactor() for a correct accounting and not getting stale fees
Discussion
IllIllI000
@xvi10 can you confirm that this is invalid?
xvi10
sorry thought i marked this, it is a valid issue
IllIllI000
@xvi10 can you elaborate on the conditions where this is a valid issue? Don’t most code paths call updateFundingAndBorrowingState() prior to fetching fees, so doesn’t that mean the value won’t be stale? I flagged the case where it’s missing in https://github.com/sherlock-audit/2023-02-gmx-judging/issues/158 . Are you saying that this is a separate issue, or that these should be combined, or something else?
xvi10
it affects the valuation of the market tokens for deposits / withdrawals
IllIllI000
@hrishibhat agree with sponsor – valid High
0xffff11
Escalate for 10 USDC
It is a valid solo high. Sponsor confirmed the issue and severity.
is made to return the borrowingFees that are pending at that moment. The issue is that inside the getTotalBorrowingFees function, they are calling the wrong function to get the cumulativeBorrowingFactor.
They are calling the function cumulativeBorrowingFactor instead of getNextCumulativeBorrowingFactor. , that is the one that should be called to get the updated borrowing fees. Calling the cumulativeBorrowingFactor returns the outdated fees.
These outdate in fees can cause a missmatch in pricing specially while withdrawing, as sponsor confirmed.
To sum up: Issue is completely valid, sponsor confirmed and enough issue has been given. Please make it a valid solo high, thanks IIIIIII!
sherlock-admin
Escalate for 10 USDC
It is a valid solo high. Sponsor confirmed the issue and severity.
is made to return the borrowingFees that are pending at that moment. The issue is that inside the getTotalBorrowingFees function, they are calling the wrong function to get the cumulativeBorrowingFactor.
They are calling the function cumulativeBorrowingFactor instead of getNextCumulativeBorrowingFactor. , that is the one that should be called to get the updated borrowing fees. Calling the cumulativeBorrowingFactor returns the outdated fees.
These outdate in fees can cause a missmatch in pricing specially while withdrawing, as sponsor confirmed.
To sum up: Issue is completely valid, sponsor confirmed and enough issue has been given. Please make it a valid solo high, thanks IIIIIII!
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
IllIllI000
I messed up the tagging - Valid solo High
hrishibhat
Escalation accepted
Considering this issue a valid high
sherlock-admin
Escalation accepted
Considering this issue a valid high
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
The original report as published on Sherlock, by 0xAmanda. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The function getTotalBorrowingFees called getCumulativeBorrowingFactor instead of getNextCumulativeBorrowingFactor, so it used a stale factor that did not include fees accrued since the last update.
Impact
The inaccurate fee calculation could cause a mismatch in pricing, especially during withdrawals, leading to liquidity providers receiving tokens worth less than they should.
What the attacker needed
None
The fix
The issue was fixed by calling getNextCumulativeBorrowingFactor instead of getCumulativeBorrowingFactor.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In a smart contract, borrowing fees accumulate over time. The code that calculates total fees used an old value instead of the latest one, so the fees shown were out of date. This meant that when people added or removed money from the pool, the pool's value was slightly wrong, which could cost liquidity providers money.
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.