Fees are not collected from traders in addToPosition
#433
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
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L278
Vulnerability details
Impact
The protocol doesn't receive fees when margin is added via the
addToPosition
function. An equal amount of tigUSD is minted even though it's not backed by margin.Proof of Concept
The protocol takes fees from margin provided by users: for example, when opening a market order:
_marginAfterFees
).Thus, traders provide full margin when opening orders and fees are subtracted from accounted margin. If trader closes an order, they'll receive margin - fees.
The protocol also allows traders to add margin to existing positions at a different price, via the
addToPosition
function (Trading.sol#L255). This function, however, subtracts fees from margin before transferring margin from traders:As a result, the protocol doesn't receive fees when margin is added via
addToPosition
.Tools Used
Manual review
Recommended Mitigation Steps
Consider not subtracting fees from
_addMargin
inaddToPosition
when calling_handleDeposit
.The text was updated successfully, but these errors were encountered: