Open code423n4 opened 1 year ago
More details, making primary
GalloDaSballo marked the issue as primary issue
TriHaz marked the issue as sponsor confirmed
The warden has shown an accounting issue in how fees are calculated, the refactoring is straightforward
GalloDaSballo marked the issue as selected for report
@GalloDaSballo This is a duplicate of #476
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L178-L179 https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L734-L738
Vulnerability details
Description
When
initiateMarketOrder
is called,_marginAfterFees
are calculated and then use it to calculate_positionSize
The problem is that
_handleOpenFees
does not consider referrer fees when it calculates its output (paidFees), leading to open a position greater than expected.Impact
For a referred trade,
initiateMarketOrder
always opens a position greater than the one supposed, by allowing to use more margin than the one expected.POC
The output of
_handleOpenFees
is_feePaid
, which is calculated once, and it does not consider referralFeesThen we can notice that, if the output of
_handleOpenFees
did not consider referral fees, neither would _marginAfterFees doMitigation steps
Consider referral fees when
_feePaid
is calculated in_handleOpenFees