_handleOpenFees returns an incorrect value for _feePaid . This directly impacts margin calculations
The fee calculation in the trading contract omitted the referral fee component, causing the reported fee paid to be understated. This led to incorrect margin calculations and reduced rewards for protocol NFT holders.
Submitted by 0Kage, also found by chaduke
Impact
Formula for fee paid in Line 734 is incorrect leading to incorrect margin calculations. Since this directly impacts the trader margin and associated fee calculations, I’ve marked as HIGH risk.
On initiating a market order, Margin is adjusted for the fees that is charged by protocol. This adjustment is in Line 178 of Trading. Fees computed by _handleOpenFees is deducted from Initial margin posted by user.
Formula misses to account for the 2*referralFee component while calculaing _feePaid.
Proof of Concept
Note that _feePaid as per formula in Line 734 is the sum of _daoFeesPaid, and sum of burnerFee&botFee . \_daoFeesPaidis calculated from\_fees.daoFeeswhich itself is calculated by subtracting2\*referralFeeandbotFee\.
So when we add back burnerFee and botFee to _feePaid, we are missing to add back the 2*referralFee which was earlier excluded when calculating _daoFeesPaid. While botFee is added back correctly, same adjustment is not being done viz-a-viz referral fee.
This results in under calculating the _feePaid and impacts the rewards paid to the protocol NFT holders.
Recommended Mitigation Steps
Suggest replacing the formula in line 734 with below (adding back \_fees.referralFees\*2)
_feePaid =
_positionSize
* (_fees.burnFees + _fees.botFees + _fees.referralFees*2 )
/ DIVISION_CONSTANT // divide by 100%
+ _daoFeesPaid;
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The warden has shown a mistake in how fees are calculated, the impact will cause a loss of yield to the protocol, however no convincing argument was made as to how this can cause a loss to depositors or users (loss of principal), for this reason, I believe Medium Severity to be the most appropriate.
GainsGoblin (Tigris Trade) confirmed and commented:
Mitigation: https://github.com/code-423n4/2022-12-tigris/pull/2#issuecomment-1419176602
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
The formula for _feePaid omitted the 2*referralFee component that had been subtracted when computing _daoFeesPaid.
Impact
The understated fee paid could reduce rewards to protocol NFT holders, but the judge noted no convincing argument was made for loss of principal to users or depositors.
What the attacker needed
None
The fix
The formula should be corrected to add back the referral fee component when calculating _feePaid.
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 someone places a trade, the platform charges a fee. Part of that fee goes to referrers, but the code forgot to include that part when calculating the total fee. This meant the platform thought it collected less in fees than it actually did, which affected how much reward was given to certain token holders.
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.