Error when handling deposit in the addToPosition
function
#644
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-659
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L255-L305
Vulnerability details
Impact
In the function
addToPosition
from theTrading
contract the amount of open fees are handled using the_handleOpenFees
function but when calling the_handleDeposit
function the wrong margin is passed, in fact the_handleDeposit
function gets_addMargin - _fee
instead of_addMargin
So this mean that the open fees are calculated and handled but when depositing there value will not be transferred from the trader and will not be deposited in the stableVault.
Proof of Concept
The issue occurs in the
addToPosition
function :File: contracts/Trading.sol Line 255-305
As you can see from the code above the
_handleDeposit
function receive_addMargin - _fee
as new margin, this value is used to calculate the transferred amount from the trader :File: contracts/Trading.sol Line 565-576
So because of this error the open fees amount will not be transferred from the trader and will not be deposited in the StableVault.
Tools Used
Manual review
Recommended Mitigation Steps
To avoid this issue correct the margin passed to the function
_handleDeposit
, theaddToPosition
function should be modified as follow :The text was updated successfully, but these errors were encountered: