Open code423n4 opened 1 year ago
Coded POC with Math -> Best
GalloDaSballo marked the issue as primary issue
I think I confirmed a similar issue.
TriHaz marked the issue as sponsor confirmed
The Warden has highlighted an discrepancy in how OpenInterest is calculated, the math should cause issues in determining funding rates, however the submission doesn't show a way to reliably extract value from the system.
Because of this, I believe the finding to be of Medium Severity
GalloDaSballo marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/496e1974ee3838be8759e7b4096dbee1b8795593/contracts/Trading.sol#L513-L517
Vulnerability details
The
PairsContract
registeres the total long/short position that's open for a pair of assets, whenever a new position is created the total grows accordingly. However atexecuteLimitOrder()
the position size that's added is wrongly calculated - it uses margin before fees, while the actual position is created after subtracting fees.Impact
The OpenInterest would register wrong values (11% diff in the case of PoC), which will distort the balance between long and short positions (the whole point of the OpenInterest is to balance them to be about equal).
Proof of Concept
In the following test, an order is created with a x100 leverage, and the position size registered for OI is 11% greater than the actual position created.
Output:
Recommended Mitigation Steps
Correct the calculation to use margin after fees.